Introduction: Connect Your Arduino to UDP/IP Thru a RF433 Gateway

Previously I made an Instructable to explain how to connect Arduino microcontroller to IP network thru WIFI connection.

In many cases for Home automation, WIFI connection is luxurious. A simple RF433 (radio frequency) connection is enough to deal with data exchange if RF message are transform in UDP message.

RF is cheapest and radio range wider than WIFI. It is a good solution if the volume of data and the exchange constraints are low.

But RF transmission need to be structured in order to be efficient and easy to use. That's what I did some years ago. I recently made a few improvements and decided to publish.

This takes part of aHome Automation Infrastructure I explained in a another Instructable.

Supplies

For the RF Gateway

  • 1 x active Buzzer For instance
  • 1 x green LEd
  • 1 x red LED
  • 1 x 150 ohms resistor
  • 1 x 100 ohms resistor

For testing

  • an Arduino microcontroller whatever the kind
  • 1x RF 433Mhz emitter and receiver

Step 1: Let's Have a Look at the RF Basics

It is quite easy to set a simple RF transmission between 2 Arduinos, thanks to theVirtualWire Library. This Library use ASK (amplitude shift keying) modulation for RF transmission and add a CRC checksum for message integrity.

A lot of RF 433 communication examples are available on the WEB.

What are the limitations ?

  • frame size under 27 bytes length
  • no message receive acknowledgements
  • no addressing (every receivers will receive all messages)

Step 2: Let's Have a Look at the Gateway Principles

  • One gateway handle a definite list of RF stations
  • A gateway must automatically convert a RF message to a UDP/IP one and vis et versa
  • One station is identified by a 2 bytes address 0xab 0xcd where 0xab00 if the gateway address
  • On to of the VirtualWire CRC, a frame number is added to identify every message

To do so:

  • I defined a RF frame standard over VirtualWire
  • I designed a RF433 Gateway
  • I developed an Arduino framework

Step 3: Let's Start With the RF Frame Standard

The figure shows frame flow between applications and VirtualWire thru RF433Link

From application to VirtualWire, RF433Link adds addresses, eventually a Flag that requires specific action inside the Gateway (flashing LED and Buzz), the sequential frame number and the data lenght.

VirtuaWire adds the CRC code.

From VirtualWire to application, VirtualWire ignore the frame if the CRC code is not the right one.

Step 4: Let's Build the RF433 Gateway and the Station

The electronic is simple.

As usual it is important to start by testing on a breadboard.

For that we must do a gateway and a station prototypes.

Just follow those schematics.

You will need:

For the RF Gateway
1 x Arduino Uno

1 x Arduino Ethernet Shield or an Ethernet Arduino (I think it is no longer available)

1 x Breadboard

1x RF 433Mhz emitter

1x RF receiver

1x active Buzzer

1 x green LED

1 x red LED

1 x 150 ohms resistor

1 x 100 ohms resistor

Optional 2 antennas not necessary if you for the test as long as you keep gateway and station closed

For station

1x Arduino Uno (or else)

1x RF 433Mhz emitter

1x RF receiver

Optional 2 antennas not necessary for testing as long as you keep gateway and station closed

Step 5: Prepare the Test

Download here and install the RF433Link library
Download the joined (at bottom of this step) HomeAutomationCommands.h and add it to your search library

Download here the Gateway code

Download here the Station framework code

Download here the Packet Sender tool

Do the Gateway configuration

  • Start Arduino IDE
  • Set the mac address, and the IP address, mask of the RF433 Gateway, the LAN router, DNS and mask.
  • For the first upload uncomment #define initEeprom to force eeprom initialization
  • Open the serial monitor at 38400
  • Upload the RF433Gateway in the Gateway Uno and the frameworkArduinoConnertedRF in the Station Uno.
  • Wait for the eeprom updated message
  • comment #define initEeprom
  • uncomment #define debugOn
  • Re-upload the code
  • comment #define initEeprom and re-upload

Do the Station configuration

  • Start another Arduino IDE
  • Set the gatewayAddress as for the Gateway inside framwrokArdionConnectedRF.ino
  • Set MOSI PIN to ground with a jumper on the ICSP connector. It will force the eeprom initialization
  • Open the serial monitor at 38400
  • Upload the code in the Arduino
  • Wait for the eeprom updated message
  • Remove the jumper and reset the UNO
  • In this test the Gateway address is 0xfe00 (65024) and the Station address is 0xfe01 (65025)

Prepare PacketSender

  • Enable UDP servers /File/Settings/Enable UDP Servers add ports 8888,8889
  • create a test entry
    • entryname: test
    • HEX: 01 01 c0 3b 0e 3b 00 0c 01 01 01 01 00 11 01 01 00 15 00 00 00 00 00 ae
    • address: your gateway IP address
    • port: 8888

Step 6: The Test Case

The purpose of the test

  • demonstrate the bidirectional RF communication between a station and the gateway
  • demonstrate the gateway bi-directional RF to UDP/IP conversion

To do so we need

  • to look at the station serial monitor
  • to look at the gateway serial monitor
  • to look at PacketSender log

The station will

  • firstly send a status message with the gateway flag for setting the buzzer and red LED on
  • regularly request for time message
  • regularly send 4 kinds of message

Those messages will be forwarded over IP and you can see them on the PacketSender log

The gateway

  • green LED will flash until receiving a message from IP
  • red LED will remain flashing until the station send status message with a gateway flag set to 0x00
  • will forward the message over IP that you can see on the PacketSender log

The server side

This instructable doesn't include the HUB/Server side (I will soon describe the infrastructure with another instructable)

Nevertheless it is possible to test the HUB to station conversion with PacketSender

Just send the test entry you created in PacketSender. It will set the station time date to 00:00:00 01/01/2021. You can see this on the station serial monitor.

As soon as the gateway recieve a message from IP the green LED of the gateway will stop flashing.

The green LED monitor the UDP/IP communication and the red LED the RF side.

Microcontroller Contest

Participated in the
Microcontroller Contest