I have a related question. What if you wanted to sense the frequency that a light was turning on and off? (nothing more than 60hz)
I have a related question. What if you wanted to sense the frequency that a light was turning on and off? (nothing more than 60hz)
You would want a sensor with a much faster response time than a CDS
photocell. Check here http://www.taosinc.com/index.asp
They have a lot of nifty optical gadgets.
makezine.com had a post about using a solar cell. Do you think that might work?
You can find the instructable here:
http://www.instructables.com/id/E5KC...FO02Y?ALLSTEPS
Hi,
I do this all the time. I have found that using adcin is best. Use the adc pins of your pic like the PIC 18F452.
TRISA = %11111111 'Set PORTA to all input
ADCON1 = %10000010 'Set PORTA analog and right justify result
adcin 1, photoVar 'read analog input of the photocell wired as a voltage divider input on pin 3 of Pic 18F452: result is stored in variable "photoVar"
use the result stored in the variable "photoVar" to do something
From what I understand, from the literature, adcin is a much better choice if your PIC has built-in analog to digital conversion such as the RA pins of Pic 18F452
This is how you would wire your photocell:
Scroll down the page and see the photocell, which is wired as a voltage divider.
http://www.phidgetsusa.com/tutorials...ue_sensors.asp
Oh, I also just wanted to say that using a solar cell would be cool but solar cells are more costly than photocells. If you wanted to store energy I would say use a solar cell, but from what I understand about your application a photocell, which costs maybe $1.00 at the most would be very effective.
The Hot wire to +5
the green to the pic pin
the black to ground
I make MIDI controllers that use a photocell to detect changes in light and dark, and in response produce MIDI notes. MIDI notes (messages) need to be very fast, the photocell and ADCIN are very fast. It's all you need for your application.
If you need help let me know.
Last edited by TonyA; - 24th January 2007 at 23:38.
Bruce felt that a photocell would be to slow to measure frequency. That is why I asked about a solar cell.
Yeah, I see. I glanced over what Jessey said about measuring the difference between dawn and dusk... I know the photocell with adcin would work great for measuring changes in light, but dawn and dusk, or measuring the frequency of light. I don't know if the photocell could do that.
(Sorry for any confusion caused by my posts in this thread, I was replying to Jessey's original post about using a photocell. I didn't read the replies posted by others.)
Last edited by TonyA; - 25th January 2007 at 10:25.
Hello Bruce,
Thanks for the info, I was really getting frustrated with the pot command and finding a proper value of a photo resistor to use.I found that the adc works great with just about any photo resistor value.
Also thanks TonyA and your right that the adc does work best for this type of application and it is very fast too, I'm pleased to see. I'm also using an 18f452 (great micro) but not with the ADCin command and it works great.
Once again thanks everyone for getting me kick started on this.Code:Check_The_Light_Level: adcon1=%00001110 ' AN0 analog, all other pins digital ADCON0 = $41 ' Set A/D to Fosc/8, Channel 0, On Pauseus 50 ' Wait for channel to setup ADCON0.2 = 1 ' Start conversion Pauseus 50 ' Wait for conversion Lite_Level = ADRESH ADCON1 = 7 ' shut off (Disable) ADC RETURN
Thanks
jessey
Bookmarks