Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
BETTESWORTHConstruction
Arduino

Automatic Street Light Control System With Arduino

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

An Arduino-based automatic street-light controller turns a low-voltage lamp on when ambient light falls below a calibrated threshold and turns it off again when daylight returns. The Arduino reads an LDR (photoresistor) through a voltage divider, then controls the lamp through a relay module or logic-level MOSFET. It should control the switching device—not power the lamp directly from an Arduino pin.

The circuit below is suitable for a classroom, workshop, garden-light, pathway-light, or low-voltage demonstration project. A real outdoor or mains-powered street-light installation additionally requires suitable protection, enclosure, wiring, grounding, weatherproofing, and compliance with local electrical regulations.

As an Amazon Associate I earn from qualifying purchases.

How the automatic street-light system works

The controller follows this sequence:

  1. An LDR changes resistance as surrounding light changes.
  2. The LDR and a fixed resistor form a voltage divider.
  3. The Arduino reads the divider voltage through analog input A0.
  4. The program compares the reading with calibrated dark and light thresholds.
  5. The Arduino drives a relay module or MOSFET.
  6. The switching device connects a separate power supply to the lamp.
Ambient light
     ↓
LDR + fixed resistor voltage divider
     ↓
Arduino analog input A0
     ↓
Threshold and hysteresis logic
     ↓
Arduino digital output D8
     ↓
Relay module or logic-level MOSFET
     ↓
Separate low-voltage LED/lamp supply

This is an automatic dusk-to-dawn switch, not a complete municipal smart-lighting platform. By itself it does not provide remote monitoring, energy metering, motion-based dimming, fault reporting, pole-to-pole communication, or professional surge protection.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

An Arduino Uno R3 is sufficient for the educational version. It provides six analog inputs, 14 digital I/O pins, a 10-bit ADC, and 5 V operation. The official Uno specifications list a recommended maximum of 20 mA per I/O pin and an absolute maximum of 40 mA, so a lamp must have its own supply and driver stage. See the official Uno pinout.

#1 Best Overall
Sale
ELEGOO Mega 2560 R3 Project The Most Complete Starter Kit with Tutorial | Compatible with Arduino, Ultimate Starter Kit, PDF Tutorial, 35+ Guided Projects, 200+ Components, Sensors, Displays, Motors
  • 35+ Guided Electronics Projects: Progress from LEDs and buttons to RFID access, real-time clocks, motion and distance sensing, environmental monitoring, motor control and interactive displays for STEM learning, coding clubs and maker projects
  • More I/O and Memory for Larger Builds: The MEGA 2560 R3 provides 54 digital I/O pins, including 15 PWM outputs, 16 analog inputs, 4 hardware serial ports and 256 KB flash for projects that combine more sensors, controls and displays
  • 200+ Components for Prototyping: Includes LCD1602, RC522 RFID, RTC, DHT11, HC-SR501 PIR, ultrasonic and water-level sensors, GY-521, MAX7219, keypad, joystick, rotary encoder, relay, SG90 servo, stepper motor, DC motor, breadboard and more
  • Learn, Modify and Create: Follow 35+ guided lessons with example code, then adjust sensor thresholds, timing, display text, motor behavior and control logic to turn structured exercises into access systems, monitors, alarms and interactive projects
  • Organized for Repeatable Learning: Pre-soldered modules, a solderless breadboard, storage case and small-parts box reduce setup time and keep sensors, LEDs, ICs, wires and other components easy to find between projects

Parts required

Basic low-voltage prototype

  • Arduino Uno R3 or compatible Uno board
  • LDR/photoresistor
  • 10 kΩ resistor
  • Small 5 V or 12 V LED lamp, LED module, or LED strip
  • Suitable external lamp power supply
  • Jumper wires and a breadboard for temporary testing

Choose one switching stage

  • 5 V relay module: suitable for simple on/off control of a compatible DC load, or for a professionally installed isolated load circuit.
  • Logic-level N-channel MOSFET: preferred for low-voltage DC LED lighting, silent switching, frequent operation, and PWM dimming.

Useful optional parts

  • 100–220 Ω resistor for a discrete LED
  • 10 kΩ MOSFET gate pulldown resistor
  • 100 nF capacitor for additional sensor filtering
  • Push button for manual override
  • Appropriately rated fuse for the lamp circuit
  • Weather-resistant enclosure and cable glands for outdoor use

A 10 kΩ resistor is a practical starting point for the LDR divider, not a universal requirement. The best value depends on the LDR’s resistance range and the desired sensitivity.

Wire the LDR voltage divider

Use this arrangement when you want the analog reading to be higher in bright conditions and lower in darkness:

