Replace buttons with PNP transistor

Hi there, I’m hoping someone can tell me if I set this up correctly, things seem to work with my arduino, but when I switch over to a raspberry it doesn’t work anymore, so I’m thinking maybe I looked over something in the pcb part, and someone can give me a hint.

I have a remote that controls our fan system in the house, it looks like this:

I want to be able to use it from my mobile phone with openhab2.

Once I opened the remote, I had the idea to replace the buttons with PNP transistors, as you can see I replaced one button with some wire, to test it out on a breadboard:

and sure enough, when I pull the base low (putting the resistor in -) for a second, and then leave it floating, the button is triggered, and the fan starts running.

So far so good :slight_smile:

After this small triumph, I desoldered 3 of the buttons and soldered a small pcb with the PNP transistors for the switch and the resistor for the base connection with the arduino this pcb will connect the arduino and the remote.


The blue wires are all - wires for the switch, the other colors are the + wires, the red and orange are + & - for power.

I connected the my arduino pins to the base pins on my small pcbs, and wrote this sketch:

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(16, INPUT);
  pinMode(18, INPUT);
  pinMode(19, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  //Receiving serial data, post to server
  if (Serial.read() == '

This all works great!
But, now I would like to connect this board to my raspberry pi instead of the arduino, I wrote a similar script in shell, which does exactly the same (pull the output low for 200ms, than switch back to input)

And when connecting a led to + and a GPIO pin of the raspberry I see the led blinking for 200ms, so I know it works.

But the remote will not work with the raspberry.

I’m a beginner, So my question ultimately is, did I wire this up correctly? or did I forget anything?

)
  {
    String  readData = captureSerial();
    if(readData == “1”){
      Serial.println(“set to 1”);
      digitalWrite(16,LOW);
      pinMode(16, OUTPUT);
      delay(200);
      pinMode(16, INPUT);
      }
      if(readData == “2”){
      Serial.println(“set to 2”);
      digitalWrite(18,LOW);
      pinMode(18, OUTPUT);
      delay(200);
      pinMode(18, INPUT);
      }
      if(readData == “3”){
      Serial.println(“set to 3”);
      digitalWrite(19,LOW);
      pinMode(19, OUTPUT);
      delay(200);
      pinMode(19, INPUT);
      }
  }
}
String captureSerial()
{
  String readData = “”;
  for (int i = 0; i < 100; i++)
  {
    delay(10);
    char curChar = Serial.read();
      if (curChar == ‘#’)
    {
      break;
    }
    readData += String(curChar);
 
  }

return readData;
}


This all works great!
But, now I would like to connect this board to my raspberry pi instead of the arduino, I wrote a similar script in shell, which does exactly the same (pull the output low for 200ms, than switch back to input)

And when connecting a led to + and a GPIO pin of the raspberry I see the led blinking for 200ms, so I know it works.

But the remote will not work with the raspberry.

I'm a beginner, So my question ultimately is, did I wire this up correctly? or did I forget anything?

It's hard to say much because you haven't told us much. Not a single part number or component value.

Given that, my guess would be that is something to do with the fact that your Arduino is 5V and the Pi is 3.3V.

PNPs would be appropriate for pull down resistors. Are you sure the buttons use that instead of the more likely pull ups? If it's pull ups you should be using NPNs.

Desolder your circuit from one of the button inputs, and measure the resistance between GND and each of the button pads (circuit unpowered of course). If you get a short circuit to one and open circuit to the other, it's probably pull up. If you get high resistance (could be up to a few dozen kilo-ohms) to one and open circuit to the other, it's probably pull down.

What is the battery voltage used to power the remote?

PaulRB: It's hard to say much because you haven't told us much. Not a single part number or component value.

Given that, my guess would be that is something to do with the fact that your Arduino is 5V and the Pi is 3.3V.

Sorry, I typed it in a hurry, the parts:

10k resistors between base and gpio PNP's are 2N2907

I use the 3.3v terminal, also tried it on a whisper node with success which is completely 3.3v

cbe is collector, base, emitter connection of the pnp

Simplified (and badly made :) )drawing:

|500x375

Jiggy-Ninja: PNPs would be appropriate for pull down resistors. Are you sure the buttons use that instead of the more likely pull ups? If it's pull ups you should be using NPNs.

Desolder your circuit from one of the button inputs, and measure the resistance between GND and each of the button pads (circuit unpowered of course). If you get a short circuit to one and open circuit to the other, it's probably pull up. If you get high resistance (could be up to a few dozen kilo-ohms) to one and open circuit to the other, it's probably pull down.

What is the battery voltage used to power the remote?

thanks I will doublecheck today, I thought I needed the pnps, when I measure the voltage across the button pads I get 3.3v when not pressed and 0v when pressed. since it seems to work with the arduino, would this rule out the npn?

the remote uses coincell batteries normally.

You will always read that when measuring directly across the button contacts, whether it's pull up or pull down. That's why you have to measure relative to the PWR and GND rails.

