Arduino Code Explanation
1. setup()
The setup() function runs once when the Arduino starts. It initializes the hardware settings.
2. [Link](9600)
Starts serial communication at 9600 baud so sensor readings can be viewed in the Serial Monitor.
3. pinMode(7, OUTPUT)
Configures digital pin 7 as an output to control the LED.
4. loop()
Runs continuously, reading the LDR value and controlling the LED.
5. analogRead(A0)
Reads the analog value from the LDR connected to analog pin A0. The value ranges from 0 to 1023
and is stored in variable c.
6. [Link](c)
Prints the LDR reading to the Serial Monitor for monitoring and debugging.
7. if(c < 500)
Compares the sensor value with the threshold value 500.
8. digitalWrite(7, LOW)
Turns the LED OFF (according to the current circuit wiring) when the sensor value is below 500.
9. digitalWrite(7, HIGH)
Turns the LED ON (according to the current circuit wiring) when the sensor value is 500 or above.
Overall Working
The Arduino continuously reads the LDR sensor through analog pin A0, displays the value on the
Serial Monitor, compares it with a threshold of 500, and turns the LED ON or OFF accordingly. This
demonstrates an automatic light control system using an LDR and Arduino.