Arduino 5V ─── LDR ───┬─── A0
                       │
                     10 kΩ
                       │
Arduino GND ───────────┘

In bright light the LDR resistance generally falls, so the voltage at A0 rises. In darkness the resistance rises and the A0 voltage generally falls. The Uno’s 10-bit ADC normally reports a value from 0 to 1023 for its 0–5 V measurement range.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If you place the fixed resistor above A0 and the LDR below it, the reading direction reverses. That is not an electrical fault; you must simply reverse the comparisons in the program.

Relay-module wiring

For the controller side, connect the relay module as follows:

Relay VCC  → Arduino 5V or an appropriate regulated supply
Relay GND  → Arduino GND
Relay IN   → Arduino D8

Connect the lamp to the relay’s contact terminals only after checking the module’s coil voltage and contact ratings. The relay’s printed rating may apply only to particular voltage, current, and load types. A relay module may also be active-low, meaning that a LOW signal turns it on.

Mechanical relays are useful for straightforward on/off switching and can provide isolation between control and load circuits. They click, wear over time, cannot normally dim an LED, and can produce electrical noise. A relay contact does not make an unsafe mains circuit safe.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
ELEGOO UNO R3 Project Super Starter Kit with PDF Tutorial for Beginners | Compatible with Arduino, 22+ Hands-on Projects, Upgraded Starter Kits with Power Supply, STEM, DIY Basic Circuit Building
  • TURN CODE INTO REAL-WORLD RESULTS — Follow 22+ guided lessons to make LEDs blink, read temperature and distance, move servo and stepper motors, control an LCD and respond to joystick or IR input; ideal for a family weekend build, homeschool unit, coding club or STEM classroom
  • MORE PROJECT VARIETY IN ONE ORGANIZED KIT — Includes the UNO R3 controller, LCD1602 with pre-soldered header, breadboard power module, ultrasonic and DHT11 sensors, joystick, IR receiver and remote, SG90 servo, stepper motor, relay, DC motor, fan blade, displays, LEDs, buttons, resistors and jumper wires
  • START WITHOUT SOLDERING — Plug-in modules, a solderless breadboard and the pre-soldered LCD help beginners focus on wiring, code and testing; the illustrated component list makes it easier to find each part and move from one lesson to the next
  • LEARN THE LOGIC, THEN CREATE YOUR OWN — Use Arduino IDE and the included example code to understand digital input and output, analog sensing, timing, motor control and display functions, then change thresholds, speeds and sequences for alarms, environmental monitors, reaction games and motion projects
  • CLEAR SETUP SUPPORT FOR FIRST-TIME BUILDERS — Download the latest tutorial and code, select the UNO board and correct computer port, check component polarity and breadboard rows, and keep power-module input at 9V or below; younger learners should work with an experienced adult

An Arduino Project Hub daylight-light example demonstrates the general arrangement, but its example AC connection should not be treated as a finished mains installation.

MOSFET wiring for a low-voltage DC lamp

A MOSFET is usually the better choice for a 5–12 V DC LED lamp:

External LED supply + ─── LED lamp +
                         LED lamp − ─── MOSFET drain
Arduino GND ───────────── MOSFET source
Arduino D9 ──100–220 Ω── MOSFET gate
MOSFET gate ──10 kΩ───── GND
External supply GND ──── Arduino GND

The Arduino controls the gate; it does not carry the lamp current. Select a logic-level N-channel MOSFET with a low RDS(on) specified at the actual gate voltage. Do not select an IRF520 module solely because it is common in beginner kits: its gate-voltage behavior may be unsuitable for efficient operation at 5 V or 3.3 V.

The Arduino and the external DC supply normally need a common ground for a non-isolated MOSFET circuit. Use a suitably rated LED module or current-controlled LED driver. A bare LED must have current limiting, typically including an appropriate series resistor.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Arduino code with averaging and hysteresis

This sketch is for the divider arrangement shown above and a relay module on D8. The threshold values are examples only and must be calibrated on the completed circuit.

const byte LDR_PIN = A0;
const byte LIGHT_PIN = 8;

// Common relay-module behavior: LOW turns the relay on.
const bool RELAY_ACTIVE_LOW = true;

// Calibrate these values using the Serial Monitor.
const int DARK_THRESHOLD = 350;  // Turn lamp ON below this value
const int LIGHT_THRESHOLD = 500; // Turn lamp OFF above this value

const byte SAMPLE_COUNT = 16;
const unsigned long SAMPLE_INTERVAL_MS = 1000;

bool lampOn = false;
unsigned long lastSampleTime = 0;

