Hi I was trying to check if an LED glows using an arduino so that I can blink it periodiaclly.
I did the following code
void setup()
{
pinMode(2,OUTPUT);
pinMode(4,INPUT);
pinMode(3,OUTPUT);
Serial.begin(9600);
}
void loop()
{
digitalWrite(2,HIGH);
digitalWrite(4,LOW);
Serial.print(digitalRead(3));
delay(1000);
digitalWrite(2,LOW);
digitalWrite(4,LOW);
Serial.print(digitalRead(3));
delay(1000);
}
and through the breadboard the pind 4 and 3 have same been connected to same terminal.
Since current flows in a closed path so the current must flow from pin 2 t 4 and hence to 3 too but that is not happening , I am only getting all 0's can anyone tell me why?? and how do I achieve what I want to.
digitalWrite(4,LOW);
Why are you trying to write to an input pin ?
I can't help feeling that this is not going to end well and has maybe already damaged the Arduino.
I was trying to check if an LED glows using an arduino
Connect the LED to an output pin via a current limiting resistor to GND. Set the pinMode() to OUTPUT and digitalWrite() the pin HIGH.
I don't understand your connections, the way you've described them, but you made pin 3 an output, (which defaults to LOW), then you read it and print the result, so of course the result is 0, (LOW).
What else could you expect?
And you give no indication which pin the LED is connected to.
Plus what Bob said as I was typing.
Cross-posting is a no-no here. I just spotted your other thread.
Ardiono trouble or strange behaviour in project
And as I said in the other thread, you're supposed to use [code]code tags[/code]
when posting code.
@OldSteve
The other thread is younger
Pin 4 is an input and hence has a high impedance. There will be barely any current flowing from pin 2 to pin 4.
Pin 3 is an output; as you don't set it, it's basically undefined if it's high or low. Reading it back as you do will give you its current setting, not a possible value on the pin itself.
sterretje:
@OldSteve
The other thread is younger
I don't think it matters which came first.
To just blink LED this tutorial might help.
Didnt get your breadboard setup, please post a schema.