Self-adjusting Light for Electric Unicycle (EUC)

by michalpietraszek in Circuits > Gadgets

1507 Views, 8 Favorites, 0 Comments

Self-adjusting Light for Electric Unicycle (EUC)

Self-adjusting light for EUC
IMG_20230304_094809.jpg
diagram.png
MODEL_COMPLETE.PNG

Electric Unicycles (just like other self-balancing vehicles) all have similar problem when riding at night: lights that were adjusted for riding on horizontal surface will not work properly when going up or down the hill. This is because self-balancing vehicle always maintains the same angle to earth's gravity vector, not to the road itself.

Project described below addresses this problem. Self-adjusting light mount actively scans the terrain in front of you and maintains more or less constant angle between light and the terrainn/road.

The device can be powered from the unicycle through USB or bicycle light itself if it's able to work as powerbank.

Note that the angle adjustment logic based on simple distance measurement is simplified and results may vary from theoretical adjustment needed. But it seems to be good enough for me and is definitely better than fixed light :)

Supplies

IMG_20230301_201802.jpg
servo.jpg
IMG_20230224_194720.jpg
screws.jpg

Parts:

  1. 3.3V Arduino Pro Mini board (or any other compatible board with similar dimensions and pinout)
  2. module with VL53L1X ToF distance sensor (with lid!).
  3. 7mm tact switch (6x6x7 mm). Consider using waterproof version of the switch.
  4. 1x Micro Servo (I'm currently using MG90s)
  5. USB cable
  6. Wires and some heat shrink tubes
  7. Resistor (THT , 20k-22k ohm)
  8. Capacitor (THT, 47uF)
  9. Screws for plastic with round head (I'm using 6 3x12 and 2 2,5x6mm TX screws here)
  10. 2 bearings: 688Z, 8x16x5 mm
  11. Bicycle lamp (I'm using KINGSEVEN L3-1000 1000 lm). Note that other models may not fit into this project.


Tools:

  1. 3D printer
  2. Soldering iron
  3. Arduino IDE installed on your computer
  4. USB-UART converter


Important:

There are 3.3V and 5V versions of Arduino Pro Mini boards. Make sure you choose 3.3V version.

There are various modules with Vl53L0X or Vl53L1X sensors available. Make sure that you order the right one:

  • choose VL53L1X, not Vl53L0X
  • choose the smallest module available - see picture above. Other modules may not fit into printed parts!
  • choose version with lid - see picture above.

Assemble Bed and Side Gears

MID_PART_COMPLETE.PNG
gear2.jpg
IMG_20230304_074743.jpg
IMG_20230304_074732.jpg
  1. Print GEAR2.stl part (2x).
  2. Print BED.stl part (1x) - print support might be needed here. This is the most difficult part to print.
  3. Push bearings into GEAR2 parts
  4. Assemble all 3 parts - there are multiple angle configurations possible. This can be changed later.

Add Sensor and Wires

IMG_20230304_081610.jpg
IMG_20230304_081047.jpg
IMG_20230305_084311.jpg
SENSOR_LID.PNG
IMG_20230304_094410.jpg
  1. Print SENSOR_LID.stl part
  2. Connect 4 wires to the sensor (see "Wiring" section below)
  3. Assemble parts as shown on the picture above.

Note that SENSOR_LID part can be sealed using rubber gasket or silicone to improve water resistance.

Downloads

Asemble Main Unit and Servo

MAIN1.PNG
IMG_20230301_201831.jpg
IMG_20230302_081931.jpg
IMG_20230302_084004.jpg
servo_mount.jpg
  1. Print MAIN.stl part.
  2. Attach USB cable
  3. Connect capacitor
  4. Attach servo. Depending on how the servo wires are connected (side or bottom), this might need to be done in 3 steps - see picture above.

Downloads

Load Program

  1. Load program using Arduino IDE and USB-UART converter

Please treat this progam as an example only. It definitely can be optimized and improved. Feel free to do it and share the results!

I'm using this external library to read sensor data. Probably other libraries can be used as well here as need only basic functionality of Vl53L1X: reading distance.


version 2 notes:

  • added PULSE_WIDTH_ADJUSTMENT_WEIGHT parameter (default 0.1). This will smooth the movement and add some stability
  • added ranging_data.range_status check. This should help to filter out potentially wrong readings.
  • increased the delay in main loop

version 3 notes:

  • improved behavior in case of sensor failure/missing readings

version 4 notes:

  • added 3 callibration positions (center, upper, lower) instead of 1 (center)

Wiring

SCHEMA.PNG

General steps:

  1. pin 2 connected to GND using 22k resistor (pulled down)
  2. tact switch to pin 2 and VCC
  3. sensor data lines:
  4. SCL to pin A5
  5. SDA to pin A4
  6. sensor VIN to Arduino VCC (3.3V!) and GND to GND
  7. servo signal line pin 9
  8. input USB power line (+) to Arduino RAW pin
  9. power servo from raw input voltage (5V)
  10. add a capacitor between servo's power lines (not needed but may help)

Attach Lid and Gear

MAIN.PNG
lid.jpg
IMG_20230302_084143.jpg
gear1.jpg
IMG_20230302_084253.jpg
  1. Print GEAR1.stl part (1x). I'm using 0.1 mm layer for higher precision here
  2. Print LID.stl part
  3. Print SWITCH_SPACER.stl part. You can glue it to tact switch

There are 4 versions of GEAR1 in case one does not fit because of your print settings or servo shaft diameter tolerances (it can be +/- 0.1 mm or more dependigng on servo model).

Remaining Parts

MAIN_WITH_ARM.PNG
IMG_20230304_094907.jpg
  1. Print ARM.stl part

Power up the device for couple of seconds before assembling final parts - the servo will move to middle position.

Downloads

Attach to Unicycle

KS16X_mount.jpg
KS14X_ADAPTER.PNG
ADAPTER_DIM.PNG

There are additional parts needed to attach the light to your electric wheel.

I have prepared an adapter for Kingsong 16X - it can be attached in non-damaging way using velcro.

Feel free to build your own adapter for your own unicycle model keeping in mind the dimensions above.

Downloads

How to Use

Basic modes:

  1. Tracking disabled: default mode, servo stays in middle position, internal LED blinks every 2s
  2. Tracking enabled. internal LED blinks 2 times per second

You can toggle between these modes by pressing button (shorter than 1s)

When servo is close to min/max position the led will be permanently on (not blinking).

If sensor cannot be initialised (sensor or connectivity failure), the LED will blink fast and program will not continue.

Callibration process:

  1. Press button longer than 5s and release. LED starts blinking fast
  2. Turn off your wheel and adjust the angle (wheel with light attached)
  3. Press the button for 1s. LED stops blinking. Device will measure the distance and save it in EEPROM memory. This will be your target distance next time you enable tracker.
  4. (software version 3 and later) Repeat step 3 for upper and lower callibration position
  5. (software version 3 and later) Device will quicky move to upper, lower and center position indicationg callibration process is done.

While callibrating make sure there is 2-3 m of free, flat space in front of you.