Control LED by light
I created a straightforward project demonstrating a simple light-activated switch using a photoresistor. A photoresistor, also known as a light-dependent resistor (LDR), changes its resistance based on the amount of light it receives. When it’s dark, the resistance is high; when it’s light, it is low.
Components:
- Arduino Uno
- Photoresistor
- Resistor (10 kΩ)
- LED
- Resistor (330 Ω)
- Jumper wires
Setup:
- Connect one leg of the photoresistor to the 5V pin of the Arduino and the other leg to a digital pin (e.g., pin 2) through a 10 kΩ resistor.
- Connect the LED to another digital pin (e.g., pin 3) through a 330 Ω resistor.
Upload the following code to your Arduino:
int photo = A0; int led = 7; void setup() { pinMode(led, OUTPUT); } void loop() { int lightRaw = analogRead(photo); int light = map(lightRaw, 1023, 0, 10, 0); if (light < 6) { digitalWrite(led, HIGH); } else { digitalWrite(led, LOW); } }
Future Developments
- One potential future development for this project would be to create a more sophisticated light-activated switch that could be used in various applications. For example, the switch could turn on lights automatically when it gets dark or open and close doors or windows.
- Another possibility would be integrating the switch into a more extensive system, such as a home automation system. This would allow users to control their lights and other devices with their smartphones or tablets.
- Additionally, the switch could be made more user-friendly by adding features such as a dimmer switch or a timer. This would allow users to customize the switch’s behavior to suit their needs.
Overall, this project has many potential future developments. With creativity and ingenuity, the light-activated switch could be used in various ways to make our lives easier and more convenient.I had a lot of fun with this assignment! It was really cool to see how a simple idea could be turned into a daily application that we can use to save electricity.