Menu & Search

Reading Data from HC-12 on Raspberry Pi and sending it to Domoticz

May 10, 2017

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 Discussion to this post

  1. pasifik says:

    Hi, Thanks for the nice article. can you make article for tutorial Domoticz.. thankss

  2. JK says:

    I connected to a Raspberry Zero but no ttyS0 can be found, only ttyAMA0.

  3. JK says:

    Ok ttyAMA0 worked fine also

  4. Doug says:

    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

Leave a Reply

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

Type your search keyword, and press enter to search