SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
By mungurs
#193746
Hello!

I'm learning arduino on Sparkfun ESP8266 Thing Dev board.
I have connected photoresistor to the Thing using this example -
Image
The code is simple :
Code: Select all
int LDR_Pin = A0;
void setup() {
    Serial.begin(9600);
    Serial.println("LDR Light Sensor | cactus.io");
}
void loop() {
   Serial.println(analogRead(LDR_Pin));
   delay(100);
}
The problem is with the analog reading values - they are fluctuating when photoresistor is reading rooms lights and values looks more like a sinusoidal wave. When the sensor is covered and in the dark, the values are more linear.
Serial plotter screenshot : Image

Any ideas what I'm doing wrong?
By jeff_kotowski
#193858
You do not have a time base on the x-axis, but I'll bet this corresponds to 120Hz. The brightness of most lights changes with 2x the line frequency. Its a power function. Looks like you have an incandescent light bulb. This converts current to heat and then heat to light at roughly 2% efficiency. Since the bulb is heating and cooling at 120Hz you will see 120Hz ripple. But since the bulb stays hot (or cools only a small amount at 120Hz) you get a DC brightness plus some ripple.