Success means a working device that sounds a buzzer when your head nods forward while driving. You can build it in about 2–3 hours, including testing. The circuit uses a tilt switch, an Arduino Uno, and a buzzer; when your head tilts past a set angle, the buzzer wakes you.
What You Need Before You Start
Gather these parts. Most are available at electronics hobby stores or online. You will also need a small breadboard and jumper wires.
- Arduino Uno board
- USB cable (A to B) to connect to your computer
- Breadboard (half-size is fine)
- Jumper wires (male-to-male, at least 6)
- One tilt switch (mercury-free, ball-type) – it acts as the head-tilt sensor
- One buzzer (5V active or passive; active is simpler)
- One 220-ohm resistor (red-red-brown)
- Small battery pack (4×AA or 9V) with a barrel jack to power the Uno when not connected to a computer
- Headband or cap to attach the tilt switch to your head
You will also need the Arduino IDE installed on your computer. If you have not used it before, open the IDE and plug in your Uno; the board should appear under Tools > Port.
How the Tilt Switch Works
A tilt switch is a small cylinder with a metal ball inside. When the switch is upright, the ball touches two contacts and completes the circuit. When tilted past about 15–20 degrees, the ball rolls away and breaks the circuit. You will read the switch as a digital input: HIGH when upright, LOW when tilted.
Attach the switch to a headband or cap so it sits on the top of your head, oriented so that when you nod forward, the switch tilts backward. That way, the ball rolls away from the contacts exactly when your head drops.
Build the Circuit
Follow these steps to wire the components on the breadboard. Double-check each connection before powering on.
- Place the Arduino Uno on the table with the USB port facing you. Connect the breadboard to the Uno using jumper wires: one from the 5V pin to the positive rail, one from GND to the negative rail.
- Insert the tilt switch into the breadboard. Connect one leg to the 5V rail. Connect the other leg to digital pin 2 on the Uno.
- Add a 10k-ohm pull-down resistor between digital pin 2 and the GND rail. This ensures the pin reads LOW when the switch is open, preventing random noise.
- Insert the buzzer. Connect its positive leg (longer one) to digital pin 3 through the 220-ohm resistor. Connect the negative leg to GND rail.
- Double-check all connections. Then connect the Uno to your computer via USB.
Write and Upload the Code
Open the Arduino IDE and create a new sketch. Copy the code below into the editor. The code reads the tilt switch and turns on the buzzer when the switch tilts for more than half a second, to avoid false alarms from quick movements.
const int tiltPin = 2;
const int buzzerPin = 3;
int tiltState = 0;
unsigned long tiltStart = 0;
bool alarmActive = false;
void setup() {
pinMode(tiltPin, INPUT);
pinMode(buzzerPin, OUTPUT);
digitalWrite(buzzerPin, LOW);
}
void loop() {
tiltState = digitalRead(tiltPin);
if (tiltState == LOW) { // tilted
if (tiltStart == 0) {
tiltStart = millis();
}
if (millis() - tiltStart > 500) {
alarmActive = true;
}
} else {
tiltStart = 0;
alarmActive = false;
}
if (alarmActive) {
digitalWrite(buzzerPin, HIGH);
delay(200);
digitalWrite(buzzerPin, LOW);
delay(200);
} else {
digitalWrite(buzzerPin, LOW);
}
}
Upload the code by clicking the arrow button. If you get an error, check that the correct board and port are selected under Tools.
Test and Adjust the Sensitivity
Place the tilt switch on a flat surface. It should be upright. Open the Serial Monitor (Tools > Serial Monitor) and set the baud rate to 9600. You will see the raw state: 1 when upright, 0 when tilted.
- Hold the switch upright. The Serial Monitor should show 1.
- Tilt the switch forward about 20 degrees. It should show 0.
- If the switch does not change, check your wiring and the orientation of the switch.
- To make the alarm more sensitive, reduce the tilt angle by mounting the switch at a slight angle on the headband. To make it less sensitive, increase the threshold in the code by changing
500to a larger number (e.g., 800) – that means the tilt must last longer before the alarm sounds.
Mount the Sensor on Your Head
Secure the tilt switch to a headband or a cap. Use tape or a small cloth pouch. Position it on the top of your head, with the switch oriented so that when you nod forward, the switch tilts backward. The buzzer can be clipped to your collar or placed in your pocket; just make sure the wires are long enough.
Test the whole system while sitting in a chair. Nod your head forward slowly. The buzzer should sound within about half a second. If it does not, adjust the mounting angle or the delay in the code.
Power It for the Car
Once tested, you can power the Arduino from a battery pack instead of the computer. Use a 9V battery connected to the barrel jack, or a 4×AA battery pack with a barrel plug. Plug it in and confirm the alarm works.
Place the Arduino and battery securely in the car, for example under the seat or in the glovebox, so they do not move while driving. Run the wires to the headband. Make sure nothing obstructs the pedals or steering wheel.
Safety and Limitations
This device is a helper, not a substitute for rest. If you feel drowsy, the safe action is to pull over and rest. The alarm may not wake you if you are deeply asleep. Never rely on it as your only safeguard. Also, be aware that driving with a headband may be distracting; test it only when parked first.
If you wear glasses or a hat, make sure the headband does not interfere. Use a breakaway clip on the wire so it does not catch on anything.
What If the Buzzer Sounds Constantly?
If the buzzer stays on, the tilt switch is probably tilted even when your head is upright. Check the orientation: the switch should be as close to horizontal as possible when you look straight ahead. Adjust the mounting angle. Also, check that the pull-down resistor is connected correctly; without it, the pin may float and cause false readings.
What If the Buzzer Never Sounds?
First, check the wiring: the buzzer’s positive leg goes through the resistor to pin 3. Then test the buzzer by uploading a simple blink code that turns pin 3 on and off. If the buzzer works, test the tilt switch by touching the two wires together – the Serial Monitor should show 0. If not, the switch may be faulty or the pull-down resistor is missing.
Can I Use a Different Sensor?
Yes, you can use an accelerometer (like the ADXL335) for more precise tilt detection. That requires analog reading and a more complex code, but it allows adjustable thresholds without changing the mounting. For a simple build, the tilt switch is enough.
Remember: this project is for learning and personal use. Always prioritize rest and safe driving.
Related
- Sunrise Alarm Clock vs Regular Alarm: Which Fits You
- How to Eliminate Bad Arduino Project Habits
- Are Yoga Mats Anti Static? What to Know
General information for everyday wellbeing, not medical advice. If something affects your health, sleep or mood for more than a short while, talk to a qualified professional. Read more
Spotted an error? Tell us and we will correct it (corrections policy).