Go Down

Topic: Light Sensor Response Time and Choosing a Light Sensor (Read 4234 times) previous topic - next topic


It's not sampling at 20Hz because you have 50ms of delay PLUS the processing time of all the other stuff you are doing. That time will be small, but the drift from 20Hz is probably more than 10%.

If you must do things on a good time schedule that doesn't drift and is accurate to better than a millisecond, use the Blink-Without-Delay technique. It's in your Examples folder, under 02Digital.

If you need timing to the microsecond level of precision, then a hardware timer can be used, but that's an advanced topic.
"The problem is in the code you didn't post."


Feb 02, 2017, 06:09 am Last Edit: Feb 02, 2017, 06:27 am by GoForSmoke
Thank you for the response! Unfortunately, even with the maximum and minimum, the problem persists.
May I see the code you use? It should be reading at least 5Khz. Isn't your signal only 100Hz? 50x slower? If you do 8-bit analog reads instead of 10-bit, you can run a lot faster.

Also IIRC with AVR ADC you can adjust the sensitivity by providing a reference voltage and again IIRC there's an on-chip magnifier but that may not be all AVR's. I'll haveta look.

328P datasheet
The ADC converts an analog input voltage to a 10-bit digital value through successive approximation. The minimum
value represents GND and the maximum value represents the voltage on the AREF pin minus 1 LSB.
Optionally, AVCC or an internal 1.1V reference voltage may be connected to the AREF pin by writing to the REFSn
bits in the ADMUX Register. The internal voltage reference may thus be decoupled by an external capacitor at the
AREF pin to improve noise immunity.
If you still read 200, the internal 1.1V will make that near 900.

One other thing. Roll up a strip of paper to make a tube 2 or 3 cm long, adjust to fit the phototransistor bulb and tape. Put the detector into the tube and point it right at the led. Now the background light is less by far. The longer the tube, the narrower the view. It is the "beam", not the light. If you do this with the lights it will make it harder get both pointing exact than just one first then turn the other. On the detector, that is how to IR trip wire even in daytime. Blocked is blocked, illuminate a wall with IR and point "beam detectors" at it. 

1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.


Go Up