0% found this document useful (0 votes)
3 views1 page

Arduino Code Explanation CodeAlpha

The document explains an Arduino code that initializes hardware settings and continuously reads an LDR sensor value. It compares the reading to a threshold of 500 to control an LED, turning it ON or OFF based on the light level. The code facilitates an automatic light control system using the LDR and Arduino.

Uploaded by

R. SRIVIDHYA
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Arduino Code Explanation CodeAlpha

The document explains an Arduino code that initializes hardware settings and continuously reads an LDR sensor value. It compares the reading to a threshold of 500 to control an LED, turning it ON or OFF based on the light level. The code facilitates an automatic light control system using the LDR and Arduino.

Uploaded by

R. SRIVIDHYA
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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.

You might also like