I was actually going to recommend measuring directly across the button myself, until I thought about it more and realized the two different configurations would still give the same measurements, so there was no point.

The other thing you could do, that may be simpler, is short the button contacts together than measure the voltage at the short relative to GND. If you read 0 it's pulled up (because the button GNDs it), if it's positive it's pull down.

I guess small current is leaking into the Raspberry's pin. Try to configure it as pull-up or driving high instead of only configurating a input. (Are you sure the pin's pull-down is not activated? IIRC Raspberry has both internal pull-up and pull-down possible.)

Thanks so much for the clear explanations, I will try and measure the current correctly tonight, and I will try and check the pins for the raspberry, that might be a good possibility too.

Smajdalf: I guess small current is leaking into the Raspberry's pin. Try to configure it as pull-up or driving high instead of only configurating a input. (Are you sure the pin's pull-down is not activated? IIRC Raspberry has both internal pull-up and pull-down possible.)

Setting them to output & high, and then switching to low for 200ms seems to have done the trick!

Do I still need to doublecheck if the buttons are actually pull downs, or does the fact that the switching works rule the possibility of them being pull ups out?

fmms: Setting them to output & high, and then switching to low for 200ms seems to have done the trick!

Do I still need to doublecheck if the buttons are actually pull downs, or does the fact that the switching works rule the possibility of them being pull ups out?

If it works, it works. It's not "the right way" to use with pull ups (I still think that's what the board is using), but it'll be fine since it's pulled up to the same level as the driving signal. It's when you're trying to switch a higher voltage than the base signal that you really need to get it right.

For the sake of completeness, and because I want to learn to do it the right way I just shutdown the raspberry to measure the resistance from ground to pad - and gnd to pad + of on of the buttons, here are the results:

  • pad to gnd 8.25Mohm
  • pad to gnd 0.00

If I got this right it is pulled down, correct?

Pull-up and pull-down resistors are usually on the kOhm range, not MOhm.

Looks to me like you're measuring wrong

fmms: For the sake of completeness, and because I want to learn to do it the right way I just shutdown the raspberry to measure the resistance from ground to pad - and gnd to pad + of on of the buttons, here are the results:

  • pad to gnd 8.25Mohm
  • pad to gnd 0.00

If I got this right it is pulled down, correct?

No. - pad to GND = 0 Ohm means there is pull up on + pad. You may try to measure resistance from + pad to 3V3 but this does not mean much: the pull up may be implemented in a MCU and when it is not powered it will be inactive.

Another possibility is to "press the button" and measure voltage between GND and the button. If it is 0V there is pull up. If it is 3V3 it is pull down.

Smajdalf:
No. - pad to GND = 0 Ohm means there is pull up on + pad. You may try to measure resistance from + pad to 3V3 but this does not mean much: the pull up may be implemented in a MCU and when it is not powered it will be inactive.

Another possibility is to “press the button” and measure voltage between GND and the button. If it is 0V there is pull up. If it is 3V3 it is pull down.

Sorry you are totally right, I’m still trying to wrap my head around this :slight_smile:
If the resistance is 0 it would mean the resistors are on the plus side… and judging by this picture that seems to be the case:

(the blue lines are connected to the negative side of the circuit, the top line is going straight to ground on the ATTiny from the remote)

So, will switching out the pnp’s for npn’s and reversing the collector and emitter wire be the way to go?

I don't think there is any extra gain from switching the transistor. It is the "right way" using NPN but if it works with PNP it is no problem.

Hi, Why are you using transistors, when opto-couplers would have simplified the whole assembly.

It would then be Arduino and Pi compatible.

https://en.wikipedia.org/wiki/Opto-isolator

Tom.. :)

Where exactly do you see simplification? I see 4 pin device + current limiting resistor vs. 3 pin device + current limiting device. In given context optocoupler is more expensive device with (at least) one leg to solder and no extra gain.

Not to mention that a DIP-4 package is significantly larger than a TO-92.

I was just measuring my pnp's and it looks like a small current keeps leaking through the pnp (when I hold a led against the collector and emitter it lights up faintly)

When I setup a basic breadboard setup this doesn't happen at all, On a breadboard I measure around 1.6v on the pcb when transistor is closed with the pcb transistors I measure 3.02v between collector & emitter.

the setup for my breadboard: 4.7k +---Emitter----Base------Collector^v^----- LED ---GND | | / 10k \ / | +

I wouldn't want the remote to somehow be sending a signal 24 hours a day through my house.. I'm thinking the voltage to the base must be somehow lower compared to the voltage in the circuit? Is there an easy way to test this when the circuit is running?

When I leave my arduino pins on input it works (leaving the base floating) but the rpi will leak current as noted by someone.

I just measured 3.13v between gpio & base. and 2.91v between colletocr and emitter I'm trying an NPN tomorrow, if this shuts as expected I'm switching the 3 pnps out..