Go Down

Topic: Problem with tactile switch (Read 1 time) previous topic - next topic

SPlatten

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.
Kind Regards,
Sy

CrossRoads

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);
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

SPlatten

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?
Kind Regards,
Sy

CrossRoads

Turn on the internal pullup resistor, will keep the pin being read from acting like an antenna.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

SPlatten

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!
Kind Regards,
Sy

CrossRoads

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

James C4S


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/
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Go Up