This project contains the code for using an ultrasonic distance sensor to determine the water level in a tank.
An Arduino Uno reads from the sensor, sends the data to a 4-digit display, and uses an ESP8266 to log the data to a remote ThingsBoard instance hosted on Google Cloud Platform.
The ESP8266 is programmed to handle all the web traffic, receiving wake signal from the Uno and data via serial.
- Arduino Uno R3
- WiFi ESP-01 (ESP8266) (with simple breakout board)
- Ultrasonic Sensor AJ-SR04M
- Display TM1637
- Bi-directional Logic Level Controller
To program the ESP8266 using the Arduino Uno (this can be programmed but the one channel in my LLC broke, so I couldn't automate the GPI0 High/Low).
- Make sure Uno Sketch is empty (select Uno board).
- Select ESP8266 board.
- Connect Rx to Rx, Tx to Tx.
- Put ESP in Flash Mode
- ESP GPI0 -> GND
- ESP RST -> GND then 3.3V (just a quick tap)
- ESP GPI0 -> 3.3V (or float) (GPI0 must not be GND for Upload).
- Upload sketch.
I had lots and lots of trouble with the ESP throwing all sorts of exceptions and stack traces, which I never fully nailed down. I believe it had to do with the breadboard connections and the iffy serial communication, also possibly power issues, although I would watch it work flawlessly for a few uploads and then just start crashing, and then fix itself and then crash again. I ended up moving stuff around on the breadboard, made sure the wires were fasted, erased the flash a number of times, and tried putting the original firmware on, and NodeCMU, all of which were unsuccessful. The last post on this page helped me get things back on track.
- erase flash ->
esptool.py --chip ESP8266 --baud 115200 --port /dev/ttyACM0 erase_flash
- nodecmu ->
esptool.py --chip ESP8266 --baud 115200 --port /dev/ttyACM0 write_flash -z --flash_mode dio --flash_freq 80m --flash_size 1MB 0x0 ~/Downloads/nodemcu-release-7-modules-2022-07-15-21-56-08-float.bin
(or --flash_mode qio/--flash_mode dout)
I tried using the WiFiAutoSelector.h which did seem to work, but it coincided with the time I started getting all the crashes and FatalExceptions, so I reverted back to a simple hardcoded cycle through known WiFis. Not pretty, but does the job. Will make updating/changing the WiFi settings a mission, but I don't foresee that happening anytime soon, so we should be good.