Replace a button with Arduino pin
Moderators: adafruit_support_bill, adafruit

Replace a button with Arduino pin

by Fozzie on Wed May 22, 2013 8:56 pm

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?
Fozzie
 
Posts: 20
Joined: Sun Mar 17, 2013 9:53 am

Re: Replace a button with Arduino pin

by adafruit_support_mike on Wed May 22, 2013 9:21 pm

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?
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 9165
Joined: Thu Feb 11, 2010 1:51 pm

Re: Replace a button with Arduino pin

by Fozzie on Wed May 22, 2013 9:26 pm

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.
Fozzie
 
Posts: 20
Joined: Sun Mar 17, 2013 9:53 am

Re: Replace a button with Arduino pin

by adafruit_support_mike on Wed May 22, 2013 10:37 pm

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.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 9165
Joined: Thu Feb 11, 2010 1:51 pm

Re: Replace a button with Arduino pin

by Fozzie on Fri May 24, 2013 12:13 pm

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: 20
Joined: Sun Mar 17, 2013 9:53 am

Re: Replace a button with Arduino pin

by Fozzie on Fri May 24, 2013 1:00 pm

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.
Fozzie
 
Posts: 20
Joined: Sun Mar 17, 2013 9:53 am

Re: Replace a button with Arduino pin

by adafruit_support_mike on Fri May 24, 2013 11:37 pm

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.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 9165
Joined: Thu Feb 11, 2010 1:51 pm