Projects / Running safety vest with lights

Running safety vest with lights

Beginner2 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. XIAO15.3 mA

    Test the LEDs

    Light white and red at low brightness.

  2. XIAO608 lux

    Test the LDR

    Print its reading in light and dark.

  3. XIAO

    Detect steps

    Print a line for each footfall.

  4. XIAO15.3 mA

    Flash on each step

    Light the strip briefly.

  5. XIAO

    Add the dusk rule

    Lights off in daylight.

  6. XIAO

    Sew the vest

    White front, red back, wires covered.

  7. XIAO

    Test outside

    Walk and run at dusk.

In short

How do you build a running safety vest with lights?

A running vest with LEDs that flash faster when you speed up and turn on automatically at dusk. You need Seeed XIAO RP2040, LIS3DH accelerometer, LDR Photoresistor, Resistor 10 kΩ, WS2812B strip 5 m (30 LEDs/m) and Li-Po battery 3.7 V 1000 mAh. It takes 7 steps and about 120 minutes.

Level
Beginner
Time
About 120 min
Parts
6

Parts list

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

Wiring

FromToWhy
LIS3DH VCC and GNDXIAO 3V3 and GNDPower
LIS3DH SDA and SCLXIAO D4 and D5I2C
LDR one legXIAO 3V3Top of the divider
LDR other leg and 10 kΩXIAO A0 (D0), 10 kΩ to GNDLight level
LED strip DINXIAO D1Data
LED strip 5V and GNDLiPo plus and GND (the strip runs on 3.7 V at reduced brightness)LED power
LiPoXIAO BAT padsPower and charging

Code

The LDR makes a voltage that falls in the dark, and the lights only run below the threshold you set, so they stay off in daylight and save the battery. The accelerometer detects each footfall as a sharp peak, and the LEDs flash with each step, so the faster you run the faster they flash. Standing still gives a slow blink so you stay visible at a crossing. The strip runs directly from the 3.7 V cell at 70 out of 255 brightness, which keeps the current to a few hundred milliamps; do not run it at full white. White at the front and red at the back follow the usual convention. These lights add visibility but do not replace a reflective vest and proper road sense: run facing traffic, on a footpath where you can, and carry a torch or a head lamp on unlit roads. Keep the LiPo in a sewn pocket, take it out before washing, never wear it while charging, and use a protected cell. Arduino IDE with the Raspberry Pi Pico/RP2040 boards package by Earle Philhower, board "Seeed XIAO RP2040".

Runs on a virtual Seeed XIAO RP2040 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).

// Running vest: lights on at dusk, flash with each step. Libraries: Adafruit LIS3DH, Adafruit NeoPixel. Board: XIAO RP2040.
#include <Wire.h>
#include <Adafruit_LIS3DH.h>
#include <Adafruit_NeoPixel.h>

Adafruit_LIS3DH lis;
Adafruit_NeoPixel strip(20, D1, NEO_GRB + NEO_KHZ800);       // 10 white at the front, 10 red at the back
const int LDR = A0;
const int DARK = 300;                           // reading below this means dusk (0 to 1023 scale of the 10-bit reading)
unsigned long lastStep = 0, flashUntil = 0, cadenceMs = 700;
float filt = 0, base = 9.8; bool above = false;

void setup() {
  Wire.begin();
  lis.begin(0x18);
  lis.setRange(LIS3DH_RANGE_4_G);
  analogReadResolution(10);
  strip.begin(); strip.setBrightness(70); strip.clear(); strip.show();
}

void show(bool on) {
  for (int i = 0; i < 20; i++) strip.setPixelColor(i, on ? (i < 10 ? strip.Color(255, 255, 255) : strip.Color(255, 0, 0)) : 0);
  strip.show();
}

void loop() {
  bool dark = analogRead(LDR) < DARK;
  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);
  filt += (mag - filt) * 0.3; base += (filt - base) * 0.01;
  float swing = filt - base;
  if (!above && swing > 3.0 && millis() - lastStep > 250) {     // a footfall
    above = true;
    cadenceMs = (cadenceMs * 3 + (millis() - lastStep)) / 4;     // smooth the step time
    lastStep = millis(); flashUntil = millis() + 120;
  }
  if (above && swing < 1.0) above = false;

  if (!dark) show(false);                                        // daylight: lights off
  else if (millis() - lastStep > 3000) show((millis() / 700) % 2);          // standing still: slow, steady blink so you stay visible
  else show(millis() < flashUntil);                              // running: a flash with every footfall
  delay(5);
}

Test checklist

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

CheckExpected
DaylightLights off
Cover the LDRLights come on
WalkA flash with each step
Stand still in the darkSlow blink

If it does not work

Flashes more than once per step

Raise the swing threshold or the minimum time.

Never turns on

Raise DARK or check the divider.

Strip dim

Check the cell voltage and the brightness setting.

Wrong colours

Change NEO_GRB to NEO_RGB.

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

Ask Lark AI

Common questions

What parts do I need for the running safety vest with lights?

Seeed XIAO RP2040, LIS3DH accelerometer, LDR Photoresistor, Resistor 10 kΩ, WS2812B strip 5 m (30 LEDs/m) and Li-Po battery 3.7 V 1000 mAh. WS2812B strip 5 m (30 LEDs/m): Cut 20 LEDs.

How long does the running safety vest with lights take to build?

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

How do I know the running safety vest with lights works?

Daylight: Lights off. Cover the LDR: Lights come on. Walk: A flash with each step.

Flashes more than once per step: what should I check?

Raise the swing threshold or the minimum time.

Never turns on: what should I check?

Raise DARK or check the divider.

Strip dim: what should I check?

Check the cell voltage and the brightness setting.

Wrong colours: what should I check?

Change NEO_GRB to NEO_RGB.