BIKE & ARDUINO - Break and Turn Lights With MPU6050 Accelerometer

Introduction: BIKE & ARDUINO - Break and Turn Lights With MPU6050 Accelerometer

IMPORTANT NOTE : This project is still in developpement

I plan to update the Instructable step by step.

Latest revision : 23/02/2021


Comments, support and suggestion are very welcome during the process !

Since I am using daily my bike to go to work, I am concerned by safety.

For a long time now, I was thinking of adding turn lights and front/rear lights.
The easy way to do so is to add led lights with battery and push buttons.

But... I tried the hard way, for more fun :)
(and of course, knowledge/skills improvement !) so I decided to use MPU 6050 accelerometer to automate some actions (but I have also thought of B-plan in case of failure, to not throw away all the work).

Here is my wish list :

- system have to be robust and water tight (under rain for winter conditions)

- battery have to be small and quite light, with autonomy of at least one week (2x 30' bike par day - ie. 6h)

- LED lights will change blinking and color according situation

Supplies

- Arduino Pro Mini (5V - 16 MHz)

- MPU 6050 on board - ref # GY 521

- 5V WS2812B Smart LED pixel strip

- two 18650 battery (about 2250 mAh each)

- Charge/discharge/voltage regulator module - ref # CC06CVSA

- various electric "classical" little stuff (resistor, capacitor...)

Step 1: History & Inspiration, Overview, to Do List

Inspiration :

Ideas come from a very large inspiration sources, from Youtube videos to Instructable, forums... etc.

However, the following links are tribute (sort of !) of my motivation :

- Bike clothes LILLYPAD from leahbuechley

- A lost video of students who make a similar project (link to be done)

- ... to be continued

Overview :

The preliminary Fritzing picture shows my ideas.

In front side, deux blocks of 3 leds are used to make blinking white front lights and can be used as turn lights with buttons.

In rear side, same principle in red light, plus break function in fix red light.

Consumption :

I plan to have a 12 LED in total : 12 x 60 mA if white light (max case, considering blinking and red color at the rear side) = 720 mA

Arduino : about 20 mA

GY 521 board : about 4 mA

TOTAL : about 750 mA -> 6 hours autonomy : 2 batteries 18650 2250 mAh in 1s2p are sufficient

In term of project's realization, I will first tests and progress independly on each main block, before regroup everything to make the project. These preliminary steps will be documented in the "under progress" Instructable, and probably set in appendix when finished.

All program developpement are done in Uno board, final project will be transfered on Pro Mini board.

Foreseen steps and progress :

  1. Tests on MPU6050 board (feature, setting, finding the "good" library) # 60%
  2. Tests on statistic to define "variation" of acceleration to activate the break light # unefficient - aborted
    Now thinking to try a ML scheme to capture the braking pattern
  3. Tests on charge/discharge board ("key" input for instance) # 70%
  4. Tests on LED ribbon (library FASTLED, check if blink indepedently...) # 0%
  5. Simple trial of USB FTDI transfer # 0%

To Do List and Debugging/troubleshooting :

  1. MPU6050 : mine is a cheap version, with probably a wrong capacitor - intensive test on that to be done in order to increase reliability of measure
  2. MPU6050 : Seems the sometimes the board freeze - investiguate if due to bad connection or other issue - if needed, think about add a Error Management to avoid this
  3. STAT : Found a library which seems to do the job properly and a low memory cost - test of "real" case to be done
    Investiguation to be done to use ML.

Step 2: GY 521 / MPU 6050 Testing

Expected information from MPU 6050 in my case are :

- Acceleration vector is the bike frontward drection (X in my configuration)

- Angle of bike when turning (Roll in my case) to auto-stop the turn lights.

Completely newbie on this board, I read intensively information on internet about it.

Main "official" ressource use is Aduino Playground.

I ended to choose Jeff Rowberg library due to his popularity and DMP integration (GitHub link).

Quaternion were my first option due to efficiency, no risk of Gemba lock but I abandon them due to my incapacity to convert them to something usable for me.

I done some code modification to understand functions - as I was not satisfied of information visualisation in console mode, I think about graphical viewing.

Successive options were :

  1. use built in graph monitor - abandonned as possibility are very poor and no tuning possible (what a pity by the way !)
  2. use Processing is a Arduino's built in - abandonned as my computer have no enough ressource to run it smootly
  3. use external library : I tried Plotter (Devin Conley) which works well, but have an incompability with use of Rowberg's library. I do not find why despites investiguation, and finally tried another thing (but I keep the library, well documented and working well otherwise for other project)
  4. use external viewer : I now use SerialPlot, which allowed me the check dynamically and graphically the reactions under GY 521 move. I plan later on to use it as a mobile system to test and set parameters on the bike (computer + developpement board + battery on the bike)

I am quite satisfied at this state, as it was not obvious at all to understand the MPU 6050 system. In can see that noise is still quite strong on signals, I hope to be able to filter it efficiently.

To be noted that (apparently) INTERRUPTION input is no longuer used in Rowberg's lib (see that forum)

Risks on this module are :

- sometimes, the system freeze - Error management may be to be think about (but how ???)

- I probably will need to investiguate on bad capacitor issue (read that)

Step 3: Statistics...

It is one of my key point to let the project works : how to trigger the break light when necessary (ie "real" breaking or slow down) ?

My first thought was to make two moving average : one long term for Ax value reference, one short term of last Ax values, and compare them - if the short term one is off the track, we consider that as a proof of breaking.

Problem : that need a huge memory compared to what the Uno can manage and due to big signal variation, it is likely that that solution do not perform well.

I therefore think to use 6 sygma rule (see internet) and control is short terme mean is out of long term mean minus 3 sygmas.

For that, I found out the Statistic lib from Rob Tillaar (GitHub link), which have the big power to be very economic is term of memory and calculation time.

I tried a lot of "basic" statistics treatent without success.

Mache learning seems to be a (hard but) good way to solve that. Data acquisition will be necessary.

Step 4: Charge/discharge Module

I previously had issue on low charging amps on my module...

...

...

but after several another brands/types of module tests with the same issue, I finally managed to found out the issue : cable section was too low... sigh...

Good point is know I have a lot of various charging module !

Be the First to Share

    Recommendations

    • Water Speed Challenge

      Water Speed Challenge
    • Pets Challenge

      Pets Challenge
    • Stone, Concrete, Cement Challenge

      Stone, Concrete, Cement Challenge

    5 Comments

    0
    skioppetto
    skioppetto

    8 months ago

    hi beeplus! I'm trying to do a similar work... I'd like to use AI to check brake and turn events, I've read some researches about it on scholar.google.com and is a running issue expecially on automotive and security contexts. I've implemented a logic to aggregate raw data on time periods and now I'm implementing a first arduino project to install on my bike just to collect data for training on SD card, I could publish a post like your and if you are still interested we could exchange experiences to get the work done. Good luck!

    0
    beeplus
    beeplus

    Reply 4 months ago

    Dear Skiopetto,
    It make ages since I take times to come back to your comment.
    I tried unsuccessfully to use moving average, and I also now aiming to work with ML system to better detect braking.
    I have also done some research and I would be pleased to share what I gathered with you. Do not hesitate to give me (us) some news on your project and to contact me for sharing.

    0
    alert251c
    alert251c

    1 year ago

    First of all: As I understand, you're looking for 2A li ion charging module. You can actually connect tp4056 supplies in parallel and charging outputs in parallel as well. I did it like that in one of my my projects and it worked well (2A charging current).
    Chinese did it in fact as well. You can buy modules with 2 tp4056 for 2 Amp.
    See this video for reference, if you're interested
    You can buy another maybe even better 2A charging modules like tp5000...

    And for braking detection I agree with your method of checking, if :
    "one long term for Ax value reference, one short term of last Ax values, and compare them - if the short term one is off the track, we consider that as a proof of breaking."
    I don't know "6 sigma" but guess it's more like the same...

    Good luck ;-)

    Adnotacja 2020-05-31 125820.png
    0
    Elaina M
    Elaina M

    1 year ago

    Thanks for sharing your work in progress ! Good luck with the rest of the build :)

    0
    beeplus
    beeplus

    Reply 1 year ago

    Thanks Elaina ! It is great to see your comment !
    I am working hard on blocking points and I hope that will be a success ! We'll see :)