Skip to content

Long Range Wireless Actuator Relay with HC12 433MHz

ChuckNorrison edited this page Oct 21, 2024 · 1 revision

Long Range Wireless Actuator Relay with HC12 433MHz (but not LoRa) Leave a reply

Long Wireless Transmission

In this post I address the scenario where the RaspberryPI with the central control SW is located in one place and the relays that control the valves or pumps are located in quite distant locations, I will show how to use a low frequency transmitters to control the Relays.

The HC-12 is a low budget (less than 7USD) transceiver which works at 433 MHz. This frequency is particularly suitable for the long distance transmission and it is free to use in many countries, although the regulation about Max transmitting power may vary from country to country.According to the datasheet the HC-12 can reach up to 1.2Km range, so it should be suitable for small farms. Of course as in all wireless transmission this distance is highly variable due to several conditions but normally in open field we should be close to quite good conditions to get a decent range.

In this blog I’m going to detail my implementation to transmit the commands from my Raspberry to the relays using the HC-12.

HC-12 module

The HC-12 module its a very interesting object for the price they sell it. 433MHz, more than 100 channels, possibility to set the TX power and TX mode, and ability to transmit and receive.

System Overview

The system is made as follow:

MAIN SITE:

The HC-12 is connected to the raspberry and it acts as the main transmitter, it will send the signal to the node site where the HC-12 connected to the relays.

NODE SITE:

The HC-12 in the node site requires an Arduino (nano/mini) which will act as interface between relays and the HC-12. The HC-12 in this location will receive the data from the main site and send the acknowledge.

It is possible to connect several HC-12 node site to the main HC-12. Due to the fact that the transmission is optimized for long distances, it works at low bit rate, for this reason there will be some seconds delay between the command sent and the acknowledge received. For the same reason, the relays cannot be switched all at the same time but they have to have some seconds in between.

The data transmitted is ciphered, and contain a timestamp to uniquely identify the packet.

Main site, HC-12 and Raspberry

NOTE: power supply is extremely important, during one of my testing I used a Huawei fast Charger, the Raspberry was working without problems but the HC-12 did not work. Only after hours of testing I realized it was the battery charger. As seen, the HC-12 is quite sensitive to poor battery chargers.

This is the HC-12 is in charge of sending the radio signal from the raspberry.

Wiring the HC-12 to the Raspberry:

For the physical connection of the HC-12 with the Raspberry, only 3 wires and power are needed as described below:

  • HC-12 TX -> RPi GPIO 15
  • HX-12 RX -> RPi GPIO 14
  • HC-12 Set -> RPi GPIO 04
  • HC-12 VCC -> +5v
  • HC-12 GND -> GND

In case you are interested in purchasing the SuperHat from my shop, the board already have the required space to conveniently solder the Module:

image image

It is assumed that the Hydrosys4 SW is already loaded and working on the RaspberryPI. (https://hydrosysblog.wordpress.com/configuration/)

Once the HC-12 is properly connected to the Raspberry, the Hydrosys4 requires to be reboot.

Starting from Hydrosys4 release 3.32 the HC12 will be fully integrated in the Setting Menu.

After wiring all the required connection and enabling the Serial (See chapter below). It is also necessary to check if any of the following pins: 4,14,15 are used in the Hardwaresetting table. If this is the case, the setting including these PINs have to be deleted, otherwise the following menus will not appear. After deleting the config with the PIN 4, 14, 15 reboot the Raspberry.

In the “setting” page there is a button named “HC-12 wireless setting”. Clicking on the button will show this interface:

NOTE: this interface will appear only if the HC-12 is properly connected to the raspberry.

image

All the parameters in this page should be the same for All the HC-12 on the Main site and node sites.

After the wiring and the wireless setting is done, then it is time to insert the Wireless Relay setting in the Hydrosys4 hardware table so that the Relay can be visible in the various menus.

To do so, it is required to give an address for the Relay (less than 10 characters) which will act as identifier for the Relay on the wireless side. This will be in the Title field. It is also required to identify the PIN on the Arduino which will trigger the relay. For example insert the PIN = 5 for the Arduino D5 pin. In the current setup the pins from D2 to D4 are used for the HC12 connection.

Let’s assume the identifier is “Relay1” and the PIN is D5. We need to go to the “hardwaresetting” menu, click on edit table, and add the following line:

image

Note: The pulse send using the HC12 (pulse/HC12) cannot be shorter than 10 seconds.

Enable UART interface on Raspberry:

In case you have installed the Hydrosys4 using the installation procedure rather then the .img file. Then the UART should be enabled as follow:

  1. Start raspi-config: sudo raspi-config.
  2. Select option 3 – Interface Options.
  3. Select option P6 – Serial Port.
  4. At the prompt Would you like a login shell to be accessible over serial? answer ‘No’
  5. At the prompt Would you like the serial port hardware to be enabled? answer ‘Yes’
  6. Exit raspi-config and reboot the Pi for changes to take effect.

HC-12 Node Side

On the node side, we require one HC-12 and an Arduino that acts as interface plus the relay board.

For the Arduino you can download the sketch here: https://github.com/Hydrosys4/Arduino-HC12-DigiHygro

The sketch name is HC-12actuator_x.x(xxx).zip

Before loading the sketch on the Arduino, it is necessary to open it with a standard text editor and adjust some of settings (unless you want to use the default).

In the sketch (main.cpp) there are some points where some changes can be done.

The above part indicates the PIN of the Arduino to be connected to the HC-12. I suggest to leave them unchanged.

  • HC-12 RX -> Ardunio 11
  • HC-12 TX -> Ardunio 10
  • HC-12 Set -> Ardunio 6

NOTE: The Code uses a random seed generator in Arduino which requires the PIN A0 to be left afloat.

Then the second section includes several settings:

CipherKey: is the ciphering Key, should match the key set in the Hydrosys4

AT_TX_Mode: suggest to use FU4 which is optimized for long distance communication.

AT_TX_power: The TX transmission power, according to the datasheet the value from 1 to 8 provide the following power.

image

AT_Channel: is the transmission channel, the values are from 001 to 100. Should match the same set in the Hydrosys4

All the above AT parameters and Cipher Key have to be the same in all nodes and main HC-12.

Once the main.cpp is modified with all the parameters, it is time to load it into the Arduino.

For instructions how to upload the SW, there are various SW which can do it. I use platformIO , anyway you can easily find tutorial on internet.

Testing

Back to the Hydrosys4 interface, it is possible to test the relays going to the setting page:

image

NOTE: the time duration should be set for at least 10 seconds.