I'm trying to make a light detector using an LDR and a LED to see the results.
When my circuit is completely powered by my arduino, it all works fine.
But if I connect the LDR to a 5V regulated power source, then arduino reads floating values on the analog input (circuit as attachement).
As I can read by serial monitor and as I see my LED turn on and off, the floating values aren't random.
They cycle from 0 to 1023 and back to 0 (sinusoidal signal) with a time period of about 1 or 2 seconds.
When I turn the external power off, I expect random floating values, but I get the same cycle.
When I confirm the values with a multimeter, all voltages read the expected contant value (the same as if powered by the arduino).
My code is simply this:
void setup() {
// put your setup code here, to run once:
pinMode(11, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int v = analogRead(A1);
int m = map(v, 0, 1023, 0, 255);
analogWrite(11, m);
Serial.print(v);
Serial.print(' ');
Serial.println(m);
delay(100);
}
I already tried to comment the use of Serial, to confirm that it wouldn't affect the reading.
That makes sense for getting random floating values, as ground is used to form a reference value, right?
But what intrigues me is that those values are ordered in a cycle, much like a sinusoid with a 1-2 sec time period.
Out of curiosity, is there an simple explanation to that?
Might that be some external interference, like a WiFi signal?
Or some internal Arduino capacitance linked to analog inputs?
The clue is in the word "circuit" - there must be a loop, otherwise you don't have a circuit, you have an antenna (or more correctly each part of your "circuit" is acting as an antenna for the other).
That makes sense for getting random floating values, as ground is used to form a reference value, right?
But what intrigues me is that those values are ordered in a cycle, much like a sinusoid with a 1-2 sec time period.
Out of curiosity, is there an simple explanation to that?
Might that be some external interference, like a WiFi signal?
Or some internal Arduino capacitance linked to analog inputs?
It could be absolutely anything.
It could be picking up some foreign radio station fading in an out.
It could be picking up the size of your chest cavity as you breathe in and out.
It could be an interference pattern between two other slightly differing frequencies.
It could be measuring the CO2 being generated by the mould in the mug on your desk...
But what intrigues me is that those values are ordered in a cycle, much like a sinusoid with a 1-2 sec time period.
I suspect you are sampling the mains pickup at some frequency lower than 60Hz and are seeing the beat of the sampling rate and the frequency of the pickup.
Put a delay(20 ) after your sample even if you have other delays in their and watch that cycle period you are seeing change. This is because it is not real, it is an artifact.