Connect any remote controller or simple button to Raspberry Pi GPIO

Hi.

I’ve found a few examples how to connect a remote controller to Raspberry Pi GPIO via relays. I admit this solution works fine but to me relay boards are too big and too expensive if you want to connect more that 3-4 buttons. So if you have a soldering iron and universal PCB there is a simpler solution to connect almost any remote or a button to your Raspberry Pi GPIO.

What will you need?

  • Rasberry Pi with Openhab2
  • Remote controller (I use 433MHz remote to control power plugs - DPM DT22)
  • Soldering iron
  • Universal PCB
  • Bipolar NPN transistors (f.e. BC546B, 2N2222)
  • Resistors (10kOhm)

To operate a remote we are going to simulate button clicking using NPN transistor and GPIO pin. The schema is very simple and it looks like this:

As you might notice I use +3.3V and GND directly from Raspberry Pi instead of original device battery which was CR2032. If you want to use original battery in remote you need to connect every emitter of your transistors to GND of Raspberry Pi.

Let’s solder!






First I used BC517 transistors which was not a good idea because they work in Darlington’s system. After some tests I switched them to BC546B which work more stable. Unfortunately I forgot to take a new picture.

To make the remote work with Openhab2 you need to:

  1. Connect remote to GPIO (see first schema)
  2. Install Expire Binding - link
  3. Implement some code:

.items

Group PowerOutlet <poweroutlet>

// Below switches should not be used directly
// Instead of this you can use virtual buttons
Switch	PowerOutlet443_1_ON	"Power outlet 433 no 1 ON"	<poweroutlet>	(PowerOutlet)	{gpio="pin:20 initialValue:low",expire="1s,command=OFF"}
Switch	PowerOutlet443_1_OFF	"Power outlet 433 nr 1 OFF"	<poweroutlet>	(PowerOutlet)	{gpio="pin:21 initialValue:low",expire="1s,command=OFF"}
Switch	PowerOutlet443_2_ON	"Power outlet 433 nr 2 ON"	<poweroutlet>	(PowerOutlet)	{gpio="pin:16 initialValue:low",expire="1s,command=OFF"}
Switch	PowerOutlet443_2_OFF	"Power outlet 433 nr 2 OFF"	<poweroutlet>	(PowerOutlet)	{gpio="pin:26 initialValue:low",expire="1s,command=OFF"}
Switch	PowerOutlet443_3_ON	"Power outlet 433 nr 3 ON"	<poweroutlet>	(PowerOutlet)	{gpio="pin:19 initialValue:low",expire="1s,command=OFF"}
Switch	PowerOutlet443_3_OFF	"Power outlet 433 nr 3 OFF"	<poweroutlet>	(PowerOutlet)	{gpio="pin:13 initialValue:low",expire="1s,command=OFF"}

// Virtual switches which use rule to change power plugs states
Switch PowerOutlet443_1 "Power outlet 433 nr 1"	<poweroutlet>
Switch PowerOutlet443_2 "Power outlet 433 nr 2"	<poweroutlet>
Switch PowerOutlet443_3 "Power outlet 433 nr 3"	<poweroutlet>

.rules

rule "Turn ON power outlet no 1"
when
	Item PowerOutlet443_1 changed from OFF to ON
then
	PowerOutlet443_1_ON.sendCommand(ON)
	Thread::sleep(100)
	PowerOutlet443_1_ON.sendCommand(OFF)
end

rule "Turn OFF power outlet no 1"
when
	Item PowerOutlet443_1 changed from ON to OFF
then
	PowerOutlet443_1_OFF.sendCommand(ON)
	Thread::sleep(100)
	PowerOutlet443_1_OFF.sendCommand(OFF)
end

rule "Turn ON power outlet no 2"
when
	Item PowerOutlet443_2 changed from OFF to ON
then
	PowerOutlet443_2_ON.sendCommand(ON)
	Thread::sleep(100)
	PowerOutlet443_2_ON.sendCommand(OFF)
end

rule "Turn OFF power outlet no 2"
when
	Item PowerOutlet443_2 changed from ON to OFF
then
	PowerOutlet443_2_OFF.sendCommand(ON)
	Thread::sleep(100)
	PowerOutlet443_2_OFF.sendCommand(OFF)
end

rule "Turn ON power outlet no 3"
when
	Item PowerOutlet443_3 changed from OFF to ON
then
	PowerOutlet443_3_ON.sendCommand(ON)
	Thread::sleep(100)
	PowerOutlet443_3_ON.sendCommand(OFF)
end

rule "Turn OFF power outlet no 3"
when
	Item PowerOutlet443_3 changed from ON to OFF
then
	PowerOutlet443_3_OFF.sendCommand(ON)
	Thread::sleep(100)
	PowerOutlet443_3_OFF.sendCommand(OFF)
end

.sitemap

Text label="Power outlets" icon="poweroutlet" {
    Default item=PowerOutlet443_1
    Default item=PowerOutlet443_2
    Default item=PowerOutlet443_3
}

You may ask is ‘Expire Binding’ necessary? In my opinion yes, because remote buttons are mostly momentary which means that if you don’t release finger press the signal will be sended all the time.

gniazdka_sitemap

Hope this post will be helpful to someone :slight_smile:

3 Likes