I'm working on a little synthesizer project, and for some of the controls I'd like to use a photocell/photoresistor input. I've got it connected right now with the photoresistor across +5V and analog input 0, and another 10K pulldown resistor from pin 0 to ground.
Right now I'm getting between 650 for my top range (depending on ambient light), down to about 390 when I've got my finger right over the sensor. But really it's more like 650, then down to 550 when my finger is 1/8" over the sensor, then drops to 390 when I go that last 1/8" and cover the sensor.
I'd like to increase the dynamic range so that it would run smoothly over the 0-1024 range as I move my finger up or down over about an inch.
I thought maybe I could take a green LED and put it right next to the sensor so that it bounces off my finger, which would increase the detectable range, and that helps, a little.
Anyone had some luck doing this? Thanks!
Try to replace the 10K resistor with a 1M potentiometer, then experiment with different settings of the potentiometer to find the best value. 10K sound a little low in my ears.
Thanks for the suggestion. I tried swapping the 10K pot for a 100K and 1M pot, but it didn't increase the dynamic range, it just moved the lowest point around within the 10-bit window.
Here's what I'm playing with currently: instead of moving my finger to create the range, I'm moving an LED up and down over the switch. I still only get a range of about 350, but the accuracy of the input is improved and it's more linear.
Here's some pictures, sorry they're so blurry I took them with my cell phone:
Anyone have a better idea?
So you don't want to increase the sensors actual dynamic range - you just want to convert the present values to a 0-1024 range?
Sounds like a perfect use for the map function.
map(value, fromLow, fromHigh, toLow, toHigh)
No, I want to increase the dynamic range and get a smoother, more linear response over the travel distance. Right now, I've got pretty good linearity by moving the LEDs, but only about 300-400 variation on my input values.
I was thinking maybe if I used the larger 8-10mm photocells they might have a little more gain? Anyone used those?
Well one solution is the use of an external op amp which can be set with gain and offset values to utilize the whole 10 bit range of the analog input.
Another approach would be to change your analogue reference voltage to 1.1v and then use the pull down resistor to move the end point down. That way the voltage swing you have will give you more real range on the A/D readings.
You'll get more "resolution" or steps if you scale in hardware, but either way the sensor isn't going to give you much more distance detection.
Also, the human skin (since you want to use your finger) is mostly red in color. That's why the weather man stands in front of a green or blue screen - so the the colors will be the furthest from the color of skin.
Maybe try a red led. Or even a red led, and a red filter over the sensor.
Just a thought.
Thanks for the ideas, everyone, you've given me a lot of options to try.
I will post back with what ends up working for me...