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
- 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
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
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.
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 :
- Tests on MPU6050 board (feature, setting, finding the "good" library) # 60%
- 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
- Tests on charge/discharge board ("key" input for instance) # 70%
- Tests on LED ribbon (library FASTLED, check if blink indepedently...) # 0%
Simple trial of USB FTDI transfer # 0%
To Do List and Debugging/troubleshooting :
- 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
- 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
- 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 :
- use built in graph monitor - abandonned as possibility are very poor and no tuning possible (what a pity by the way !)
- use Processing is a Arduino's built in - abandonned as my computer have no enough ressource to run it smootly
- 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)
- 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 !