Pages: [1]   Go Down
Author Topic: Problem with tactile switch  (Read 1273 times)
0 Members and 1 Guest are viewing this topic.
United kingdom
Offline Offline
Full Member
***
Karma: 1
Posts: 198
just think how much free time you would have if everything worked first time!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm no electronics wizard, so the solution to this is probably very simple....

I have a tactile switch, I have wired this in series with a resistor and LED to a digital pin configured as output.  When I write the the digital output the LED does not light until I depress the tactile switch.  This works, its clear to me why and I understand it.

Then I wired the tactile switch to a digital pin configured as input.  Another pin is configured as output with a resistor and LED connected.

In the code I read the digital input and if its HIGH set the digital output HIGH, if not I set the digital output LOW.  This doesn't work and I'm struggling to see why not.  The wiring for this is as follows:

(+) from pin 8 (configured as input) to one side of switch.  (-) from other side of switch connected to GND.
(+) from pin 13 (configured as output) to resistor, other side of resistor to longer leg of LED, short leg of LED connected to GND.

I'm trying to write a debounce routine using my timer libary, but failing to see why this doesn't work.
Logged

Kind Regards,
Sy

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 27372
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you turn on the internal pullup resistor so the input pins sits a solid  high level when switch is not pressed?

pinMode (pin8, INPUT);
digitalWrite (pin8, HIGH);
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

United kingdom
Offline Offline
Full Member
***
Karma: 1
Posts: 198
just think how much free time you would have if everything worked first time!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No...I'm really confused and experiencing some very odd behaviour.

I have a prototype breatboard which only has the components as mentioned above.  I'm monitoring the application via serial.print output statements.  Nothing happens at all, until I move my finger over the bread board.  I'm not touching anything, just moving my finger over the components, on the serial output I see that the input is going high momentarially then low again, this happens very realiabily as I move my hand back and forth.

Is this normal?
Logged

Kind Regards,
Sy

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 27372
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Turn on the internal pullup resistor, will keep the pin being read from acting like an antenna.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

United kingdom
Offline Offline
Full Member
***
Karma: 1
Posts: 198
just think how much free time you would have if everything worked first time!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you, worked like a charm, now when switch depressed input is LOW, when not depressed HIGH.  I can modify my code to suit.

Thanks again!
Logged

Kind Regards,
Sy

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 27372
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

There you go.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Nothing happens at all, until I move my finger over the bread board. 

I have videos showing why this happens:
http://www.cmiyc.com/tutorials/arduino-pull-ups/
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

Pages: [1]   Go Up
Jump to: