Go Down

Topic: What am i getting with unconnected pin ? (Read 803 times) previous topic - next topic

as1m

When i read with analogRead(0) with unconnected pin, what are these random numbers and how are they generated ?

Thanks for helping.


kf2qd

That pin is "FLOATING". What you are seeing is the influence or the misc. electromagnetic fields around the board at a instant in time. There is a mix of RF and 60Hz fields that are interacting and with the analog input pin connected those fields are enough to build up a charge on that pin. Digital inouts can show some of the same effect - being either LOW or HIGH but you won't see it as dynamically as you do on an analog input. If the reading on a pin is in any way important make sure the proper connections are made to properly condition the signal.

srinathdevelopment

hmmm wonder if this behavior can serve (adequately scaled of course and with a speed penalty) as a "true" random number generator vs. the pseudorandom algorithm in the library ?
Ardgrafix6100 - A fast, full-featured Arduino graphics driver for Nokia 6100 LCDs http://code.google.com/p/ardgrafix6100/

dxw00d

Its often suggested as a method of seeding the random number generator.

srinathdevelopment

#5
Apr 26, 2012, 07:31 pm Last Edit: Apr 26, 2012, 07:34 pm by srinathdevelopment Reason: 1

Its often suggested as a method of seeding the random number generator.

Makes sense... Thanks! One of the benefits of the pseudorandom generator algorithm is that it is supposed to generate a flat frequency distribution which is unlikely to be the case with analogRead on a floating pin and seeding it with this as you say would randomized it in a way timer counter may not.

One of these days nevertheless, i will try taking a look at what  frequency distributions you can get on a floating pin :)
Ardgrafix6100 - A fast, full-featured Arduino graphics driver for Nokia 6100 LCDs http://code.google.com/p/ardgrafix6100/

Go Up