Hi everyone, i'm a newbie so i am having a lot of problems with these stuff. My problem is with the INPUT_PULLUP function. Firstly, here is a simple code:
From what i learned from the internet, the pin 8 now is equilavent to connecting a ~20k ohm resistor between the pin and +5V. So i try if this is true. When i connect pin 8 and 5v pin to the LED, and it worked out well as i expected( the LED isnt bright,but the digitalRead here show 1), but when i connect pin 8 and ground pin to the LED, the LED is still bright, but the digitalRead show that the voltage here is 0. What?? If both pin are 0, then how can the LED bright? I am currently stuck here and really need your help. Thank you!
P.S: Sorry for my bad english
The forward voltage of the LED is probably not high enough to cross the digital high voltage threshold, which is why the LED can still illuminate (driven by the internal pullup resistance) while the digital input still reads LOW (0).
I have also thought of that, but the LED i'm using here is green LED which requires more than 1,9 v to light up( i read this from the internet) so the voltage at pin 8 must be more than 1,9v which is higher then the digital high voltage threshold.
An LED is an INDICATOR - and you connect it to an arduino OUTPUT to show if the output is high or low.
INPUTs are for connecting devices that give a SIGNAL to the Arduino; such as a switch.
You can read about INPUTS here
If you have a good multimeter (DMM, high impedance), measure the voltage over the LED once connected to the Input pin. Then you will know what the voltage divider made by +5V --- 20K -- LED – GND ground is doing. You can also decide to measure the current in the circuit to se what is going on.
In this kind of topics to measure is to know, but beware, your multimeter also has an internal resistance that can play a role when measuring.
1. Remove JI (jumpre J1) and execute the following code:
pinMode(8, INPUT_PULLUP);
(1) Switch S1 is closed. Internal pull-up resistor Rip gets connected. HIGH (5V) virtually appears at the input of GOIB gate. The execution of the following codes shows 1 on the Serial Monitor.
bool n = digitalRead(8);
Serial.print(n, BIN); //shows: 1
2. Place J1 and connect GND signal at the negative side of LED. The LED receives about 5/20k = 0.25 mA current which is not enough for the LED to be bright. (A LED needs about 10-15 mA current (with 2.5V drop across it) to emit light with good brightness.). At this setup, the DPin-8 is essentially at GND potention. Now, we will see 0 to appear on the Serial Monitor when the following codes are executed. (LED is providing a circuit to GND with an effective resistance of about 250R (2.5V/10mA)).
bool n = digitalRead(8);
Serial.print(n, BIN); //shows: 0
When the pin is operated as "output pin", then VIH can go as low as 3.0 V (as per data sheets); but, the @quanny is operating the said pin as "input pin with internal pull-up resistor"; so, there is no way to get enough volatge at the pin to turn on the LED.
Depends on the LED, some will light with very little current, I used to use 10K resistors with LEDs when I wanted an indicator with a small current draw.