A diode and a floating GPIO is confusing me

Hi all. New to Arduino and this is my first post. Probably one of many to come. I've followed a project from this page here (Traffic Lights): DFRduino_Beginner_Kit_For_Arduino_V3_SKU_DFR0100-DFRobot

It all works great and has helped me to understand somewhat what a floating state is for a GPIO is as well as pull-down resistors. Playing around, I added a diode to the circuit, between the button (and pull-down resistor) and the input pin 9, with the negative cathode pointing towards the button. The circuit works and the lights change when I push the button.

Question)
So how am I able to send a signal to Pin 9, seemingly against the diode? Pin 9 being the input pin waiting on a HIGH state to initiate the code to change the lights. I didn't expect the lights to work as they should with the diode in. I was expecting to push the button and nothing happen.

If I reverse the diode, it works as I was kind of expecting. The voltage can't be pulled down to ground and I believe the pin stays in the floating state, which continually triggers the light changing.

If the diode works then it is your expectations that need fixed. :slight_smile:

Diodes have reverse leakage. Some (schottky) more than others.
That leakage is enough to pull the pin high.
Leo..

Wawa:
Diodes have reverse leakage. Some (schottky) more than others.
That leakage is enough to pull the pin high.
Leo..

scubamandan:
If I reverse the diode, it works as I was kind of expecting.

I think he either doesn't understand the diode or how it relates to the package. He understands it blocks in one direction and when he reverses it, guess what? My guess is he doesn't understand which direction it blocks in or is confused about how to determine which end of the package is which. That or I have to believe the manufacture got it wrong.

If you put the cathode (band) towards the pin, think about what is happening.

