Categories
TUTORIALS

Using 2 Heltec WiFi-LoRa 32 V2 boards to transmit and respond to sensed data

Overview:

In this tutorial we will explore the benefits of LoRa and program one LoRa enabled dev-board to receive inputs and transmit those inputs to another LoRa enabled board which will coordinate a response. Specifically, we will build two circuits: one that senses when one of two push switches has been pressed and transmits a LoRa packet, and the second that receives the LoRa packet and turns a LED on or off based on the sent data. This tutorial could be applied to projects such as Smart-Home controllers such as garage door openers or light switches or home garden monitoring devices.

The major steps are:

  1. Solder pin headers
  2. Prepare your Arduino IDE to communicate with the Heltec WiFi LoRa 32 V2 dev-boards
  3. Wire the circuits
  4. Write code to control the transmitter and receiver boards

Why LoRa?

In short, LoRa (Long Range) is a type of wireless data communication that is used for projects that have long distance and lower power usage requirements. LoRa is great for projects that run on solar power or small batteries and need to be placed in areas that do not have WiFi connectivity. Further, LoRa can be used in a point to point (just two devices) or network (three or more devices). However, LoRa is not suitable for situations where data is communicated frequently and in large quantities.

For more information about LoRa please visit these resources:

  1. What is LoRa?
  2. Arduino and LoRa tutorial

This tutorial explains radio frequency allocation in the US and guides the user through calculating data loss

Parts needed:

  • 2 Heltec WiFi LoRa 32 V2 Boards
    • When purchasing LoRa devices, check that they support transmission at the proper frequency band for your region. For instance, these boards can transmit at 915MHz
    • These boards come with a built-in OLED display and WiFi capabilities. These extra features are not necessary and there are less expensive boards that come without these features.
    • The boards can also be purchased here
  • (1) large breadboard (or two small breadboards)
  • (2) push switches
  • (1) LED
  • (1) 220Ω resistor
  • (7) M-M jumper wires

Step-by-Step:

Step 1: Solder the pin headers onto the Heltec WiFi LoRa 32 V2 dev-boards

The Heltec WiFi LoRa 32 V2 dev-boards do not come assembled and need to be soldered. When soldering, be careful not to burn the ribbon cable that connects the board to the OLED. Here is a helpful tutorial on how to solder header pins on printed circuit boards. Additionally, Adafruit has an awesome help-guide that covers soldering tools and techniques.

Step 2: Prepare your Arduino IDE to communicate with the Heltec WiFi LoRa 32 V2 dev-boards

Follow the Heltec official ESP32+LoRa Series Quick start guide. Ensure that you:

  1. Add the latest Heltec ESP32 board manager to the board manager URLs
  2. Install the Heltec ESP32 boards in the board manager
  3. Download the Heltec ESP32 library

Before you start wiring, test that your boards are working:

  1. Ensure that you have switched to the LoRa board by going to Tools > Board Manager > Heltec ESP32 Arduino > WiFi LoRa 32 (V2)
  2. Ensure that you are using the correct COM port for your LoRa board (for instance, on my machine, COM3 was reserved for my Arduino Uno and COM4 and COM5 were used for the LoRa boards)
  3. Load the transmitter example LoRa+OLED sketch from Heltec onto one of the boards: File > Examples > Heltec ESP32 Dev-Boards (under Examples from Custom Libraries) > LoRa > OLED_LoRa_Sender
    1. **Important note**: as noted above, ensure that you band value on line 23 to make sure you are transmitting on an appropriate frequency for your region
  4. Load the receiver  example LoRa+OLED sketch from Heltec onto one of the boards: File > Examples > Heltec ESP32 Dev-Boards (under Examples from Custom Libraries) > LoRa > OLED_LoRa_Reciever
    1. **Important note**: as noted above, ensure that you band value on line 12 to make sure you are transmitting on an appropriate frequency for your region

When you power up the boards with these sketches, the Heltec logo should flash for 1.5 seconds, then it should its LoRa functionality has been initialized with: “Heltec.LoRa Initial success!”. Finally, on the receiver board you should start to see “hello “ with an incrementing digit for the number of packets that have been received.

Step 3: Wire the circuits

To a novice, the pinout diagram for the Heltec WiFi LoRa 32 V2 dev-board can be overwhelming. I have included a copy of the pinout diagram from the Heltec WiFi-Kit series Github page.

When identifying pins to use for your projects, first pay attention to the red arrows. These arrows indicate which pins are reserved for the OLED and LoRa capabilities of the board and should not be adjusted. GPIO (General Purpose Input/Output) pins such as 2, 12, 13, 17, 22, 23, and 34-39 are open pins.

Heltec WiFi LoRa 32 (V2) Pinout Diagram

Now that the pins have been selected, it is time to wire the transmitter and receiver circuits.

Transmitter circuit:

The transmitter circuit contains two push switches, button A and button B. These buttons are connected to digital pins 2 and 17, respectively, and grounded to one of the LoRa boards 2 ground pins. When a button is pressed, the digital signal at its corresponding pin will read LOW, whereas the default reading is HIGH. In the code, we can look for this change in signal and complete some actions based on the event occurring.

Receiver circuit:

The receiver circuit is a little simpler. It is just a standard LED connected to pin 17 on the receiver LoRa board with a 220Ω resistor. The code for the receiver circuit will control the LED by setting pin 17 to high  for LED on, or low for LED off.

Control an LED Remotely via 2 Heltec LoRa boards: Transmitter Circuit Diagram

Step 4: Write code to control the transmitter and receiver boards

The code for this project is held in this Github repository. Additionally, I have included both sketches below. Everything is explained in the comments throughout.

Congratulations! You’ve sensed, transmitted, received, and responded to stimuli using LoRa!

One reply on “Using 2 Heltec WiFi-LoRa 32 V2 boards to transmit and respond to sensed data”

Leave a Reply

Your email address will not be published. Required fields are marked *