What you will need:
Arduino UNO
1x Buzzer(5v) OR 1x small Speaker
1x Photoresistor 500KΩ
1x Resistor 10KΩ
2x Resistors 330Ω
1x Red LED (or whatever you prefer)
1x Yellow LED (or whatever you prefer)
(don't forget to click read more for the code)
Schematics
Code
void setup() {
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
}
void loop() {
int sensorValue = analogRead(A0);
if (sensorValue < 700) {
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
analogWrite(9, 1900);
delay(700);
digitalWrite(13, LOW);
analogWrite(9, 900);
delay(700);
digitalWrite(13, HIGH);
analogWrite(9, 1900);
delay(700);
digitalWrite(13, LOW);
analogWrite(9, 900);
delay(700);
digitalWrite(13, HIGH);
analogWrite(9, 1900);
delay(700);
digitalWrite(13, LOW);
analogWrite(9, 900);
delay(700);
digitalWrite(13, HIGH);
analogWrite(9, 1900);
delay(700);
digitalWrite(13, LOW);
analogWrite(9, 900);
delay(700);
digitalWrite(13, HIGH);
}
else {
digitalWrite(9, LOW);
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
}
}
NOTE: ATTENTION TO POLARITY
Arduino UNO
1x Buzzer(5v) OR 1x small Speaker
1x Photoresistor 500KΩ
1x Resistor 10KΩ
2x Resistors 330Ω
1x Red LED (or whatever you prefer)
1x Yellow LED (or whatever you prefer)
(don't forget to click read more for the code)
Schematics
Code
void setup() {
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
}
void loop() {
int sensorValue = analogRead(A0);
if (sensorValue < 700) {
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
analogWrite(9, 1900);
delay(700);
digitalWrite(13, LOW);
analogWrite(9, 900);
delay(700);
digitalWrite(13, HIGH);
analogWrite(9, 1900);
delay(700);
digitalWrite(13, LOW);
analogWrite(9, 900);
delay(700);
digitalWrite(13, HIGH);
analogWrite(9, 1900);
delay(700);
digitalWrite(13, LOW);
analogWrite(9, 900);
delay(700);
digitalWrite(13, HIGH);
analogWrite(9, 1900);
delay(700);
digitalWrite(13, LOW);
analogWrite(9, 900);
delay(700);
digitalWrite(13, HIGH);
}
else {
digitalWrite(9, LOW);
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
}
}
NOTE: ATTENTION TO POLARITY
No comments:
Post a Comment