The Best DIY STEM Tutorials and Projects

OVERVIEW
This project creates a smart night light that automatically turns on in the dark and off in bright light using an LDR (Light Dependent Resistor). It’s a great way to learn how sensors work and how we can use them to automate everyday tasks. Perfect for making your own energy-saving night light! ✨🔆
You can follow this video and the instructions below.
Video
Program / Code
Code is Explained in the Comments of the Code
const int ldrPin = A0; // Connect LDR to Analog Pin A0 const int ledPin = 7; // Connect LED to Pin 7 void setup() { Serial.begin(9600); // Set Serial Monitor to 9600 baud rate pinMode(ledPin, OUTPUT); // Set LED pin as output } void loop() { int ldrValue = analogRead(ldrPin); // Read LDR value Serial.println(ldrValue); // Print LDR value to Serial Monitor // If LDR value is above 128 (light), turn LED off if (ldrValue > 128) { digitalWrite(ledPin, LOW); // Turn LED off } // Else (dark), turn LED on else { digitalWrite(ledPin, HIGH); // Turn LED on } delay(100); // Wait for 100ms before taking next reading }
Thank you so much for going through our tutorial, we hope it was easy to follow and you enjoyed it, please share your feedback and pictures of the project (if you have made it) in the comments below .!