The code's purpose is to change from one led to another if the LDR detects a certain level of light for a given time. Currently, since I cannot wait 5 minutes to complete one circuit, each LED should be on for 1000 ms. At one stage in the code, there are no LEDs on. The LEDs should not turn on until the LDR has sensed no light and then light levels necessary for the code to restart.
Here is the code;
const int buzzer=3;
const int ldr = A4;
void setup () {
Serial.begin(9600);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(ldr, INPUT);
}
void loop() {
int ldrStatus = analogRead(ldr);
if (ldrStatus >= 300) {
digitalWrite(13, HIGH);
delay(1000);
} else {
noTone(buzzer);
digitalWrite(13, LOW);
digitalWrite(12, LOW);
}
if (ldrStatus >= 300) {
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
tone(buzzer, 100, 30);
delay(1000);
tone(buzzer, 100);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
} else {
noTone(buzzer);
digitalWrite(13, LOW);
digitalWrite(12, LOW);
}
}
I have realised that the purpose of my code is unclear. What happens is one LED turns on when the LDR senses light. If the light continues, then the buzzer will sound once and the LED will change to a different colour LED. If the LDR continues to detect light, then all LEDs will turn off and the buzzer will sound continuously. The only problem is that the code doesn't stop until the LDR has sensed a high enough decrease in light levels.
Zoe Melck
and you edited the question asZoe
.... please click theFlag
button at bottom of your question and clickmoderator intervention
and request to merge your accounts