Replace a button with Arduino pin

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
Fozzie
 
Posts: 23
Joined: Sun Mar 17, 2013 10:53 am

Replace a button with Arduino pin

Post by Fozzie »

I have a device which is activated by the press of a momentary contact button. It runs at 4.5v. I would like to remove the button and activate the device via a signal from the Arduino. I'm not entirely sure how this would be accomplished however. Suggestions?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Replace a button with Arduino pin

Post by adafruit_support_mike »

What you want is a transistor, either a mosfet or a BJT.

Transistors are subtle when you try to use them as amplifiers, but when you use them as switches they're fairly simple. When the control pin's voltage is at the OFF level, the resistance between the other two pins is huge.. usually more than 20 megohms. When the control pin's voltage is at the ON level, the resistance between the other two pins is low.. a few ohms for a BJT or a small-signal mosfet, a few thousandths of an ohm for a power mosfet.

How is the switch connected to the circuit you want to control?

Fozzie
 
Posts: 23
Joined: Sun Mar 17, 2013 10:53 am

Re: Replace a button with Arduino pin

Post by Fozzie »

I've actually used both transistors and MOSFETs successfully before. I wondered if that was the way to do it or if there was something simpler I was missing.

Since I'm simulating a "momentary contact switch", I assume I will have to experiment with how long a delay I will need between switching the transistor "on" and then "off" for the device to activate.

The switch is connected by two wires that run to two pins on the control board. Re-routing it through a transistor shouldn't be too hard.

Thank you for pointing me in the right direction.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Replace a button with Arduino pin

Post by adafruit_support_mike »

Make sure you measure the output from the switch when it's closed. If it has a pull-up resistor, you'll see GND on both sides of the switch when it's closed. For that, you'll want an N-mosfet or NPN BJT. If the switch has a pull-down resistor, you'll see VCC on both sides of the switch when it's closed. For that, you'll want a P-mosfet (slightly harder to find) or a PNP BJT.

Fozzie
 
Posts: 23
Joined: Sun Mar 17, 2013 10:53 am

Re: Replace a button with Arduino pin

Post by Fozzie »

When the switch is open, I'm reading just under 4v. When it is closed, it goes to zero. I am using an NPN bipolar transistor (PN2222) from Adafruit which, from what you wrote, seems appropriate, but I am having a bit of trouble getting it to work. I'm not sure I am wiring it up right. I can see the transistor being turned on and off with the multimeter, but when I hook it up to the device, it fires once and that is it, instead of once with each push. This tells me that it is getting a constant GND and I'm not sure why. Exactly how should I have this wired up...?

(The voltage going through the transistor is enough to activate the device and not so much as it will fry it...so that isn't an issue.)

Fozzie
 
Posts: 23
Joined: Sun Mar 17, 2013 10:53 am

Re: Replace a button with Arduino pin

Post by Fozzie »

Okay, I got it to work simply by hooking one of the wires to the #10 I/O and one to ground. I set it to output and flip it between 0 and 150 with an analogWrite.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Replace a button with Arduino pin

Post by adafruit_support_mike »

Just to double-check your connetions:

- the 2N2222's collector should connect to the side of the switch that reads 4v when the switch is open
- the 2N2222's emitter should connect to the other side of the switch
- the 2N2222's base should connect to one end of a 1k resistor, and the other end of the resistor should go to your Arduino

Sending the Arduino's output HIGH will turn the 2N2222 on, which will have the same effect on the circuit as pressing the switch. Sending the Arduino's output LOW will turn the 2N2222 off, which will have the same effect as releasing the switch.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”