"I want to have sensors everywhere!" In this article we'll show you how to create a wireless sensor node using an inexpensive ESP32 module. An ESP32 is a tiny, low-cost WiFi-enabled microcontroller that supports direct connectivity to sensors via SPI, I2C, ADC, GPIO, etc. Programming of the module is made easier with support for the Arduino Integrated Development Environment (IDE). You can build up as many wireless sensor nodes as needed to create your wireless sensor network. Because of the wide range of supported interfaces on the ESP32, you can select from 1000’s of sensors (gas, door switch, noise, water level, soil moisture, etc).
In this project, we will show you how to create wireless sensor nodes that send their data to Machinechat’s JEDI One software that runs on MacOS, Windows, Ubuntu Linux and the Raspberry Pi. JEDI One enables you to collect data from all the sensors and display the data on a dashboard accessible from any browser on the network. You can also setup rules, actions and notifications.
Here is an example of a JEDI One data dashboard showing multiple sensors:
We will show you in just 5 steps, how to get a wireless sensor network started. For your convenience you can buy all the parts and software from Digi-Key Electronics using the links below:
- Buy parts from Digi-Key for the Windows 10 environment
- Buy parts from Digi-Key for the MacOS environment
- Buy parts from Digi-Key for the Ubuntu Linux environment
Step 1: Install JEDI One
Install JEDI One on your PC (Windows, Linux, Mac) or Raspberry Pi. Checkout the appropriate product installation guide here for details.
Step 2: Setting up the Arduino IDE
Download the Arduino IDE here for your MAC, PC or Linux computer. If you are new to Arduino, please review this tutorial. Once you have it installed and running, you will see this:
Now install the libraries needed to talk to the BME280 environmental sensor. Select Tools -> Manage Libraries. Type bme into the search box. Install the Adafruit BME280 Library. Also install the supporting libraries it recommends.
We also need the Arduino IDE to know how to talk to our ESP32 module. Select:
- Arduino -> Preferences -> Additional Boards Manager URLs:
- Enter: https://dl.espressif.com/dl/package_esp32_index.json
- Click: OK
That window looks like this:
Finally, setup the details about your ESP32 module under Tools. This is important; if not correct, undesired behavior may occur! For the board referenced above, the settings you want to select are:
Changing the flash mode to “DIO” is important. Also, your “Port” number will likely be different; just look for it by clicking on the “Port” arrow.
Now, close the Arduino IDE program.
Step 3: Connecting the BME280 Sensor to the ESP32
Connect the ESP32 to the recommended BME280 module as follows:
Step 4: Loading, configuring, and running the software
Plug the micro USB cable into your PC and attach the ESP32 to the other end. Important: The ESP32 module will get power from the USB cable. Open the Arduino IDE. Your screen should look like this:
Download the Arduino sketch found here (esp32_bme280.ino). Within the Arduino IDE click on FILE -> Open and then select the file you just downloaded. It will prompt to create a directory, agree to this.
Find the following lines of code in the sketch and change the "your SSID” and "your WiFi password" with the settings for your wireless router or access point in quotes.
// Wi-Fi settings - replace with your Wi-Fi SSID and password const char* ssid = "your SSID"; const char* password = "your WiFi password";
Also, edit the following line in the sketch with the IP address and port number for your system running JEDI One. The default HTTP listener for JEDI One is on port 8100. For this example we use 192.168.1.7:8100:
// IP address of PC or Raspberry Pi running Machinechat JEDI One software // If you changed the JEDI port number, replace 8100 with the new port const char* host = "192.168.1.7:8100";
Save the sketch:
It is finally time to compile and download the sketch into the ESP32 (Note: you may need to press the “boot” button on the ESP32 to initiate the download):
Success! Now that the code is in the ESP32, the Arduino IDE can be closed and the unit moved to another location. A USB charger can be used to power the ESP32; no need for the computer at this point.
The serial window in the video above shows that the information from the sensor is being successfully sent to JEDI One.
You can setup several of these ESP32 sensor nodes to create a network and put them in various places to monitor many locations. Just make sure you change the target id to a unique name for each ESP32. Here is what you will want to change:
// Create a unique ID for the data from each ESP32 running this code const char* jediID = "ESP32Sensor51";
You can call them whatever you like (ESP32Sensor51 in this example), the name just needs to be unique for each ESP32. Then when you go to setup the dashboards and notifications in JEDI One, you will be able to tell which ESP32's data you are working with.
We are now done setting up the ESP32 module. The hard part is over and now we will take a moment to setup a JEDI One data view dashboard.
Step 5: Create a data dashboard to monitor your data
Now let’s add a dashboard. JEDI One dashboards allow you to view your data in two ways:
- as a real-time / historical data view dashboard; and/or
- as a system view dashboard, which allows you to view real-time data in the context of the environment your sensors and devices are operating in
In this example, we will create a data view dashboard and add the temperature, humidity and pressure values from the ESP32/BME280 sensor node.
Notice how the target ID, ESP32Sensor51 automatically showed up along with its the properties, tempF, humi, and pressure. These are being collected by the default HTTP listener, which is up and running when you install JEDI One. Our Arduino program is sending the data via HTTP POST.
Congratulations! You’ve just learned how to set up and configure a wireless sensor in an ESP32 environment. Now go ahead and create more ESP32 nodes and add more sensors (just repeat steps 3 and 4, and remember to give each of your ESP32 a unique target id name)…and in no time, you can be the sensor master of your universe (wherever it may be).
Check out the following links to learn how you can easily configure JEDI One to view, store and monitor your data in different ways:
- Creating and using data dashboards
- Creating rules and notifications
- Sending data using the HTTP Post method