Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

Close

ATtiny85 - PIR sensor LED strip light control | PCB Design

ATtiny85 - PIR sensor LED strip light control
Version 1 - Last update: Oct 5, 2015

This uses two Amtel ATTiny85 processors. Each '85 reads two PIR motion sensors, and triggers a MOSFET on PWM pin, to fade on / off LEDs for lighting. trim POT on analog pin is used to set the delay for how long the LEDs stay on once triggered. The reason for using two tiny85's instead of a single 168 or 328P, is the fade on/off is a blocking loop, so while the LEDs for one zone are fading off, it cannot turn on the LEDs in the second zone. May seem like a minor thing, but this was to ensure the two zones could operate independently in that regard. I built this to control the lighting on my staircase and in an adjacent hallway. Using 123D Circuits, I want to order the circuit board I designed, to give the project a polished look (no more breadboard tucked away in a hall closet!!) Below is the full code, just upload this to both of the Arduino bootloader enabled ATTiny85 on the board, and you're set.

// MOSFET-driven LED strips, motion controlled from PIR sensors // Designed to run on an Amtel ATTiny85 Micro controller // By Joe Bishop, 2013 -- jbishop129 (at) gmail (dot) com

#define FADESPEED 7 // higher number for slower dimming speed unsigned long LEDTimer; unsigned long DelayTime; int ledPin = 0; // pin for the LED MOSFET Transistor int inputPin1 = 1; // input pin for PIR sensor 1 int inputPin2 = 2; // input pin for PIR sensor 2 int delayPin = A2; // input pin for analog POT, used to calculate delay timer

int PIRState = LOW; // we start, assuming no motion detected int PIR1 = 0; // variable for reading the pin status int PIR2 = 0; // variable for reading the pin status unsigned long DelayCalc; void setup() { pinMode(ledPin, OUTPUT); // declare LED pin as output

pinMode(inputPin1, INPUT); // declare sensor 1 as input pinMode(inputPin2, INPUT); // declare sensor 2 as input pinMode(delayPin, INPUT); // delcare input POT as input }

void loop(){ PIR1 = digitalRead(inputPin1); // read input value for PIR 1 PIR2 = digitalRead(inputPin2); // read input value for PIR 2 DelayCalc = analogRead(delayPin); // read analog value to calculate delay time DelayTime = (DelayCalc * 300) + 5000; // multiply the analog POT value (0-1024) for a sensible delay time, in ms // 300 lets the max time be about 5 minutes. the +5000 ensures if it is turned all // the way down, it wont 'bounce' with a zero value. Minimum delay will always be 5 sec if(PIRState == LOW) { if (PIR1 == HIGH || PIR2 == HIGH) { // check if either of the inputs are HIGH LEDTimer = millis(); // start delay timer for (int i = 0; i = DelayTime && PIRState == HIGH) { for (int i = 255; i > 0; i--) { analogWrite(ledPin, i); // fade LED OFF delay(FADESPEED); } digitalWrite(ledPin, LOW); PIRState = LOW; } } }

Comments disabled