void setLamp(bool on) {
  lampOn = on;

  if (RELAY_ACTIVE_LOW) {
    digitalWrite(LIGHT_PIN, on ? LOW : HIGH);
  } else {
    digitalWrite(LIGHT_PIN, on ? HIGH : LOW);
  }
}

int readAverageLight() {
  long total = 0;

  for (byte i = 0; i < SAMPLE_COUNT; i++) {
    total += analogRead(LDR_PIN);
    delay(5);
  }

  return total / SAMPLE_COUNT;
}

void setup() {
  Serial.begin(9600);
  pinMode(LDR_PIN, INPUT);
  pinMode(LIGHT_PIN, OUTPUT);

  // Fail-safe startup state.
  setLamp(false);
}

void loop() {
  if (millis() - lastSampleTime < SAMPLE_INTERVAL_MS) {
    return;
  }

  lastSampleTime = millis();
  int lightLevel = readAverageLight();

  Serial.print("Light level: ");
  Serial.print(lightLevel);
  Serial.print(" | Lamp: ");
  Serial.println(lampOn ? "ON" : "OFF");

  // Turn on only when clearly dark.
  if (!lampOn && lightLevel < DARK_THRESHOLD) {
    setLamp(true);
  }

  // Turn off only when clearly bright.
  if (lampOn && lightLevel > LIGHT_THRESHOLD) {
    setLamp(false);
  }
}

The startup state deliberately keeps the lamp off until the first measurement is taken. If the project must default to a different state during a reset, change that behavior deliberately and consider what should happen if the sensor or controller fails.

If the sensor direction is reversed

When darkness produces a higher analog value, use:

if (!lampOn && lightLevel > DARK_THRESHOLD) {
  setLamp(true);
}

if (lampOn && lightLevel < LIGHT_THRESHOLD) {
  setLamp(false);
}

If using a MOSFET instead of a relay

For simple on/off switching on a MOSFET gate connected to D9:

Rank #3
Sale
ELEGOO UNO R3 Project Most Complete Starter Kit, Compatible with Arduino | 63 Items, 200+ Components, 30+ Guided Projects, PDF Tutorial, Organized Storage, STEM and DIY Circuit Building
  • 30+ Guided Electronics Projects: Start with LEDs and build toward LCD1602 displays, RFID access, motion detection, distance sensing, motor control and environmental monitoring for STEM learning, coding clubs, classrooms and hobby projects
  • 200+ Components Across 63 Types: Includes an ELEGOO UNO R3 controller, LCD1602, RC522 RFID, RTC, HC-SR501 PIR sensor, ultrasonic sensor, DHT11, GY-521, MAX7219, keypad, joystick, relay, SG90 servo, stepper motor, breadboard and more
  • Begin Without Soldering: Pre-soldered modules, a solderless breadboard, organized storage case and small-parts box reduce setup time and help beginners move from lesson to lesson while keeping LEDs, ICs, wires and sensors easy to find
  • Learn, Modify and Create: Program the ELEGOO UNO R3 board with Arduino IDE using the included PDF tutorial and example code, then adjust sensor thresholds, timing, display text and motor behavior to turn guided lessons into original projects
  • Flexible Power and Project Setup: Includes a 9 V, 1 A power supply, breadboard power module, 9 V battery and USB cable to support controller, breadboard and module experiments without sourcing basic setup accessories separately
const byte LIGHT_PIN = 9;

void setLamp(bool on) {
  lampOn = on;
  digitalWrite(LIGHT_PIN, on ? HIGH : LOW);
}

For PWM brightness control, use a PWM-capable Uno pin such as D9:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
analogWrite(LIGHT_PIN, 128); // approximately half duty cycle

The Uno supports PWM on pins 3, 5, 6, 9, 10, and 11. See the official pinout.

Upload and test the controller

  1. Connect only the LDR divider and Arduino.
  2. Upload the sketch.
  3. Open the Serial Monitor at 9600 baud.
  4. Record the reading in full daylight.
  5. Cover the LDR and record the reading in darkness.
  6. Expose the sensor to the actual dusk-like conditions in which the lamp should turn on.
  7. Choose a dark threshold between the relevant readings.
  8. Choose a light threshold sufficiently higher than the dark threshold.
  9. Test the switching output with a small low-voltage LED.
  10. Only then connect the intended low-voltage lamp and its correctly rated supply.

Do not copy a threshold such as 290, 400, or 600 as though it represented a universal darkness level. The reading depends on the LDR, resistor, board voltage, wiring orientation, sensor cover, mounting position, and surrounding light.

Why hysteresis prevents flicker

