Projects / Model lighthouse

Model lighthouse

Beginner1.2 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. NANO59°19.0 mA

    Fit the LED to the servo horn

    With tape and a loop of slack in thin wires.

  2. NANO854 lux

    Build the light divider

    LDR from 5V to A0 with the 10 kilohm resistor from A0 to GND.

  3. NANO

    Wire the pot

    Outer legs to 5V and GND, middle to A1.

  4. NANO

    Upload the sketch

    In a bright room the lamp stays off.

  5. NANO857 lux

    Cover the LDR

    The lamp comes on and the beam sweeps.

  6. NANO

    Turn the pot

    The sweep gets faster or slower.

  7. NANO858 lux

    Uncover the LDR

    The lamp switches off.

In short

How do you build a model lighthouse?

A bright LED on a servo sweeps a beam round a model lighthouse, and a light sensor switches the lamp on at dusk and off at dawn. A knob sets the speed of the sweep. It is a charming night light for a shelf. Do not look straight into a bright LED. You need Arduino Nano, SG90 Micro Servo, LDR Photoresistor, Resistor 10 kΩ, LED 5 mm red, Resistor 220 Ω, Potentiometer 10 kΩ, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 70 minutes.

Level
Beginner
Time
About 70 min
Parts
9

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Servo signal (orange)Nano D9Swings the lamp
Servo red and brownNano 5V and GNDServo power, a very light load only
LED long legNano D6 through a 220 ohm resistor, short leg to GNDThe lamp, fixed to the servo horn
LDR leg 1Nano 5VTop of the light sensor divider
LDR leg 2Nano A0 and one leg of the 10 kilohm resistorReads the light level
10 kilohm resistor other legNano GNDBottom of the divider
Pot outer legsNano 5V and GNDSpeed knob supply
Pot middle legNano A1Sets the sweep speed

Code

The light sensor and the 10 kilohm resistor make a voltage divider: in daylight the reading is high, and at night it is low. The sketch uses two thresholds, 300 to switch on and 450 to switch off, so a reading hovering around one value at dusk does not make the lamp flicker. At night the LED comes on and the servo steps from 20 to 160 degrees and back, one degree at a time, with a pause of one and a half seconds, with the lamp off, at each end of the sweep. The pot sets how long each step takes, so the beam is faster or slower. Fix the LED to the servo horn with tape, using thin flexible wires and a loop of slack so nothing is pulled, and keep the LDR out of the beam so the lamp does not turn itself off; mounting it on the back of the base works well. Use a card cone around the LED to make a beam, and do not look straight into the LED. Adjust the two thresholds for your room by watching the readings on the serial monitor.

Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <Servo.h>

const uint8_t SERVO_PIN = 9;
const uint8_t LED_PIN = 6;
const uint8_t LDR_PIN = A0;
const uint8_t POT_PIN = A1;

const int DARK_BELOW = 300;       // lamp on when the reading falls below this
const int LIGHT_ABOVE = 450;      // lamp off when it rises above this (stops flicker at dusk)
const int MIN_ANGLE = 20;
const int MAX_ANGLE = 160;
const unsigned long GAP_MS = 1500;

Servo lamp;
int angle = MIN_ANGLE;
int dir = 1;
bool night = false;
unsigned long lastStep = 0;
unsigned long gapUntil = 0;

void setup() {
  pinMode(LED_PIN, OUTPUT);
  lamp.attach(SERVO_PIN);
  lamp.write(angle);
  Serial.begin(9600);
}

void loop() {
  int light = analogRead(LDR_PIN);
  if (!night && light < DARK_BELOW) { night = true; Serial.println("Dusk: lamp on"); }
  if (night && light > LIGHT_ABOVE) { night = false; Serial.println("Dawn: lamp off"); }

  unsigned long now = millis();
  if (!night) {
    digitalWrite(LED_PIN, LOW);
    return;
  }

  if (now < gapUntil) {                         // pause between sweeps with the lamp dark
    digitalWrite(LED_PIN, LOW);
    return;
  }

  digitalWrite(LED_PIN, HIGH);
  unsigned long stepEvery = map(analogRead(POT_PIN), 0, 1023, 8, 60);   // knob sets speed
  if (now - lastStep >= stepEvery) {
    lastStep = now;
    angle += dir;
    lamp.write(angle);
    if (angle >= MAX_ANGLE || angle <= MIN_ANGLE) {
      dir = -dir;
      gapUntil = now + GAP_MS;
    }
  }
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Bright roomLamp off, servo still
Dark roomLamp on, beam sweeping
Pot turnedSweep speed changes
End of each sweepA short dark pause
Serial monitorPrints dusk and dawn

If it does not work

Lamp never turns on

Check the LDR divider and try raising DARK_BELOW.

Lamp flickers at dusk

Widen the gap between the two thresholds.

Servo jitters or the Nano resets

The load is too heavy, use a lighter servo load or a separate 5V supply.

Lamp turns off by itself

Its own light is reaching the LDR, shield the sensor.

Sweep never changes speed

Check the pot middle leg goes to A1.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the model lighthouse?

Arduino Nano, SG90 Micro Servo, LDR Photoresistor, Resistor 10 kΩ, LED 5 mm red, Resistor 220 Ω, Potentiometer 10 kΩ, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).

How long does the model lighthouse take to build?

About 70 minutes for a beginner maker, in 7 steps.

How do I know the model lighthouse works?

Bright room: Lamp off, servo still. Dark room: Lamp on, beam sweeping. Pot turned: Sweep speed changes.

Lamp never turns on: what should I check?

Check the LDR divider and try raising DARK_BELOW.

Lamp flickers at dusk: what should I check?

Widen the gap between the two thresholds.

Servo jitters or the Nano resets: what should I check?

The load is too heavy, use a lighter servo load or a separate 5V supply.

Lamp turns off by itself: what should I check?

Its own light is reaching the LDR, shield the sensor.