Build a LoRaWAN Weather Sensor for the Things Network
by taste_the_code in Circuits > Sensors
47 Views, 0 Favorites, 0 Comments
Build a LoRaWAN Weather Sensor for the Things Network
In this Instructable, I'll show you how I built a wireless LoRaWAN sensor that sends temperature, humidity, and atmospheric pressure data to the cloud using The Things Network (TTN).
It spends most of its time in a deep sleep mode, only waking up to send a reading before going back to sleep.
This makes it perfect for remote, battery-powered monitoring projects.
Supplies
You will need a few key parts for this project. The brain is a NodeMCU (ESP8266) board, which is easy to program. For sensing, I used a BME680 sensor that measures temperature, humidity, pressure, and air quality. The most important part for long-range communication is the RYLR993 LoRa module. You'll also need a USB cable for power and programming, some jumper wires to connect everything, and a breadboard to hold it all together.
Parts Used in the Video
- ESP8266 (NodeMCU) - https://s.click.aliexpress.com/e/_c4O3aYmj
- BME680 Environmental Sensor - https://s.click.aliexpress.com/e/_c4MHm6uR
- REYAX RYLR993 LoRa Module - https://reyax.com/products/RYLR993_Lite
- Jumper Wires & Breadboard - https://s.click.aliexpress.com/e/_c3kAulBh
- Pocket PD Power Supply by Sentilab - https://hackaday.io/project/194295-pocketpd-usb-c-portable-bench-power-supply
Other tools and modules for projects:
- Heltec Lora 32 board - https://s.click.aliexpress.com/e/_c3viupVN
- T-Beam ESP32 LoRa Module - https://s.click.aliexpress.com/e/_c4O8dyET
- Solar Meshtastic Node - https://s.click.aliexpress.com/e/_c3suRwOb
- Soldering Station - https://s.click.aliexpress.com/e/_c3zRMuOT
- Multimeter - https://s.click.aliexpress.com/e/_c44i5gzv
- Bench Power Supply - https://s.click.aliexpress.com/e/_c41iTw0B
Wiring the Circuit
The wiring for this project is straightforward. First, connect the BME680 sensor to the NodeMCU using the I2C pins (D1 for SCL and D2 for SDA) for power and data. Next, connect the LoRa module. Link its RX pin to NodeMCU's D6, its TX pin to D7, and provide 3.3V power.
Finally, for deep sleep to work on the NodeMCU, you must connect a wire from the D0 pin directly to the RST (reset) pin. This wakes the board up after its sleep timer ends.
Setting Up the Things Network (TTN)
To receive the data, you need to set up an account on The Things Network. Once logged in, create a new application.
Inside that application, register a new device. You will need to copy the Device EUI, Application EUI, and App Key from TTN and paste them into your code later.
Finally, you will write a simple payload decoder function in your TTN application so it can translate the raw bytes from your sensor into readable numbers.
The full code is available here.
Understanding and Uploading the Code
The code, written in the Arduino IDE, does a few key things. When the device powers on, it checks if it's the first boot. If it is, it instructs the LoRa module to join the TTN network.
It then reads the BME680 sensor, packages the data into a small byte array, and sends it.
After it gets a confirmation, it puts the NodeMCU into deep sleep for a set period (like two minutes). When it wakes up, it repeats the process.
Remember to paste your TTN keys into the code before uploading it to your NodeMCU.
For a full walkthrough, checkout the video at the top of the article.
Testing and Power Analysis
Plug your device into your computer with a USB cable. Open the Serial Monitor in the Arduino IDE to watch the process. You should see it join the network and send data.
Then, check your TTN console to see the decoded data arrive.
To see the power usage, I connected my device to a variable power supply. The current jumps to about 40mA when sending data but drops to a very low level during sleep, showing how the device conserves energy.
Next Steps and Improvements
This project is a great starting point. You can easily modify it by changing the sensor or adjusting the sleep interval for your needs.
For even better battery life, consider using an ESP32 instead of the NodeMCU, as it has more efficient sleep modes.
If you need to send commands to your device at any time, you would need to modify it to act as a Class C device. I hope this guide inspires you to create your own long-range IoT sensor.
Check out my YouTube channel for more LoRaWAN and electronics related projects.