Build it step by step
0 of 6 doneWire the sensor and buzzer
Connect them to the XIAO as in the table.
Check the angle
Print the angle and tilt the board to see 0 to 90 degrees.
Mark the rail
Fix the sensor with its X arrow up the ladder.
Test the safe band
Lean the ladder at about 75 degrees and check it stays quiet.
Test the alarms
Make it steeper, then flatter, and then give it a quick shake.
Check the sleep
Lay it flat and confirm it stops beeping and draws almost nothing.
How do you build a ladder tilt alarm?
An accelerometer on a ladder beeps if the angle is too steep or too shallow, or if it starts to slip. An aid only; always check a ladder before use. You need Seeed XIAO ESP32C3, LIS3DH accelerometer, Active buzzer 5 V and Li-Po battery 3.7 V 500 mAh. It takes 6 steps and about 90 minutes.
- Level
- Beginner
- Time
- About 90 min
- Parts
- 4
Parts list
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| LIS3DH VCC, GND | XIAO 3V3, GND | Power |
| LIS3DH SDA, SCL | XIAO D4, D5 | I2C |
| Active buzzer + | XIAO D10 | Alarm |
| Active buzzer - | XIAO GND | Return |
| LiPo battery + and - | XIAO BAT+ and BAT- pads on the back | Powers and charges through USB-C |
Code
Arduino IDE with the ESP32 boards package, board "XIAO_ESP32C3". Install "Adafruit LIS3DH" and "Adafruit Unified Sensor". Fix the sensor to the ladder rail with its X arrow pointing up the rail. The 4 in 1 rule gives about 75 degrees; this alarm is a reminder, not a safety system. Always check the ladder, footing and condition before climbing and have a second person foot it where possible. Use a LiPo with a protection circuit and the correct connector polarity.
Runs on a virtual Seeed XIAO ESP32-C3 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 <Wire.h>
#include <Adafruit_LIS3DH.h>
#include <Adafruit_Sensor.h>
Adafruit_LIS3DH lis = Adafruit_LIS3DH();
const byte BUZZER = D10;
const float SAFE_MIN = 70.0, SAFE_MAX = 80.0; // degrees from horizontal; 75 is the common 4 in 1 guidance
unsigned long badSince = 0;
float angleNow(float &jerk) {
static float lastMag = 9.81;
sensors_event_t e; lis.getEvent(&e);
float mag = sqrt(e.acceleration.x * e.acceleration.x + e.acceleration.y * e.acceleration.y + e.acceleration.z * e.acceleration.z);
jerk = fabs(mag - lastMag); lastMag = mag;
// X axis along the ladder rail, pointing up
return atan2(e.acceleration.x, sqrt(e.acceleration.y * e.acceleration.y + e.acceleration.z * e.acceleration.z)) * 180.0 / PI;
}
void beep(int ms) { digitalWrite(BUZZER, HIGH); delay(ms); digitalWrite(BUZZER, LOW); }
void setup() {
pinMode(BUZZER, OUTPUT);
Wire.begin();
lis.begin(0x18);
lis.setRange(LIS3DH_RANGE_4_G);
float j; float a = angleNow(j);
if (a < 20) { // lying flat: not in use, sleep and check again in 5 s
esp_sleep_enable_timer_wakeup(5ULL * 1000000ULL);
esp_deep_sleep_start();
}
}
void loop() {
float jerk; float a = angleNow(jerk);
if (jerk > 4.0) { for (byte i = 0; i < 5; i++) { beep(80); delay(60); } } // sudden movement: possible slip
bool bad = a < SAFE_MIN || a > SAFE_MAX;
if (bad) { if (badSince == 0) badSince = millis(); } else badSince = 0;
if (bad && millis() - badSince > 2000) { beep(300); delay(500); } // wrong angle for 2 seconds
if (a < 20) { // laid down again
esp_sleep_enable_timer_wakeup(5ULL * 1000000ULL);
esp_deep_sleep_start();
}
delay(50);
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Ladder at about 75 degrees | Quiet |
| Too steep or too flat for 2 seconds | Slow repeated beeps |
| Sudden shake | Five quick beeps |
| Laid flat | Goes to sleep |
If it does not work
Beeps constantly
X axis is not along the rail. Remount or change the axis in the code.
Never beeps
Check the buzzer wiring and that D10 matches the pin used.
Wrong angle
Check the sensor orientation and that the X arrow points up.
Will not wake
Tip it above 20 degrees within 5 seconds of a wake check.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the ladder tilt alarm?
Seeed XIAO ESP32C3, LIS3DH accelerometer, Active buzzer 5 V and Li-Po battery 3.7 V 500 mAh.
How long does the ladder tilt alarm take to build?
About 90 minutes for a beginner maker, in 6 steps.
How do I know the ladder tilt alarm works?
Ladder at about 75 degrees: Quiet. Too steep or too flat for 2 seconds: Slow repeated beeps. Sudden shake: Five quick beeps.
Beeps constantly: what should I check?
X axis is not along the rail. Remount or change the axis in the code.
Never beeps: what should I check?
Check the buzzer wiring and that D10 matches the pin used.
Wrong angle: what should I check?
Check the sensor orientation and that the X arrow points up.
Will not wake: what should I check?
Tip it above 20 degrees within 5 seconds of a wake check.
