Beginner question, pushbutton

Discussion in 'General Electronics Chat' started by Spek, Oct 8, 2009.

  1. Spek

    Thread Starter Member

    Feb 6, 2009
    20
    0
    Hi,

    A beginner question. I'm trying to get a pushbutton to work, but without succes so far. The button itself has 2 legs, a green LED, and it sais: "1A 125V, 0.5A 250V". Here is its paper:
    http://www2.produktinfo.conrad.com/...27-da-01-en-DRUCKTASTER_R13_529AL_Rot_LED.pdf

    One of the problems I have is that I'm not familiar with such papers... For example, I'm confused about its required input voltage. Is it 125V or more, or 2Volt like the Circuit Diagram in the paper sais?


    So far I connected it to a Microcontroller that delivers 5 Volt:
    Code ( (Unknown Language)):
    1.  
    2. 5V ---> resistor A ---> BUTTON ----------------> Microcontroller digital input
    3.                                      |
    4.                                      -------- resistor B ---> Ground
    5.  
    So, the 5Volt goes through a resistor towards the button long leg. The shorter leg is connected to the ground via another resistor (pull-down?) and the digital input.

    Depending on the set of resistors I use, either my input is always high or low, no matter if the button is pushed or not. My first guess is that the input voltage(5Volt) is too strong, so it will flow through the button even if its not pushed. If I use stronger resistors(A), the LED in the button dims, and at a certain point my microcontroller input will keep low, also if the button is pushed.

    Currently resistor A = 47 KOhm, B = 220 KOhm. In this situation the button LED is off, but the input on the microcontroller is still high. If I use a weaker resistor B (to the ground), it will eventually turn low.


    Probably a stupid beginner question, but let's hope I learn something from it :)

    Rick
     
  2. Wendy

    Moderator

    Mar 24, 2008
    20,766
    2,536
    You've got a voltage divider, which could mean the CPU isn't getting a clean signal.

    Try something like this instead.
     
  3. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Try this:

    [​IMG]

    S1 is your switch.
    D1 is the LED in your switch.
    R1 limits the current through the LED to about 20mA when the switch is closed. The LED will not be lit when the switch is open.
    C1, R2, and R3 make up a "de-bounce" circuit for your PIC input. Mechanical switches have contacts that bounce and chatter for quite a while in electronic terms. R2 causes C1 to charge relatively slowly. When S1 is opened, R3 provides a discharge path for C1 via R2 to ground. You can't rely on R1/D1 to discharge C1, as it may take quite a while for the voltage on C1 to drop to a logic 0 level.

    For more on debouncing, read this very helpful PDF by John Ganssle: http://www.ganssle.com/debouncing.pdf
     
  4. Wendy

    Moderator

    Mar 24, 2008
    20,766
    2,536
    Save from a brain fart again. Thanks Wookie. :rolleyes:

    My diagram has major flaws.
     
  5. Spek

    Thread Starter Member

    Feb 6, 2009
    20
    0
    I knew it would be something stupid. The button has actually 4 connections; 2 legs for the LED, 2 clips for the button itself. I connected the whole thing through the LED, so basically my digital input always resulted into HIGH.

    Thanks for the scheme's nevertheless, I need to learn howto read them! It's late now, but trying to reduce noise (de-bounce) is a nice excersise for tomorrow. But let's see if I understand it a little bit...
    - The LED burns when the button is closed. It's the shortest route to the ground.
    - R3 is the second shortest route... can I connect R1/R3/C1 to the same ground?
    - To be honest, I thought current would only pick the shortest(less resistance) route, so behind R2 and R3 I would see nothing because it already left via R1. Guess I'm wrong :)
    - C1 = capacitor? If I remember correctly, they can "store" some power and then discharge. But when does that exactly happen (after x time, when full, contionously, ...)
    - C1 is also connected directly to the ground. I don't understand why it would discharge via R3, as this takes more resistance than through R1 or directly to its own ground connection.

    Sorry for the simple questions, but everything I ever learned about electronics also "discharged" via my left ear :) Too bad, because I think you can make a great hobby out of it.

    Thanks for helping,
    Rick
     
  6. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    It happens. :)

    OK, but it is not a DEAD short; the current through the LED is limited to 20mA by the 150 Ohm resistor.
    According to the datasheet you linked to, the LED has a Vf (forward voltage) of 2v, but the current was not specified. 20mA is a pretty safe value for most LEDs nowadays.
    So, to calculate the current limiting resistor for the LED:
    Rlimit = (Voltage Supply - VfLED) / Desired Current
    Rlimit = (5v - 2v) / 20mA
    Rlimit = 3v / 0.02 Amperes = 150 Ohms, which is a standard value.
    You could go higher in resistance if you wish, but not lower.
    All ground symbols should be considered as connected to the same point.
    No, R1/D1 will take some current, but your power supply should be able to output more than that. If not, you will have problems.
    See this chapter in our E-book: http://www.allaboutcircuits.com/vol_1/chpt_16/index.html

    It WILL partially discharge through R1/D1, but as the voltage drops, current through D1 will decrease; it may take quite a while for C1 to discharge to a valid logic 0 level. R3 is there to ensure that C1 discharges all the way to 0v.
     
Loading...