Over Kill Project

Hi Everyone

Ive spent a lot of time reading the forum this year and im now decided to ask for some guidance.
My quest is a simple one in my head but im a man and like a challenge.

Lighting the side of the house when poeple walk to the rear garden (my partner runs a business in a log cabin in the garden)

Easy i hear you cry, of course it is PIR on 30 seconds one either end … done

Thats how it started as i said Im a man , lets make it so when someone comes round the lights fade up :slight_smile: (led 10w x 4) and when they exit the other end they fade off and then reverse it as they go out, then add the back door in so when you come out the door the light come on as well and switch off as you leave either way

Sensor PIR - hacked to reset in 2sec and resticted beams sorted
LED sorted with electronics

My next quest and the reason for this over length entry is the programming of my adruino. Ive been playing with room counter, distence sensor codes all sort of video on switch case etc and I cant believe im the first person who as wanted to do this type of project. I am not going to enter any code because I have so main variation and none work 50% of what I want.

So could anyone point me in the right direction for coding for this project as the nights will soon be coming in again in the UK :slight_smile: I have attached a diagram of my hoped layout

Hi,
Welcome to the forum.
aea2e0aed6a2c9a9a9b320aa60b16f20b7b1e1e0.jpg
Wouldn’t sensor 2 also be an entry point for anyone returning from the garden to the front, or don’t they ever come back?

I would make the lights come ON when ANY PIR detects and the timer is reset each time ANY PIR detects, after that the lights fade off after 30Seconds, unless reset.
So anyone walking from anywhere along the side will activate the PIR and keep the lights on.

Tom… :slight_smile:

Are you wanting to control the LED lights individually or all of them at the same time?

Tom

You are correct sensor 2 is an entry point lol not every good for business if thay never came out

I agree its the easy option 30sec fade up fade down, think because I couldnt sort out the progamming its become an obsection, that its possiable just that my know how isnt upto it

Riva

No im just going to switch them all on, altho at one piont it was going to light up as you walked along with a couple of distance sensor and 8 LEDs :slight_smile:

photo100:
I cant believe im the first person who as wanted to do this type of project.

you would be correct

Easy enough to reset your count down timers when a PIR is retriggered. Could throw in a Photo-Resistor to disable system when it is day light. My PIR's are good for more than 20 feet.

Nasa

Thanks, yes the Photo-Resistor was going to be thrown in that was the easy bit but hadnt done a countdown timer , how would you break the countdown if another sensor is triggered?

Dave

Ive spent weeks looking on youtube and hadnt seen any of the vids you listed

Thanks to both of you

If you were a man you wouldn’t be asking for direction :smiley:

Sorry couldn’t help myself. to make up for that here is some code that gives a nice linear(appearing) fade for your lights.Written by our own Grumpy Mike

/*
  Change brightness of LED linearly to Human eye
  32 step brightness using 8 bit PWM of Arduino
  brightness step 24 should be twice bright than step 12 to your eye.
  reply #11 by Grumpy Mike: http://forum.arduino.cc/index.php?topic=147818.0
*/


#include <avr/pgmspace.h>
#define CIELPWM(a) (pgm_read_word_near(CIEL8 + a)) // CIE Lightness lookup table function

/*
  5 bit CIE Lightness to 8 bit PWM conversion
  L* = 116(Y/Yn)^1/3 - 16 , Y/Yn > 0.008856
  L* = 903.3(Y/Yn), Y/Yn <= 0.008856
*/

const uint8_t CIEL8[] PROGMEM = {
  0,    1,    2,    3,    4,    5,    7,    9,    12,
  15,    18,    22,    27,    32,    38,    44,    51,    58,
  67,    76,    86,    96,    108,    120,    134,    148,    163,
  180,    197,    216,    235,    255
};

int brightness = 0;             // initial brightness of LED
int fadeAmount = 1;
int led1Pin = 9;

unsigned long startTime = 0;    // timing variables
const long interval = 100;


void setup()  {  
  pinMode(led1Pin, OUTPUT);     // declare pin 9 to be an output:
}

void loop()  {
  unsigned long currentTime = millis();
  if (currentTime - startTime >= interval)
  {
    startTime += interval;                         // increment timing sequence
    analogWrite(led1Pin, CIELPWM(brightness));     // set the brightness of pin 9:, 0-31, 5 bit steps of brightness
    brightness += fadeAmount;                      // change the brightness for next time through the loop:
    if (brightness == 0 || brightness == 31)       // reverse the direction of the fading at the ends of the fade:
    {
      fadeAmount = -fadeAmount ;
    }
  }
}

In order to determine if someone is coming or going, you will need 2 pir sensors at each entry point and the order in which they are triggered can determine direction.

No countdown would then be needed but you would need to count how many have entered the space vs how many exited. This wouldn’t account for if 2 people crossed in front of the sensors at the same time.

Hutkikz

I did find a couple of room counters that used 2 sensors on an entry count in and count out , I thought that if I was to use a PIR (hacked to reset in 2s) that it would trigger in and then trigger out. I know that if I just set them to a time (30s etc) they will work fine but after 4 month of trying to work it out thought I would give the forum a try but im beginning to think give up and move on to the next project and come back to it at a later date.

Thats a very nice fade, work really well, thank you and Grumpy Mike

photo100:
Hutkikz

