/* ATtiny Dark Detector This program turns on a green light when it is bright. and a red light when it is dark. Pin OUT (only shows pins used) --[[()]]-- 5V --[[[]]]-- A1 --[[[]]]-- D1 GND --[[[]]]-- D0 Hook Up --[[()]]-- 5V --- Photocell (leg one) --[[[]]]--------- Photocell (leg two)----{10KΩ}--- GND --[[[]]]----{330Ω}--- RED LED --- GND GND --[[[]]]----{330Ω}--- GREEN LED --- GND Created by Peter Flickinger ( http://www.peterfoxflick.com ) With help from http://highlowtech.org/?p=1695 You can buy all the parts at https://www.sparkfun.com/wish_lists/92986 Aug 10, 2014 */ //pins int photo = 1; //Photo is an analog pin int red = 1; //Red is a digital pin int green = 0; //variables int threshold = 600; //This is the light level that determins wheather it is bright or dark void setup() { pinMode(red, OUTPUT); pinMode(green, OUTPUT); } void loop() { int light = analogRead(photo); //This chunk adds a blink to the led to let you know its working and not stuck digitalWrite(red, LOW); digitalWrite(green, LOW); delay(100); //This is the decision part if(light >= threshold) { digitalWrite(green, HIGH); digitalWrite(red, LOW); } else{ digitalWrite(green, LOW); digitalWrite(red, HIGH); } delay(1000); //Wait one second before checking levels again }