-
1Wiring All The Components
![]()
Wiring the LDR SensorCreate a voltage divider
- LDR leg1 - 5v
- LDR leg 2 - A0
- 10k resistor between A0 and GND
This setup gives the Arduino a changing voltage that represents brightness.
Wiring the Relay Module
- Relay VCC - 5v
- Relay GND - GND
- Relay IN - Digital Pin 2
LEDStripPower
For a 12v LED Strip:
- LED strip + directly to 12V supply
- LED strip - to COM on relay
- Relay NO to the 12v supply ground
The relay will switch the strip ON/OFF by controlling the ground connection.
-
2Uploading The Code
Use the Arduino IDE The sketch below reads the LDR, checks if it's dark, and switches the relay.
// Beginner-friendly: Read button on pin 6 and control a relay on pin 2 // Wiring (recommended): // - Relay module VCC -> 5V // - Relay module GND -> GND // - Relay module IN -> Arduino digital pin 2 // - Button one side -> Arduino pin 6 // - Button other side -> GND // Note: This sketch uses INPUT_PULLUP, so button connects to GND when pressed. const int RELAY_PIN = 2; // Relay control pin const int BUTTON_PIN = 7; // Input pin (button or switch) // If your relay module is "active LOW" (common for many modules), set true. // If your relay turns ON when IN is HIGH, set false. const bool RELAY_ACTIVE_LOW = false; void setup() { Serial.begin(9600); // Optional: debug output to Serial Monitor pinMode(RELAY_PIN, OUTPUT); // Relay pin is an output pinMode(BUTTON_PIN, INPUT_PULLUP); // Use the internal pull-up resistor // Make sure relay starts OFF if (RELAY_ACTIVE_LOW) digitalWrite(RELAY_PIN, HIGH); // HIGH -> off for active-low relay else digitalWrite(RELAY_PIN, LOW); // LOW -> off for active-high relay Serial.println("Ready. Press the button to turn the relay ON."); } //Made By Rohan Barnwal void loop() { // Read the button. Because of INPUT_PULLUP, pressed == LOW. int raw = digitalRead(BUTTON_PIN); bool pressed = (raw == LOW); // true when button is pressed // Simple debounce: when we detect a press state change, wait briefly and re-read. static bool lastPressed = false; if (pressed != lastPressed) { delay(30); // small debounce delay (30 ms) raw = digitalRead(BUTTON_PIN); pressed = (raw == LOW); lastPressed = pressed; } // Turn relay on or off based on button if (pressed) { // Turn relay ON if (RELAY_ACTIVE_LOW) digitalWrite(RELAY_PIN, LOW); // active-low -> LOW turns ON else digitalWrite(RELAY_PIN, HIGH); // active-high -> HIGH turns ON Serial.println("Relay: ON"); } else { // Turn relay OFF if (RELAY_ACTIVE_LOW) digitalWrite(RELAY_PIN, HIGH); // active-low -> HIGH turns OFF else digitalWrite(RELAY_PIN, LOW); // active-high -> LOW turns OFF Serial.println("Relay: OFF"); } delay(100); // small loop delay to avoid flooding Serial } -
3Testing
- Cover the LDR with your hands - LED strip should turn ON
- Shine a light - LED strip should turn OFF
Taking It to the Next Level - With JUSTWAY
Your breadboard prototype may work perfectly, but looks like a tech spaghetti bowl.
When you want to impress at a science fair, competition, or investor meeting presentation is everything.
That's where JUSTWAY comes in.
JUSTWAY helps you transform your DIY project into a professional grade prototype, complete with a custom enclosure, metal finish, or injection-molded body - ready for the world to see.
Why JUSTWAY is the Perfect Partner
- Rapid Prototyping: 24-hour turnaround, real time order tracking
- CNC Machining: Aluminum 6061 or Stainless Steel 304 - strong, premium enclosures
- Sheet Metal Fabrication: Laser-cut CNC-bent and powder coated finishes
- Injection Molding: Ideal for moving from prototype to mass production
- Urethane Casting: Perfect for small batches or display models
- 3D Printing (SLA / HP-PA12): SLA resin for clear aesthetic display, HP-PA12 nylon for durable, matte finish
Pro Tip: Want your circuit look futuristic?
- Use transparent SLA resin to show off your Arduino and LEDs
- Or go matte black HP-PA12 for a stealthy, modern vibe.
How To Order in 4 Easy Steps
Step1: Upload You CAD Files at JUSTWAY.com
![]()
Step2: Select Material & Finish - plastics, resins or metals
![]()
Step 3: Preview Your Model in 3D - Check fit and look before confirming
![]()
Step 4: Place Your Order - Fast Delivery, Transparent Pricing, Zero Hidden Costs.
![]()
Conclusion
You now have a simple and reliable automatic lighting controller using an LDR, relay, and Arduino UNO Mini. This system is great for bedrooms, hallways, stair lighting, or outdoor decorative LEDs. By combining this with a 3D-printed housing from JUSTWAY, you can turn a hobby build into a neat, durable, professional-looking device.
Rohan Barnwal




Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.