I am trying to measure the flickering of led lighting with simple phototransistors and Arduino Nano.
My sensors,
OSRAM Opto Semiconductors SFH 3310
OSRAM Opto Semiconductors LPT 80A
My setup:
The pull up resistors are 10K and 50K(Two 100K in parallel). The black jumper connects GND.
My code:
int lightPin0 = 0; //define a pin for Photo resistor
int lightPin1 = 1; //define a pin for Photo resistor
int K = 600;
int data[600];
void setup()
{
Serial.begin(115200); //Begin serial communcation
}
void loop()
{
int a, b;
int i;
for (i=0; i<K; i=i+1) {
data[i] = analogRead(lightPin1); // or lightPin0
}
Serial.println(""); //Write the value of the photoresistor to the serial monitor.
for (i=0; i<K; i=i+1) {
Serial.print(data[i]);
Serial.print("\t");
}
delay(1000); //short delay for faster response to light.
}
And my result:
I see two problems here.
Both amplitude are very small. What can I do to make it higher? The setup is placed ambient next to my laptop, so no shading is done.
Though the two sensor readings have the same rhythm, I get 6.5 cycles in 600 samples, which would make the frequency of the lights to be 1/(600/15e3/6.5) = 162.5 Hz. However I expect 60 Hz, which is the AC frequency. What may have happened?
What can I do to measure the real pulse width modulation waveform of the led lamps my lecture hall uses?
Use an oscilloscope. You may eventually be able to get an Arduino to measure the signal from the sensors in a crude way, but first you need reliable knowledge of what the signal should look like.
What does the 15e3 value in your calculation represent?
Depending on how led lighting is driven, you might expect to see a 120Hz signal.
You should Google for an explanation of how AC dimming circuits work. They are not as simple as the pwm signal used by an Arduino to dim a led.
Correct me if I'm wrong, but I don't see photo diodes with pull up resistors.
I see photo diodes used in photo-voltaic mode, with load resistors across.
Powered from the REF pin (= dangerous).
Leo..
Thank you Wawa.
The website where i bought these phototransistors states these are transisitors instead of diodes.
FYI the leg is not connected to the REF pin (Lower Left pin #3) on the board, it appears this way because of the angle of my photo.
Is the 5V on board intended to drive a load? Eventually I would need it to drive a HC-06 and a sensor.
Yes, you can draw a few hundred mA from the 5volt pin on USB supply.
A Nano however runs on 4.6volt on USB supply.
This is not a problem for a HC-06 module with onboard 3.3volt regulation.
Don't know what "a sensor" is.
Record millis() at the start and end of your sampling for loop.
Subtract the two values to know the exact sampling time.
I doubt you can measure LED lighting like this.
Most have buildin DC/DC converters that work on several hundred kHz.
You might be able to see the PWM frequency of a dimmed LED, but that is unlikely related to mains frequency.
Leo..
There are many ways to drive led lighting from mains AC. I have some led "filament" bulbs at home which have no visible driver circuit. I assume there are a large number of UV led chips connected in series inside the phosphor "filaments". These have a noticeable 50Hz flicker (it seems too noticeable to be 100Hz) so I guess they only light on half the AC cycle. The phosphor compound may continue to glow when the LEDs are not energised, but not enough to remove the flickering.
You probably won't be achieving the 15K samples per second, as mentioned above, because of the overheads of the Arduino language. I would use micros() function to measure how long your 600 samples actually take and calculate the achieved sample rate from that.
PaulRB:
There are many ways to drive led lighting from mains AC. I have some led "filament" bulbs at home which have no visible driver circuit. I assume there are a large number of UV led chips connected in series inside the phosphor "filaments". These have a noticeable 50Hz flicker (it seems too noticeable to be 100Hz) so I guess they only light on half the AC cycle. The phosphor compound may continue to glow when the LEDs are not energised, but not enough to remove the flickering.
You probably won't be achieving the 15K samples per second, as mentioned above, because of the overheads of the Arduino language. I would use micros() function to measure how long your 600 samples actually take and calculate the achieved sample rate from that.
my objective is not to remove flickering.
lcd monitors use PWM to dim the screen. the waveform of the pwm is what i want to measure. some websites say the frequency ranges from hundreds to kilos. i reckon 8.8ksps is good enough to sample that.
lighting_expert_87:
Indeed. I added millis and this is what I get.
It averages to 113us a sample. that's 8.8Ksps. what's wrong here?
That makes the led lighting modulation to be at 1/(600/8.8e3/6.5) = 95.3333 Hz.
Still a number I can't explain.
I make it 100, since I measured the graph more carefully - 6.5 cycles takes about 570
samples, not 600.
That implies your mains is 50Hz, not 60Hz and you are getting a flash for each half cycle.
The low signal to noise ratio is due to the flickering being smoothed in the LED lamps with
capacitors. Try fluorescent strip light for a more deep flicker.
[ of course if you really are in a 60Hz mains territory, I can't explain that!! ]
The lights in rooms/halls (those sources which may flicker, ie fluorescent lamps) are usually connected to different mains phases (each lamp or a group of lamps is connected to a different phase, you have got 3 phases). That is a common practice to reduce flickering since ever. Thus you may measure 60hz/120Hz/180Hz (or 50/100/150Hz in 50hz land) or something like that..
Your photodiode is measuring the AM envelope consisting of several sources wired to different phases.
A friend of mind is a maintenance supervisor whose company is in the process of converting the factory to LED lighting. The large "high bay" LED lighting is powered by a (controllable) constant current with minimal ripple.
I built a LED installation for my home. After some research I ended up with a PWM frequency of 156 HZ.
My reasons were:
I didn't want it to be any multiple of 60Hz for fear of beat frequency flickering.
The higher the frequency above which the human eye can detect flicker the more losses in the switch. Yes I know MOSFETs can switch very fast, however at very fast speeds EMI is also created. My design method at home is to slow the MOSFET switching time (not the PWM frequency) until a cheap AM radio near by doesn't pick up any interference.
So there may not be any flicker to measure, and if there is, it is likely to be above 100Hz but not too much higher.
Regarding sensitivity,
you might amplify the signal and filter out any 60Hz.
If this is a truly manual measurement, Perhaps you could use a comparator with a variable threshold (good old pot). Measure the output with a capture and compare timer.
I understand that the sum of the numerous lights on the ceiling would add on and even out the PWM in brightness. Single light source like LCD would not have such issue when shading is applied.
My objective is to measure LCD screens because my eyes are sensitive to that pwm and I am making a DIY to measure that and use when I shop for another laptop. And enrich my hardware skill too because I am a semiconductor engineer. I haven't seen any affordable & portable equipment on the market yet.
So far I managed to make arduino nano, ADC, sd card, 2.8" lcd screen preview, battery working. All I lack is the sensing hardware and I don't have proper equipment.
Any suggestion on the type of sensors is welcome. I have seen people measuring that in the lab, for example,