When the button is pressed, the anode of the diode is held high. Unless the pin is also high, the diode will conduct, and the pin will become high. (it's wired such that the pin is pulled down and button connects to vcc, the opposite of how people normally do it)

What should be surprising is that it can see that you've released the button; there's now 0v on the anode, and whatever there was before on the cathode - a higher voltage, so it doesn't conduct, so you'd expect it to stay at that voltage. That it doesn't... reverse leakage is all I can think of for that. There's not much capacitance in a pin, though, so it doesn't take much to change the value on the pin a case like that. I suspect it can misbehave while the button isn't pressed - try waving your hands close to pin 9 with the button released (and the diode like you have it).

@others responding: uhh guys? You seem to be posting like the diode is the other way around, or the switch is? (or you've just forgotten which end is the cathode - I always have to double-check when people use "anode" and "cathode" :wink: )

DrAzzy:
I
@others responding: uhh guys? You seem to be posting like the diode is the other way around, or the switch is? (or you've just forgotten which end is the cathode - I always have to double-check when people use "anode" and "cathode" :wink: )

He simply points to someone else's diagram and describes what he thought he did. Then he says it works opposite what he expects. "Operator error" is the obvious option. Unless he posts a photo of what he did, then that remains the most obvious.

Thanks for your help, autofoptions. Though to be honest I was expecting more than just "Haha, what a newb."

Thanks Wawa. I was wondering this, and it would explain things. I was reading the following (D+M), so I guess any small amount of current leaking through the other end of the diode would do the job.

I thought diodes only allowed current to go one way 100%, but after your comment I started reading into diodes a bit more. An example of what I found is:

"although the voltage increases, hardly any current flows. This small current is called the leakage current of the diode and is typically only a few micro-amps with germanium diodes and even less in silicon."

So my current understanding is now this:
Just those few micro-amps would be enough to pull the pin to HIGH and get things going. If I reverse the diode, with the cathode band towards the pin, the diode doesn't allow the pin to be pulled down and the lights keep on changing.

Its actually a contest between the internal protection diodes' reverse leakage and the external
diode's reverse leakage... Typically an external diode has 100's of times the rating of the protection
diodes, so the leakage current is much larger (ie nA rather then pA).

It is also complicated by the fact that each input has two protection diodes, and their leakage
currents work against each other to pull both up and down, so floating inputs can actually
stabilise somewhere between 0V and 5V repeatably, but it takes very little external influence
to dominate.

Reverse biased diode leakage is highly sensitive to temperature, doubling for each rise of a few
degrees, by the way, so one problem with a floating input is that its behaviour can change
radically with temperature.

Lastly schottky diodes have much higher leakage currents and at high temperature this can reach
milliamp values.

Thanks for the extra info Mark :slight_smile: Though I'm going to have to lookup some of what you said. i.e. Built in diodes on the GPIO pins (If I read you correctly)

Yup. All the pins on most microcontrollers have two internal diodes on them, one to Vcc, one to Gnd, arranged so as to keep the voltage on the pin from rising above Vcc or below Gnd; these are termed protection diodes.

And just for completeness their job is to protect against static electricity discharge which would otherwise
easily trash the whole chip through handling (in fact mains pickup by the human body is the main risk in
practice, this can be 50V or so).

scubamandan:
Thanks for your help, autofoptions. Though to be honest I was expecting more than just "Haha, what a newb."

Sorry, I guess I misunderstood what you meant when you said

scubamandan:
If I reverse the diode, it works as I was kind of expecting.

I didn't catch you were covering two different expectations there. I read it as when you turned it around it worked and previously it hadn't. Not, it works in position A as expected but not in position B.

One of my hobbies is home brewing. I know not to mix the two but after a few home brews you kinda 'forget'. Again, sorry. My bad.

Is there a reason for "adding" the diode if you don't understand why the circuit works or is it that you think you understand but thought the diode was "missing" ? Inputs float HIGH so I usually make buttons "active LOW" ( pull-up on GPIO pin and button/switch to GND. I change the code if necessary )
The circuit linked appears to have a pullDOWN and button to +5V. A resistor to +5V with a .1 uF cap to GND makes a good switch debouncer.

Thank you outofoptions. Very gracious of you. I tried home brewing a couple of times to make ginger beer. I think I gave up after I ended up with something like ginger champagne. And I nearly threw up when I tried using some wild yeast I cultivated :smiley:

Thanks to everyone. You’ve given me much to learn and experiment with :slight_smile:

Ras, it was mainly because I was trying to figure out why it needed that extra resistor and route to ground, which led me to learn about pull down and pull up resistors and floating state. From then it was just experimenting to see what happened. So I added the diode just to test some hypotheses. I’m glad I did, as thanks to this thread alone I’ve learned a fair bit. :slight_smile:

There's experimentation , and then there's "BREWERS GONE WILD !" ...
The same is true in Electronics. You could have asked about the diode and learned just as much without adding it. The standard rule in electronics is "If you don't know WHAT you are doing, DON'T do anything ! To some extent this applies to hobbyist electronics where mistakes are paid for by the hobbyist rather than a company. The object is to prevent damage to components. Some Newbees are out of control because they have spent too much time playing video games where you can do whatever you want. Standard practice is to read datasheets to obtain electrical specifications and "Absolute Maximum Ratings" and then "do the math". If you don't know what a datasheet is or which "math" to do, you probably should limit your experimentation to fantasizing on paper and asking questions. An example of why techs are not supposed to expeeiment is a factory maintenance tech pushing a relay test button while troubleshooting a TOXIC WASTE LEAK ALARM circuit and inadvertently triggering a 6-foot diameter 120 decible alarm siren mounted on the factory floor, bringing the entire factory production to screeching halt for 30 seconds until someone resets the alarm.
No harm done but probably not a good idea...

Point taken, but as a father of three children under 5 and when I have maybe an hour to myself every odd day (zero time for computer games), I do what I can. Many of the items I've bought from eBay don't have datasheets and I've always learned well from experimentation. So while I can see what you mean when you're doing an actual job, this is just me learning with minimal possible consequences. I have bought a book to get me on the right track though (Beginning Arduino). When my newborn starts sleeping better at night, I might just get the time to read it. :slight_smile:

Maybe others won't agree but I draw a distingtion between "Trial and Error" and "Experimentation".

I do "Experiments" at work all the time following the strict Tedt guidelines ser by the engineer ( a PhD) . The "Procedure" requires specifuc parameters and number if repetitions, delay in seconds between test shots etc... If for some reason these cannot be followed ( breaktime, lunch, bathroom break ) then the test must be repeated. I would hardly call that "Trial and Error", which is pretty much what you are doing. Making the transition from trial & error to experimentation can take months or years.