Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This little project makes an ATtiny tell you when it is dark or bright. This project is an excellent introduction to the capabilities of the ATtiny85 chip.
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 ( )
With help from
You can buy all the parts at
Instructions at:
Aug 10, 2014
int photo = 1; //Photo is an analog pin
int red = 1; //Red is a digital pin
int green = 0;
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);
//This is the decision part
if(light >= threshold) {
digitalWrite(green, HIGH);
digitalWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(red, HIGH);
delay(1000); //Wait one second before checking levels again
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.