Build it step by step
0 of 7 doneFit a light card deck to the servo arm
Tape it so it lies flat at 0 degrees.
Wire the servo, button, LEDs and buzzer
D9, D2, D6, D7 and D8.
Upload and open the serial monitor at 9600
It says Bridge down.
Press the button
The road light goes red and the warning flashes with the bell.
Watch the deck rise
Slowly to the up position.
Press again
It warns, lowers, then the road light goes out.
Adjust UP_ANGLE
For your deck.
How do you build a model drawbridge?
A button lowers and raises a model drawbridge deck on a servo while warning lights flash and a bell sounds, and the road light stays red whenever the bridge is not fully down. A lovely first model for state machines. You need Arduino Nano, SG90 Micro Servo, Tactile push button 6 mm, LED 5 mm red × 2, Resistor 220 Ω × 2, Passive buzzer, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 80 minutes.
- Level
- Beginner
- Time
- About 80 min
- Parts
- 8
Parts list
- Development BoardsBuyArduino Nano × 1
- Motors & ActuatorsBuySG90 Micro Servo × 1
- SwitchesBuy
- SemiconductorsBuyLED 5 mm red × 2
- PassivesBuyResistor 220 Ω × 2
- Motors & ActuatorsBuyPassive buzzer × 1
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Servo signal (orange) | Nano D9 | Moves the deck |
| Servo red and brown | Nano 5V and GND | Servo power, a light card deck only |
| Button leg 1 | Nano D2 | Raise or lower request |
| Button leg 2 | Nano GND | Pressing joins D2 to ground |
| Warning LED long leg | Nano D6 through a 220 ohm resistor, short leg to GND | Flashes while the deck moves |
| Road light LED long leg | Nano D7 through a 220 ohm resistor, short leg to GND | Red while the bridge is not down |
| Passive buzzer + and - | Nano D8 and GND | The bell |
Code
Real lifting bridges follow a careful order, and this model copies it. When you press the button the road light goes red first, then the warning light flashes and the bell rings for three seconds, and only then does the deck move, slowly, one degree at a time so it looks like a heavy bridge. The road light stays red the whole time the bridge is up, and goes out only after the deck is fully down and has settled. The sketch is a simple sequence of states, with the button deciding whether to raise or lower. Use a light card deck on the servo and keep fingers clear while it moves. The servo is powered from the Nano's 5 volts, so keep the deck light, or the Nano may reset. This is a toy model for learning, never a design for a real bridge. Try adding a second button as an emergency stop, or a sensor that stops the deck if something is in the way.
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 BUTTON_PIN = 2;
const uint8_t WARN_LED = 6;
const uint8_t ROAD_LED = 7;
const uint8_t BUZZER_PIN = 8;
const uint8_t SERVO_PIN = 9;
const int DOWN_ANGLE = 0;
const int UP_ANGLE = 80;
Servo deck;
int angle = DOWN_ANGLE;
bool bridgeUp = false;
void warn(unsigned long ms) { // flash and ring the bell for a while
unsigned long start = millis();
while (millis() - start < ms) {
digitalWrite(WARN_LED, HIGH);
tone(BUZZER_PIN, 1500, 120);
delay(200);
digitalWrite(WARN_LED, LOW);
delay(200);
}
}
void moveTo(int target) { // slow, one degree at a time
while (angle != target) {
angle += (target > angle) ? 1 : -1;
deck.write(angle);
digitalWrite(WARN_LED, (millis() / 200) % 2); // keep flashing while moving
delay(25);
}
digitalWrite(WARN_LED, LOW);
}
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(WARN_LED, OUTPUT);
pinMode(ROAD_LED, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
deck.attach(SERVO_PIN);
deck.write(DOWN_ANGLE);
Serial.begin(9600);
Serial.println("Bridge down. Press the button to raise it.");
}
void loop() {
if (digitalRead(BUTTON_PIN) == LOW) {
delay(30);
while (digitalRead(BUTTON_PIN) == LOW) {} // wait for release
digitalWrite(ROAD_LED, HIGH); // road goes red first
warn(3000);
if (!bridgeUp) {
Serial.println("Raising...");
moveTo(UP_ANGLE);
bridgeUp = true;
Serial.println("Bridge up. Press to lower.");
} else {
Serial.println("Lowering...");
moveTo(DOWN_ANGLE);
bridgeUp = false;
delay(500);
digitalWrite(ROAD_LED, LOW); // road reopens only when it is fully down
Serial.println("Bridge down.");
}
}
}What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
Bridge down. Press the button to raise it.
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Button press | Road red, warning and bell for three seconds |
| Deck movement | Slow and smooth |
| Bridge up | Road light stays red |
| Lowering | Warning again, then the road reopens |
| Serial monitor | Prints each stage |
If it does not work
Servo twitches or the Nano resets
The deck is too heavy, use a lighter one.
Deck goes the wrong way
Swap UP_ANGLE and DOWN_ANGLE.
No bell
Check you have a passive buzzer on D8.
LED stays dark
Check its direction and the 220 ohm resistor.
Nothing happens on a press
Check the button is wired to D2 and GND.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the model drawbridge?
Arduino Nano, SG90 Micro Servo, Tactile push button 6 mm, LED 5 mm red × 2, Resistor 220 Ω × 2, Passive buzzer, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the model drawbridge take to build?
About 80 minutes for a beginner maker, in 7 steps.
How do I know the model drawbridge works?
Button press: Road red, warning and bell for three seconds. Deck movement: Slow and smooth. Bridge up: Road light stays red.
Servo twitches or the Nano resets: what should I check?
The deck is too heavy, use a lighter one.
Deck goes the wrong way: what should I check?
Swap UP_ANGLE and DOWN_ANGLE.
No bell: what should I check?
Check you have a passive buzzer on D8.
LED stays dark: what should I check?
Check its direction and the 220 ohm resistor.
