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.
Bookmarks