Go Down

Topic: Does Arduino keep the state of pin? (Read 688 times) previous topic - next topic


Aug 15, 2011, 03:06 am Last Edit: Aug 15, 2011, 03:11 am by ardypro Reason: 1
Hi, all,

According to the reference, the digitalWrite(pin, HIGH) command would set 5v or 0v to the pin when the command is digitalWrite(pin,LOW), but the waveform of the output pin, captured with a virtual scope, differs from the conclusion above, the waveform indicates the output voltage is set to 5v when digitalWrite(pin, HIGH) is executed, and then set to about 0v until next command is executed.

The code snippet as follows:

void loop()
  if (val)
  val = !val;


What I am confused is that the LED connected to the output pin could still light before it is set to LOW. Can anyone help me understand this command correctly?




Switch your scope to DC input , instead of AC


Probably used AC coupling where dc is needed.


Aug 15, 2011, 07:13 am Last Edit: Aug 15, 2011, 12:14 pm by ardypro Reason: 1
Ooops, my soundcard based virtual scope seems only support AC input.  =(


Ooops, my soundcard based virtual scope seems only support AC input.  =(

Then just trust your LED :)
Sound cards have capacitors or else to take DC out from input.


You have not put the curly braces in if-else statement!!!!!
Simply...You can't afford me..

Author Of:

Oops..some one gave me Karma...:)


The OP doesn't really have block statement so no curly brackets are needed.


I was seeing something very similar when I was testing the digital output functionality. A short while back I was trying to figure out why my relay driver circuit was always ON whether I set the digital pin to "0" or "1".

After a lot of scouring around, I learned the hard way that I had to explicitly set the digital pin as OUTPUT (duh). In a nutshell, the Arduino digital pins are all initiaized to INPUT by default, which is a High Impedance state (~10MOhms). Long story short, due to the much lower input impedance of my driver circuit, it seems to draw just enough extra current that it will be activated even if the digital output is set to "0".

Oddly, my observation with a DVM is similar in that the "0" state output is also around 1.5-2V, which was higher than one would expect. I tried adding pull-up and pull-down resistors but I still got glitchy results. But after reading the description of the I/O pins:


I just had to explicitly set the pin to OUTPUT, an everything worked like a charm afterwards. Since I didn't see your setup() function, I'm not sure if you are already setting the pit to OUTPUT - but it's worth a shot because the solution is not obvious.

Go Up