2.Light-Controlled LED Using an LDR and Arduino
Light-Controlled LED Using an LDR and Arduino Components Needed: Arduino board LDR (photoresistor) 10kΩ resistor LED 220Ω resistor Breadboard and jumper wires Circuit Connections: LDR Circuit : Connect one leg of the LDR to 5V on the Arduino. Connect the other leg of the LDR to an analog input pin (e.g., A0) and a 10kΩ resistor. Connect the other end of the 10kΩ resistor to GND. LED Circuit : Connect the anode (longer leg) of the LED to a digital pin (e.g., 13). Connect a 220Ω resistor in series with the cathode of the LED, and connect the other end of the resistor to GND. Example Code: C++ Code int ldrPin = A0; // Analog pin for LDR int ledPin = 13 ; // Digital pin for LED int threshold = 500 ; // Threshold value for light level void setup () { pinMode (ledPin, OUTPUT); // Set LED pin as output Serial. begin ( 9600 ); // Start serial communication } void loop () { int ldrValue = analogRead (ldrPin); // Read LDR value Serial. println (ldrValue); ...