Difficulty with OR statements powering a LED


hey
so i've been trying darn thing work! goal led turn on when photo-resistor registers change in light or input switch.  right works fine except

  // door closing
  if (photocellreading < 378 || manualdownreading == 0) {
    digitalwrite (6, high);
}

more manualdownreading part. if light off (because photocell registers light > 400) triggering manual down switch should turn light on, doesn't. have no idea why! help!


the attachment photo of schematic.

the led substitute motor find easier test because it's visible.

just fyi i've noticed when toggle switch led blink, faintly, every 10 seconds or so. delays have it?

i got rid of delays on serial print , led started blink faster within second.


code: [select]


int photocell = 0;

int updetect = 11;
int downdetect = 9;

int manualup = 10;
int manualdown = 3;

int upswitchreading;
int downswitchreading;
int photocellreading;
int manualupreading;
int manualdownreading;

void setup(void) {
  pinmode (updetect, input_pullup);
  pinmode (downdetect, input_pullup);

  pinmode (manualdown, input_pullup);
  pinmode (manualup, input_pullup);
  pinmode (6, output);

  serial.begin(9600);
  delay(1000);
}

void loop(void) {
  serial.println("up switch reading = ");
  upswitchreading = digitalread(updetect);
  serial.println(upswitchreading, dec);
  delay(1000);

  serial.println("down switch reading = ");
  downswitchreading = digitalread(downdetect);
  serial.println(downswitchreading, dec);
  delay(1000);

  serial.println("manual down switch = ");
  manualdownreading = digitalread(manualdown);
  serial.println(manualdownreading, dec);
  delay(1000);

  serial.println("manual switch = ");
  manualupreading = digitalread(manualup);
  serial.println(manualupreading, dec);
  delay(1000);

  serial.println("  photocell reading = ");
  photocellreading = analogread(photocell);
  serial.println(photocellreading);
  delay(1000);


  // door closing
  if (photocellreading < 378 || manualdownreading == 0) {
    digitalwrite (6, high);
  }
 
  // door opening
  if (photocellreading > 400 || manualupreading == 0) {
    digitalwrite (6, low);
  }

}


first, have current limit resistor ( 220 330 ohms) in series led? drawing don't show one.


Arduino Forum > Using Arduino > Programming Questions > Difficulty with OR statements powering a LED


arduino

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???