Turn signal and blind spot detection for Xiaomi M365
- Wemos D1 Mini (ESP8266, Arduino-compatible layout, wifi, 80/160Mhz, 4Mb flash)
-
Led strip composed of 14 leds (5V)
-
Sonar HC-SR04 or DYP-ME007V1 (5V)
- The Android application, used to control remotly the electric scooter
This allow the Wemos (the web server) to retreive the speed of the electric scooter.
Here is a screenshot with the interface with the blinking controls, the electric scooter battery and the speed in real time :
Arduino IDE with ESP8266 platform installed
If you use windows / OSx you will probably need drivers: Wemos Driver
- Adafruit_NeoPixel (for the leds)
- ESP8266WiFi (for the Wifi)
- QuickMedianLib (for the median filter)
- ESP8266FS (SPIFFS, see: Using ESP8266 SPIFFS tutorial )
Links usefuls for the androidapp:
- Communicate with xiaomi for get parameters : https://github.com/maisi/M365-Power
- webview bridge library to communicate between android (java) and webview (js): https://github.com/lzyzsd/JsBridge
The Wemos is connected to the phone wifi hotspot, and so the can connect it via the android application from a webview. The android application is a bridge from the bluetooth to the web interface.
Firstly, the Arduino card connect on a WiFi network. Modify the SSID and Password at the top of the code.
Secondly, use the diagram bellow the connect the sonar (enabling blind spot detection) and the led strip (enabling turn signal and warning signal)
You can found the original file in ressources/Connection.fzz
While using the sonar HC-SR04 or DYP-ME007V1 we had problems with the echo signal. The original signal had random peaks (green signal on the picture bellow), like noise. We do not want this peaks as it is generating a bad blind spot detection randomly, even when we put a condition at 120CM or less to engage the blind spot signal.
To solve this problem, we put 2 additionnal signals :
-The median of the 15 last values of the original signal (blue)
-The moving average of the 15 last values of the original signal (red)
As we can see on the picture above, an array of 15 values is not enought for making the signal flat and removing the noise we do not want. Let's try with 30 values :
While trying to simulate an obstacle, we saw that it was slow to detect the signal, almost 2/3 of the real signal (green) is lost because of the median filter if we use it.
We have been searching the perfect value and we have found that 20 is a good value :
Both the moving average and the median are removing most of the peaks that we do not want here. As the median is more "flat", we used this signal to solve the problem.