I did find a couple of room counters that used 2 sensors on an entry count in and count out , I thought that if I was to use a PIR (hacked to reset in 2s) that it would trigger in and then trigger out. I know that if I just set them to a time (30s etc) they will work fine but after 4 month of trying to work it out thought I would give the forum a try but im beginning to think give up and move on to the next project and come back to it at a later date.

Thats a very nice fade, work really well, thank you and Grumpy Mike

as I understand from your first post, you have the motion sensor part sorted ?

looking at the rising edge of the signal, you start a counter.
for each of the next 1/10 seconds, you begin to fade up the lights from the motion sensor that tripped first.
each light fade up starting 1/10 second after the last.
fade up over 2-3 seconds

as a way of determining the length of time the lights would stay on, I would walk up, back, then up again. that would cover the average ON time, longer is fine.

you have 3 states, fade up, ON, fade down.
if you are ON, and the sensor trips again, it would re-set the timer as to when the fade down was to occur.

on the surface, it seems simple enough.

where are you having problems ?

Dave I agree 100% with

"you have 3 states, fade up, ON, fade down.
if you are ON, and the sensor trips again, it would re-set the timer as to when the fade down was to occur.

on the surface, it seems simple enough."

PIR 1 triggered

Leds fade on

Pir 2 or sensor 3 triggered (this is were i seem to have the problem switching the leds off, using any of the sensors as the first trigger and any to switch off)

Leds fade down

Im back trying to figure out the best way to program this sytem, i want to do…

So far im attempting a FSM attached pic , the blue arrow are the problem, I maybe be answering my own question by saying I want to interrupt the timer in the wait state.

The wait state is 60sec but if any of the PIR go high while the led is on i would like it (LED) to switch off

I have this sketch which I have been working on that does not have a wait state or a sort of default which if the LED is high for x amount of time will switch off.

I have never posted a code before so please be gentle :slight_smile:

// FSM house lights v8

const int WaitForTrigger = 0;
const int Pir1Trigger = 1;
const int Pir2Trigger = 2;
const int LedStateHigh = 3;
const int LedStateLow = 4;
const int LedON = 5;
const int LedOFF = 6;
const int LedWAIT = 7; 


// Pin numbers
const int Pir1Pin = 7;
const int Pir2Pin = 6;
const int LedPin = 9;

void setup()
{
     pinMode(LedPin, OUTPUT);
     Serial.begin(115200);
}
 
void loop()
{

    static int state = WaitForTrigger ;
 
    // To store the current time  for delays
   static unsigned long wait;


 switch (state)
  {
 
    case WaitForTrigger:

                  //  digitalWrite( LedPin, LOW); test to see if LedState is working
 
                    state = Pir1Trigger;
               
                    break;
 
    case Pir1Trigger:

                  if ( digitalRead (Pir1Pin) == HIGH) {
                 
 // Serial.print("PIR 1 :");
                    state = LedStateHigh;
                    }
                    else {
                     state = Pir2Trigger; 
                      }
                    break;
 
    case Pir2Trigger:

             if ( digitalRead (Pir2Pin) == HIGH) {
           
 // Serial.print("PIR 2 :");
                   state = LedStateHigh;
                   }  
                   else {
                     state = WaitForTrigger; 
                    }
                  break;
 
    case LedStateHigh: // reading the LED pin to change the state
                
                 if ( digitalRead (LedPin) == HIGH) {
// Serial.println("Led state high: ");                  
                   state = LedOFF;
                    }
                    else {
                    state = LedStateLow;  
                    }
                   break;
 
    case LedStateLow:
 
                 if ( digitalRead (LedPin) == LOW) {
//Serial.println("Led state low: "); 
                   state = LedON;
                    }
            
                  break;

    case LedON:
// Serial.println("Led ON: ");
          
              for (int i=0; i<255; i++){
              analogWrite(LedPin, i);
              delay (5); 
               } // end for
              analogWrite(LedPin, 255);
                
              wait = millis();  // Remember the current time
     
              state = LedWAIT;
     
              break;

    case LedOFF:
// Serial.println("Led OFF: ");
            
             for (int x=255; x>0; x--){
             analogWrite(LedPin, x);
             delay (5);  
             } // for end off
             digitalWrite(LedPin,0); 
       
            wait = millis();  // Remember the current time
       
            state = LedWAIT;
       
            break;
 
    case LedWAIT: //wait time is sort of a debounce for PIRs
// Serial.println("3sec wait: ");
            
             if (millis() > wait + 3000)
              {
                state = WaitForTrigger;
              }
         
              break;           
 
  } // end of switch
 
} // end of loop

FSM.jpg

If I read your sketch correct, you only have one pin for the LED's ?
You are not trying to have the one near the front come one and ramp up
then, a second later have the second come on and ramp up
then have the thrid.. then the last.....

just all fade up at once ?

Dave
Thank you for your reply, at the moment you are correct as ive also change the design of the lights slightly and will now be using 4 10w leds down the alley way.

My program is very basic and works just but i would like it to be more reliable.
Once im happy with the triggering I will look to get the leds lighting to ramp up as you suggest and also adding a light sensor.

The other bit im would like to add is if a sort of backup if the led is on for 60sec and not triggered off, to switch off automaticly

The project is now finished and would like to thank Dave-in-nj for pointing me to speedy signals stair project

Take a look at this and be the first