Instructables

Trying to get help with arduino photocell sketch...

Not too familiarl with writing arduino sketches but I'd like to connect a photocell to arduino so that when  a shadow is casted upon a photocell nothing happens but when exposed to light again it triggers an action. Any help would be much appreciated. I've looked for any project like this but have been unable to find anything. 

Photocells
Just a quick post about hooking up a photocell to your arduino. This setup should work for other variable resistors (flex, force, etc).

Materials you’ll need:
Arduino Duemilanove
Photocell
10K ohm resistor (brown, black, orange)

Arduino Sketch

01 /*
02 * Photocell Reading
03 * -----------------
04 *
05 * Read an analog value from a photocell (variable resistor)
06 * connected to analog pin 0.
07 *
08 * Created January 2010
09 * Matt Wiechec
10 *
11 */
12
13 int photocellPin = 0; // select the input pin for the photocell
14 int photocellVal; // variable to store the analog valie from the cell
15
16 void setup(void) {
17 Serial.begin(9600); // for debugging via the Serial Monitor
18 }
19
20 void loop(void) {
21 photocellVal = analogRead(photocellPin);
22
23 Serial.print("Photocell Val: ");
24 Serial.println(photocellVal); // the raw analog reading
25
26 delay(100);
27 }
arduino-photocell-01.jpgarduino-photocell-02.jpg
purpulhaze (author) 3 years ago
Thanks alot for the help but I decided to use picaxe logicator as it is pretty easier to use without knowing much about coding.
Avad has once again stolen someone else's work and presented it as his own.
The original, and helpful link is here
http://mattwiechec.wordpress.com/

The link doesn't help with the code you need though to do what you want.
Connect the cell to one of the analogue inputs.

Set a variable "arm= false"

Repeat
Read the input
If Input < dark level, then Arm=true;
Until (arm=true) ;

Repeat
Read input
Until input > trigger.

{do your event}
+1

to add to the pseudocode:

the first repeat loop waits until its gone dark, and only once it's dark can the second loop begin waiting for a light transition.
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!