Software
Arduino IDE
TinkerCad
Tools
Glue Gun
Scissor
Tape
Cutter
Materials
Wires
LDR Sensor
BreadBoard
green LED
Resistor 330/220 Ohm
ON/OFF Switch
Buzzer
USB Cable
Arduino UNO
Designing
1- install all materials we are going to use
Arduino Uno.
jumpers.
USB cable.
Green LED.
Resistor.
breadboard.
LDR sensor.
Buzzer.
ON/OFF Switch.
2- Connect all components on the breadboard (Parallel).
3- start the STIMULATION .feature to make sure every component is working.
I connect the
+ve wire of LED to pin 2& -ve wire of LED to pin GND on a GND of Breadboard,
+ve wire of Buzzer to pin 3 & -ve wire of Buzzer to pin GND on a GND of Breadboard,
one terminal of Button to pin 4&the other terminal of Button to pin GND on a GND of Breadboard,
GND of Breadboard to a GND of Arduino.
As in the previous pic, I connect the LDR sensor, VCC connects to the 5v
n& GND connected to a GND of Arduino & DO connect To digital pin 5.
Circuit on Tinkercad
1- Connect all components on the breadboard and Arduino Uno in tinkercad.
2- Connect all components on the breadboard and Arduino Uno.
3- Writing the code on Arduino IDE.
4- Uploading the code to the Arduino UNO.
Circuit Before Connection
Circuit after connecting it
// HERE IS THE EXPLANATION OF EACH PIN
int LDRInput = 5;
int LED = 2;
int BUZZER = 3;
int BUTTON = 4;
void setup() {
// HERE IS DECLARING OF INPUT & OUTPUT
Serial.begin(9600);
pinMode(LDRInput, INPUT);
pinMode(BUTTON, INPUT_PULLUP);
pinMode(LED, OUTPUT);
pinMode(BUZZER, OUTPUT);
}
void loop() {
// int value = analogRead(LDRInput); //Reads the Value of LDR(light).
Serial.println("LDR value is :"); //Prints the value of LDR to Serial Monitor.
Serial.println(digitalRead(5));
Serial.println("BUTTON VAlue is :"); //Prints the value of LDR to Serial Monitor.
Serial.println(digitalRead(4));
delay(1000);
if (digitalRead(BUTTON) == LOW) { // HERE IS THE LOOP START WITH CHECKING IF THE BUTTON IS WORKING OR NOT
if (digitalRead(5) == HIGH) { // IF THE BUTTON IS ON SYSTEM START WITH THE LDR SENSOR IF IT SENSE DARKNESS
digitalWrite(LED, HIGH); //The LED turns ON in Dark.
digitalWrite(BUZZER, HIGH); //The LED turns ON in Dark.
delay(100);
digitalWrite(BUZZER, LOW); //The BUZZER turns OFF in Dark.
} else {// IF THE BUTTON IS OFF SYSTEM EVERTHING WILL STOP
digitalWrite(LED, LOW); //The LED turns OFF in Light.
digitalWrite(BUZZER, LOW); //The LED turns ON in Dark.
}
}
}
so I Consider only the Analog Read but when I Start verifying everything going good then I uploaded the code on Arduino here comes the problem I could light the LED
if (analogRead(5) == HIGH) {
if (digitalRead(5) == HIGH) {
I Wish I had pics of the whole situation but unfortunately
I Learned how to design a circuit and code it with tinker cad to know how to design & code electrical circuits by using Arduino IDE, it is going to help me to code my final project.