Introduction: HiFive1 Arduino Intruder Detection With MQTT Alerts Using ESP32 or ESP8266
The HiFive1 is the first Arduino-compatible RISC-V based board built with FE310 CPU from SiFive. The board is about 20 times faster than Arduino UNO yet like the UNO board, it lacks any wireless connectivity.
Fortunately, there are several inexpensive modules on the market to mitigate this limitation.
In this tutorial I used a ESP32 or a ESP8266 in order to obtain wireless connectivity.
Despite how cheap the ESP-01 is, due to the need to program it with an Arduino sketch, the ESP-01 was a less practical solution. In order to program the ESP-01, it needs an external USB to ESP-01 adapter that I didn't have at the time of making this tutorial. (If you are interested in using a HiFive1 with the ESP-01 follow this link)
I also contemplated using an Arduino Shield but ended up sticking with the ESP8266/32 because of the relatively expensive price tag most shields have.
This project will focus on creating an Intruder Detection System which will operate by sending a notification to MQTT Broker every time the Ultrasonic sensor (SRF05) detects an object crossing its line of sight.
Materials needed for this project:
- HiFive1 board (Can be purchased here)
- ESP32 Dev Module or ESP8266 NodeMCU 1.0
- 10k resistor x 2
- 1k resistor
- Breadboard
- jumper cable x 6
- SRF05 Ultrasonic module
- Mobile device
Step 1: Setting Up the Environment
Install the Arduino IDE
1. Follow the instructions to install the HiFive1 board Arduino package and USB driver.
2. Install the ESP32 or ESP8266 board package by adding an appropriate URL to the "File->Preferences->Additional Boards Manager":
- ESP8266 - http://arduino.esp8266.com/stable/package_esp8266com_index.json
- ESP32 - https://dl.espressif.com/dl/package_esp32_index.json
Step 2: Wiring the ESP32
If you are using an ESP8266 skip to step 3.
Important: The SRF05 comes in 2 pinout versions that are mirrored versions of each other, make sure you have the same module as mine using the link below.
For more technical details on the SRF05 follow this link.
GND (HiFive1) - > GND (SRF05)
5v (HiFive1) - > VCC (SRF05)
DI/O 11 (HiFive1) - > Trigger Pin (SRF05)
DI/O 12 (HiFive1) - > Echo Pin (SRF05)
DI/O 5 (HiFive1) - > Tx (ESP32)
DI/O 6 (HiFive1) - > Rx (ESP32)
Note: Make sure that the IOREF jumper is set on 3.3v.
Step 3: Wiring the ESP8266
Important: The SRF05 comes in 2 pinout versions that are mirrored versions of each other, make sure you have the same module as mine using the link below.
For more technical details on the SRF05 follow this link
GND (HiFive1) - > GND (SRF05)
5v (HiFive1) - > VCC (SRF05)
DI/O 11 (HiFive1) - > Trigger Pin (SRF05)
DI/O 12 (HiFive1) - > Echo Pin (SRF05)
DI/O 5 (HiFive1) - > Tx (ESP8266)
DI/O 6 (HiFive1) - > Rx (ESP8266)
Note: Make sure that the IOREF jumper is set to 3.3v.
Step 4: Programming
HiFive1 Code:
Before programming set the "Tools->Board" to HiFive1 board, the "Tools->CPU Clock Frequency" to "256MHz PLL", the "Tools->Programmer" to "SiFive OpenOCD" and the correct Serial Port is selected.
You will also need to download this Ultrasonic library, and this PubSubClient and extract them into your Arduino Libraries folder found in "User->Documents->Arduino->Libraries".
ESP32/8266 Code:
During the programming, the ESP board should have the hardware Rx and Tx pins disconnected.
After the code was successfully uploaded rewire the Rx and Tx pins on the ESP to ensure communication between the HiFive1 and the ESP.
For ESP32 - Set the "Tools->Board" to "ESP32 Dev Module", the "Tools->Programmer" to "AVRISP mkll" and the select the correct Serial Port.
For ESP8266 - Set the "Tools->Board" to "NodeMCU 1.0 (ESP-12E Module)", the "Tools->Programmer" to "AVRISP mkll" and the select the correct Serial Port.
The sketch code was borrowed from here with modifications to convert it into an intruder detection system.
Step 5: Setting Up the Client
Step 6: Final Result
Note: You should set your Serial Monitor’s baud rate to 115200 as that is the baud rate we use in our sketch.
Your final result should look similar to the final screenshots