Go Down

### Topic: What does the LED do to my circuit? (Read 240 times)previous topic - next topic

#### pickle_incognito

##### Sep 19, 2020, 06:00 pm
Hi,

First post here, any pointers would be appreciated.

I am trying to figure out how to use an Arduino as a keyboard HID with three pin LED Arcade buttons as the inputs.

The button are from with the Hikig Zero Delay LED kit(see Pics) and the buttons are the 3 pin versions not 4, if it was 4 I would be golden but this is not the case.

So without going into too much detail about all the rabbit holes I have gone down I am at a point where I am trying to reproduce the the functionality of the button using a breadboard only.  While doing this I have stumbled upon what I assume is a very basic issue but I don't have a fundamental understanding for why.

This is a simple button circuit with an LED attached, when the button is pressed I want the LED to light up as well as change the state on Pin 9.  I am using the internal pullup on pin 9 and will print HIGH or LOW to COM4 based on the button being pressed or not.

So my questions is this:  Why does this work when the LED is not in the circuit, the serial monitor shows the state changes, all is good.  When the LED is attached the voltage doesn't drop to zero and the pin stays HIGH, the LED does light up.

Measuring from PWR to Pin 9:

Button not pressed = 0V (no LED)
Button not pressed = 0V (with LED)
Button pressed = +5V (no LED)
Button pressed = +2.38V (with LED)???

Measuring from PWR to GND

Button not pressed = +5V (no LED)
Button not pressed = +5V (with LED)
Button pressed = +5V (no LED)
Button pressed = +5V (with LED)

Measuring from Pin 9 to GND

Button not pressed = +5V (no LED)
Button not pressed = +5V (with LED)
Button pressed = 0V (no LED)
Button pressed = +2.73V dropped (with LED)???

While it will be great if someone can tell me the straight forward answer if anyone has a recommended "Intro to Electronics" book that would have allowed me to answer this myself that would be great too.

Here is my code:

#define PIN_D 9 // Pin for d

void setup(){
pinMode(PIN_D, INPUT_PULLUP);
Serial.begin(9600); // Setup Serial communication
}

void loop(){

Serial.println("LOW");
}else{
Serial.println("HIGH");
}

delay(100);
}

#### larryd

#1
##### Sep 19, 2020, 06:32 pmLast Edit: Sep 19, 2020, 06:38 pm by larryd
Code: ("  To be tested") [Select]
`#define PIN_D 9 // Pin for dbyte lastState;void setup(){  Serial.begin(9600);  pinMode(PIN_D, INPUT_PULLUP);  lastState = digitalRead(PIN_D);} //END of setup()void loop(){  byte thisState = digitalRead(PIN_D);  if (lastState != thisState)  {    lastState = thisState;    if (thisState == LOW)    {      Serial.println("LOW");    }    else    {      Serial.println("HIGH");    }  }} //END of loop()`

No technical PMs.
If you need clarification, ask for help.

#### pickle_incognito

#2
##### Sep 19, 2020, 06:44 pmLast Edit: Sep 19, 2020, 06:45 pm by pickle_incognito
Same results, with the new code:

No LED I get Low printed when pressed and High when I let go(my code just checks the state every 100ms and prints High or Low)

With LED - Nothing printed at all.

HOLD ON - The new diagram wasn't there yet.....Need to check again.

#### larryd

#3
##### Sep 19, 2020, 06:45 pm

No technical PMs.
If you need clarification, ask for help.

#### pickle_incognito

#4
##### Sep 19, 2020, 06:54 pmLast Edit: Sep 19, 2020, 06:54 pm by pickle_incognito
I had it wired up that way before and yes it was ok.  I don't remember exactly why I moved the LED but I did and when it didn't work with the same results I got confused.

So this questions isn't about how to get the button, led and high/low output, the question is why does it work with the LED before the switch or without and LED altogether but not when the LED comes after the switch?

#### larryd

#5
##### Sep 19, 2020, 07:02 pm
The way you had the circuit wired resulted in a non logic level on pin 9.

The LED and the 1k were creating a voltage divider when the switch was pressed.

2.2v across the LED and 2.8v across the 1k.

2.8v is not a HIGH or a LOW, it is an indeterminate level.

No technical PMs.