Docs

Micro-controllers, wireless transmission and database

Head

Basic LORA data transmission

I have used two sets of Raspberry Pi Pico and Ebyte 433MHz UART LORA Module to transmit and receive data between long distance. This LORA module does not need library. We can simply use UART.write() and UART.Read() to transmit and receive. When receiving we need to decode the data from character to integer. Manufacturer sets Channel, Address and key to default value so no need to change these until we complete basic circuit and do a distance testing. It will work out of the box. Make sure to use both modules with same part number. E220-400T22D module is rated for 5km distance. Because I used low voltage of 3.3V VCC, I was able to get about 500m (half km) easily without line of sight using about 25mW power.

Some countries uses different frequencies and power limitation for LORA transmission. After finding out these you can get the matching module from https://www.ebyte.com. Inexpensive items can be purchased from https://www.aliexpress.com/store/5489003. I bought my items from https://www.aliexpress.com/item/1005002091320352.html and the antenna from https://www.aliexpress.com/item/1005001530239330.html. For in-house testing we do not need the antenna. If we do not use antennas, we need to switch the power off for few minutes every hour to cool the module. The reason is RF power will be returned back to module if no antenna found and it will produce heat.

Even though these modules can be used for transmit and receive simultaneously, I used one of them for transmission and the other one for receiving only for simplicity. You can do a modification for feedback transmission for acknowledgement. I used three switches for data source. You can use any sensors or any data for transmission. You can use the received data to save in a database or control something using MOSFET or relay.

Prerequisites

This project assumes you have already installed Thonny and done a simple blink program using Raspberry Pi Pico

Wiring Diagram

Transmitter Module

Transmitter TransmitterIMG
#Transmitter code starts here
import utime
from machine import UART
from machine import Pin

lora = UART(0,9600)
switch1 = Pin(20, Pin.IN, Pin.PULL_DOWN)
switch2 = Pin(19, Pin.IN, Pin.PULL_DOWN)
switch3 = Pin(18, Pin.IN, Pin.PULL_DOWN)
while True:
    if switch1.value() and switch2.value() and switch3.value():
        lora.write("SECRET111")
    elif switch1.value() and switch2.value():
        lora.write("SECRET110")
    elif switch1.value() and switch3.value():
        lora.write("SECRET101")
    elif switch2.value() and switch3.value():
        lora.write("SECRET011")
    elif switch1.value():
        lora.write("SECRET100")
    elif switch2.value():
        lora.write("SECRET010")
    elif switch3.value():
        lora.write("SECRET001")
    else:
        lora.write("SECRET000")
    utime.sleep(0.2)
#Transmitter code Ends here

Receiver Module

Receiver ReceiverIMG
#Receiver code starts here
import utime
from machine import UART
from machine import Pin

lora = UART(0,9600)

led_red = machine.Pin(20, machine.Pin.OUT)
led_green = machine.Pin(19, machine.Pin.OUT)
led_blue = machine.Pin(18, machine.Pin.OUT)
led_red.value(0)
led_green.value(0)
led_blue.value(0)

while True:
    dataRead = lora.readline()
    if dataRead is not None and "SECRET000" in dataRead:
        led_red.value(0)
        led_green.value(0)
        led_blue.value(0)
    elif dataRead is not None and "SECRET001" in dataRead:
        led_red.value(0)
        led_green.value(0)
        led_blue.value(1)
    elif dataRead is not None and "SECRET010" in dataRead:
        led_red.value(0)
        led_green.value(1)
        led_blue.value(0)
    elif dataRead is not None and "SECRET011" in dataRead:
        led_red.value(0)
        led_green.value(1)
        led_blue.value(1)
    elif dataRead is not None and "SECRET100" in dataRead:
        led_red.value(1)
        led_green.value(0)
        led_blue.value(0)
    elif dataRead is not None and "SECRET101" in dataRead:
        led_red.value(1)
        led_green.value(0)
        led_blue.value(1)
    elif dataRead is not None and "SECRET110" in dataRead:
        led_red.value(1)
        led_green.value(1)
        led_blue.value(0)
    elif dataRead is not None and "SECRET111" in dataRead:
        led_red.value(1)
        led_green.value(1)
        led_blue.value(1)
    utime.sleep(0.2)
#Receiver code Ends here