Hey
So I've really been trying to get this darn thing to work! The goal is to get the LED to turn on when the photo-resistor registers a change in light or an input from a switch. Right now everything works perfectly fine except for
// Door Closing
if (photocellReading < 378 || manualDownReading == 0) {
digitalWrite (6, HIGH);
}
More specifically the manualDownReading part. If the light is off (because the photocell registers light > 400) triggering the manual Down Switch should turn the light on, but it doesn't. I really have no idea why! Thanks for the help!
The attachment is a photo of my schematic.
The LED is a substitute for a motor I just find it easier to test because it's visible.
Just FYI I've noticed that when i toggle the switch the LED does blink, very faintly, every 10 seconds or so. Could the delays have something to do with it?
I got rid of all the delays on the serial print and the led started to blink faster within a second.
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 UP 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);
}
}