Hardware.
Okay, to read data from HC-12 to the Raspberry PI is practically very easy :). All you need to do is hook it up and power from RPi.
- VIN – Connect to RPi 5V (PIN 4)
- GND – Connect to RPi GND (PIN 6)
- RX – Connect to RPi GPIO14 (PIN 8, UART0_TXD)
- TX – Connect to RPi GPIO15 (PIN 10, UART0_RXD)
I “stole” that image from Internet, so you can see which pins exactly are those that we need:
Software.
Simple Python script can be downloaded here. It’s not that “pretty”, but I just learned python, lol :). The idea of the script is to read the HC-12 sensor’s values on the serial port as text lines, split them, and depending on some basic configuration, send the value to the dummy device in Domoticz, by it’s idx. You need to add the dummy devices before that, in our case – One dummy device type temperature, it has idx 26 in our sample, and another one type lux, it has idx 27 in the example.
You will need to make the script run at start, if you need persistency. For my test purposes I will not explain that right now. Btw, make sure you have python3, pip3, and wiringPi libraries installed, and also make sure the serial port at /dev/ttyS0 is activated and accessible ( you can configure it in raspi-config -> Interfacing Options -> Serial ).
After this, you can see the values being read to Domoticz.
and
That’s it, very very simple 🙂
4 comments On Reading Data from HC-12 on Raspberry Pi and sending it to Domoticz
Hi, Thanks for the nice article. can you make article for tutorial Domoticz.. thankss
I connected to a Raspberry Zero but no ttyS0 can be found, only ttyAMA0.
Ok ttyAMA0 worked fine also
stated here: https://www.allaboutcircuits.com/projects/understanding-and-implementing-the-hc-12-wireless-transceiver-module/
Connect HC-12 “Gnd” and “Vcc” to a 3.2 V to 5.5V 200mA source. Per the datasheet, if powering the HC-12 with more than 4.5V, place a 1N4007 diode in series with the HC-12 “Vcc” pin