A single threshold can cause rapid switching at dawn and dusk. Clouds, vehicle headlights, shadows, reflections, and electrical noise can move the reading back and forth around the boundary. Hysteresis uses separate turn-on and turn-off points:

Lamp turns ON  below 350
Lamp turns OFF above 500

After the lamp turns on, the reading must rise above the higher threshold before it turns off. This prevents relay chatter and makes the system more stable. The exact values must be measured for the finished installation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Sensor placement is critical

Do not mount the LDR where it can see the lamp it controls. Otherwise the system can oscillate:

  1. Darkness causes the lamp to turn on.
  2. The lamp illuminates the LDR.
  3. The Arduino interprets that light as daytime.
  4. The lamp turns off.
  5. Darkness returns and the cycle repeats.

Place the sensor where it sees ambient sky light but is shielded from the controlled lamp. A short opaque hood can block direct glare while allowing diffuse daylight to reach the LDR. An Arduino Forum discussion describes this common placement problem.

Rank #4
SunFounder Elite Explorer Kit with Original Arduino® UNO™ R4 WiFi, Powered by Arduino, RoHS Compliant, Bluetooth IoT ESP32 LCD1602 OLED, Super Starter Kit, Video Courses for Beginners & Engineers
  • All-in-One Starter Kit for Beginners: Part of the Powered by Arduino program, this kit includes an original Arduino UNO R4 WiFi, 300+ high-quality components, 50+ hands-on projects (30 basic, 13 fun, and 8 IoT), and 100+ free video lessons co-created with renowned educator Paul McWhorter. Designed for beginners ages 8+, it provides a complete, step-by-step path to learn Arduino, electronics, coding, and IoT. RoHS compliant for added safety and quality, it also makes a thoughtful gift for tech enthusiasts, students, and aspiring makers for birthdays, holidays, and special occasions
  • Powerful Arduino Uno R4 WiFi Board: Upgraded from the Arduino Uno R3, the Arduino Uno R4 WiFi features a 32-bit processor, more memory, and built-in WiFi and Bluetooth, enabling connection to third-party apps for more interactive and practical projects.
  • 300+ Components for Endless Possibilities: With 300+ components and sensors, this kit is perfect for portable projects. It features step-by-step tutorials, open-source code, and compatibility with other Arduino boards like Uno R3 and Nano, offering endless customization and learning opportunities.
  • Engaging Projects for Every Skill Level: Featuring 50 projects (30 basic, 13 fun, 8 IoT) with IoT app integration like Arduino IoT Cloud , this kit supports Arduino C++ programming, making it perfect for students, teachers, and engineers to learn, code, and create at any skill level.
  • Dedicated Support for Beginners: Alongside online resources and video tutorials, SunFounder provides technical support and troubleshooting forums to help beginners solve programming challenges with ease.

Also consider headlights, porch lights, reflections, shadows, condensation, dirt, insects, nearby LED lighting, seasonal changes, and artificial light pollution. Averaging helps with short noise spikes, but it cannot correct poor placement.

Troubleshooting

Symptom Likely cause Fix
Lamp works backward Divider orientation or comparisons are reversed Print readings and reverse the conditions if necessary
Relay clicks repeatedly No hysteresis, noisy readings, or lamp light reaching the LDR Use separate thresholds, averaging, and better sensor placement
Relay is always on Active-low module treated as active-high Change RELAY_ACTIVE_LOW
Arduino resets when lamp turns on Supply droop, electrical noise, or inadequate shared supply Use a correctly sized supply and appropriate filtering or suppression
Lamp is dim or unreliable Arduino pin is being used to power the lamp Use a MOSFET or properly driven relay with a separate lamp supply
Analog value is unstable Long sensor wires, poor grounding, or interference Shorten wires, improve grounding, add filtering, and average samples
LED is damaged Missing current limiting or unsuitable driver Use a suitable resistor, constant-current driver, or rated LED module
Relay does not trigger Incorrect coil voltage or incompatible logic level Verify the module’s input requirements and supply voltage
Outdoor circuit fails after rain No weatherproof enclosure or cable sealing Use outdoor-rated components, enclosure, and cable glands
Arduino power is unreliable Incorrect input voltage or conflicting power sources Follow official Uno power guidance

The official Arduino guidance discusses suitable power arrangements and warns against treating high-power components as ordinary Arduino loads. The Uno’s listed recommended external input range is 7–12 V, with a stated input limit of 6–20 V; unsuitable voltage can cause instability, overheating, or damage. See Arduino’s power-supply guidance and the official Uno specifications.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Outdoor construction and installation considerations

