// Solar-powered Light for a Bus Shelter with a motion sensor //analog pins int ldrPin = A0; //digital pins int ldrSignal = 4; //this pin is turn activates the latch whenever there is dark int stopSignal = 6; //this pin acts as a stop signal for latch int pirSensor = 3; int dataVal = 5; int output; void setup() { pinMode(ldrPin, INPUT); pinMode(ldrSignal, OUTPUT); pinMode(stopSignal, OUTPUT); pinMode(pirSensor, INPUT); Serial.begin(9600); } void loop() { dataVal = analogRead(ldrPin); digitalRead(pirSensor); digitalWrite(stopSignal, LOW); digitalWrite(ldrSignal, LOW); //when it's dark enough, Arduino make ldrPin high, indicating that the button can be pushed. //Otherwise the button can be pressed during the day which does not make sence) if(dataVal <= 400) { digitalWrite(ldrSignal, HIGH); }else { digitalWrite(ldrSignal, LOW); } if(digitalRead(pirSensor) == HIGH) { digitalWrite(stopSignal, LOW); delay(15000); //the latch will continue for the next 15 seconds and then it will be unlatched digitalWrite(stopSignal, HIGH); } //This part isn't neccasary to have in the final version of code, but it is neccasary to have in order to check the values from a ldr Serial.println(dataVal); delay(1000); }