A breadboard is appropriate only for temporary, low-voltage bench testing. An outdoor controller needs:

  • Weather-resistant enclosure appropriate to the environment
  • Sealed cable entries and strain relief
  • Protection against condensation, insects, dirt, and ultraviolet exposure
  • Suitable wire gauge and connectors
  • A fuse or other overcurrent protection appropriate to the lamp circuit
  • Safe separation between low-voltage control wiring and hazardous-voltage wiring
  • Accessible maintenance and replacement points
  • A sensor position that remains representative as landscaping and nearby lighting change

For a permanent construction or property installation, a commercial photocell or lighting controller may be more appropriate than an exposed general-purpose Arduino board. The Arduino prototype is valuable for demonstrating the control logic, but outdoor reliability depends on the entire power, enclosure, wiring, and maintenance design.

Mains safety

Do not place exposed 120 V AC or 230 V AC wiring on a breadboard. Do not connect or modify energized mains terminals. A mains implementation requires a correctly rated relay or contactor, suitable enclosure, strain relief, overcurrent protection, protective earthing where required, adequate creepage and clearance, suitable wire gauge, weather and condensation protection, and compliance with local electrical codes.

The Arduino only supplies a control signal to the switching device. The switching device, enclosure, and installation must all be rated for the actual load and environment. Have hazardous-voltage work performed or inspected by a qualified person where local rules require it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Solar-powered version

A solar street-light prototype needs more than an Arduino and a solar panel. It normally includes a solar panel, charge controller, battery, battery protection, DC-DC regulation, an LED driver or suitable switching stage, low-voltage cutoff, and a weatherproof enclosure.

Best Value
Sale
REXQualis Super Starter Kit Based on Arduino UNO R3 with Tutorial and Controller Board Compatible with Arduino IDE
  • The most economical kit comes with everything compatible with Arduino to starting programming for beginners .
  • This is the upgraded starter kits come with a 9V 1A Power Adapter (At least $5.99 on amazon) to replace a 9V Battery , and the Lcd1602 module come with pin header(not need to be soldered by yourself).
  • Include High Quality Base Board base on Arduino UNO R3 compatible with Arduino IED and Sensors, Servo, Motor, ULN2003 driver board, lcds, etc.
  • Free PDF Tutorial and Datasheet are available to download from our official website or you can contact our customer service.
  • All of the Components and Integrated Circuits are individually packaged and labeled, and packing in a plastic box which is bigger enough for you.

Never connect a panel or battery directly to an Arduino I/O pin. Battery voltage varies substantially, and the lamp may require far more current than the Arduino regulator or output pins can provide.

Useful design upgrades

Motion-based dimming

Add a PIR or other motion sensor so the lamp remains dim or off during darkness when no one is present and rises to full brightness when movement is detected. This can reduce energy use, but it introduces detection-range, false-trigger, timeout, and weather-related design questions.

RTC scheduling

A real-time clock can limit operation to programmed hours. It does not automatically adapt to unusual weather or seasonal daylight changes, so combining schedule limits with an LDR can be more flexible.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Manual override

A physical switch or button allows maintenance staff to force the lamp on or off. A useful design should define whether manual mode is temporary, latched, or restored after a reset.

Fault detection

A more robust controller can identify readings that remain permanently near 0 or 1023, indicating a disconnected or saturated sensor. It can then enter a defined fallback state rather than silently making an unsafe assumption.

Network monitoring

The Uno R3 does not include built-in Wi-Fi or Bluetooth. An Uno R4 WiFi or another network-capable controller can add status reporting and remote configuration, but it also increases software, power, security, and maintenance requirements. Networking is usually unnecessary for a single local lamp.

Choosing between relay and MOSFET

Option Best suited to Main advantages Main limitations
LDR plus relay Simple educational on/off control Easy to understand; can switch compatible AC or DC loads through contacts Mechanical wear, audible switching, no simple dimming, greater safety risk for mains
LDR plus MOSFET Low-voltage DC LED lighting Silent, efficient, fast, suitable for frequent switching and PWM Requires correct gate-voltage selection; does not directly switch AC
LDR plus motion sensor Energy-saving pathway or security lighting Allows brightness to respond to occupancy More sensors, timing decisions, and false-trigger behavior
RTC plus LDR Predictable operating windows Combines scheduled limits with daylight confirmation More components and configuration

What this prototype can—and cannot—claim

The circuit can demonstrate automatic light activation when an LDR reading crosses calibrated thresholds. It may reduce energy use compared with an unnecessarily long fixed schedule, but savings depend on the previous system, lamp efficiency, controller consumption, and operating pattern.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

It does not automatically become a production-grade street-light system. Real deployment requires engineered power distribution, protection, environmental sealing, fault handling, maintenance planning, and regulatory compliance.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.