SMART BUILDING FEATURE - Visual Indicator Motion Sensor Array

Hi guys,

I was wondering how to get more than one motion sensor wired into a circuit and when motion is detected by each sensor, it relates to a specific LED lighting up?

I have used the motion sensor tutorial I have found on the Arduino forums and it works with one sensor and lights up one LED attached to it.....when however I put two motion sensors in and 2 LED's....the same initial motion sensor and LED light up but the other do not. I was wondering how someone would go wiring the circuit for 2 motion sensors and 2 LED's?

The 2 LED's are connected to the Digital pins as outputs and the motion sensors are also connected to 2 digital pins as inputs, however I cannot seemt to get power to the other LED and MOTION SENSOR I add. I am wondering is it the Arduino not able to give enough power from the USB cable I am using?

I am pretty sure I can figure out the code once I get the wiring sorted. I am going to use this simple project for security applications in buildings for security guards as an example where when motion is detected in a room, a box containing the arduino and LED's will go off behind a perspex screen and light up red to indicate movement.

Just underneath the Perspex screen there will be a white piece of paper and on the paper there will be the layout of the floor the guard is monitoring. Where there is a motion sensor in each room, on the diagram, there will be an LED behind it to light up that room indicating precisely where the movement is coming from.

I was also wondering how long can the wires be to each motion sensor before I need to boost the voltage or increase the power?

Any help or advice would be greatly appreciated.

Henry

You don't post your code, showing how you read the motion sensors, so it is not possible to help you there.

As to wire lengths, you need good ol' Ohm's law, E = IR (voltage = current time resistance). As your wire gets longer, it contains more resistance. If your sensor uses only a very small current, you won't have much voltage drop. If you do have too much voltage drop, use a larger gauge of wire, which decreases the resistance per foot.

The term 'motion sensor' is very loose. Do you mean a PIR motion sensor? If so, you could do something like this:

const int led1 = 2;//   change these to the pins you want
const int led2 = 3;
const int pir1 = 4;
const int pir2 = 5;


void setup(){
  
  pinMode(led1, OUTPUT);  // declare leds as outputs
  pinMode(led2, OUTPUT);  
  
  pinMode(pir1, INPUT);  // declare sensors as inputs
  pinMode(pir2, INPUT);
  
  digitalWrite(led1, LOW); // turn leds off
  digitalWrite(led2, LOW);
  
  digitalWrite(pir1, LOW);  // disable input pullups
  digitalWrite(pir2, LOW);
  
}


void loop(){
  
  if(digitalRead(pir1) == 1)  // if pir1 is activated
    digitalWrite(led1, HIGH);  // turn led1 on
  else 
    digitalWrite(led2, LOW);  //otherwise, turn led1 off
  
  
  if(digitalRead(pir2) == 1) // if pir2 is activated
    digitalWrite(led2, HIGH); // turn led2 on 
  else 
    digitalWrite(led2, LOW);  //otherwise, turn led2 off
}

jrdoner:
You don't post your code, showing how you read the motion sensors, so it is not possible to help you there.

As to wire lengths, you need good ol' Ohm's law, E = IR (voltage = current time resistance). As your wire gets longer, it contains more resistance. If your sensor uses only a very small current, you won't have much voltage drop. If you do have too much voltage drop, use a larger gauge of wire, which decreases the resistance per foot.

Hi sorry still kinda new to this here is the code I got called PIRsense from this arduino website at Arduino Playground - HomePage. I used it to read motion from the serial port into a program I was making in C++ in Visual Studio to turn pictures from red to green but it was quite complicated the loop so I opted to make a physical version instead. Here is the code I used, when I added a PIR sensor I assigned it to a PIN and copied to them in each section to match the new PIN name etc. I did the same with the LED. However only the first LED and motion sensor I hooked up was working and cannot understand why:

/* 
 * //////////////////////////////////////////////////
 * //making sense of the Parallax PIR sensor's output
 * //////////////////////////////////////////////////
 *
 * Switches a LED according to the state of the sensors output pin.
 * Determines the beginning and end of continuous motion sequences.
 *
 * @author: Kristian Gohlke / krigoo (_) gmail (_) com / http://krx.at
 * @date:   3. September 2006 
 *
 * kr1 (cleft) 2006 
 * released under a creative commons "Attribution-NonCommercial-ShareAlike 2.0" license
 * http://creativecommons.org/licenses/by-nc-sa/2.0/de/
 *
 *
 * The Parallax PIR Sensor is an easy to use digital infrared motion sensor module. 
 * (http://www.parallax.com/detail.asp?product_id=555-28027)
 *
 * The sensor's output pin goes to HIGH if motion is present.
 * However, even if motion is present it goes to LOW from time to time, 
 * which might give the impression no motion is present. 
 * This program deals with this issue by ignoring LOW-phases shorter than a given time, 
 * assuming continuous motion is present during these phases.
 *  
 */

/////////////////////////////
//VARS
//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 30;        

//the time when the sensor outputs a low impulse
long unsigned int lowIn;         

//the amount of milliseconds the sensor has to be low 
//before we assume all motion has stopped
long unsigned int pause = 5000;  

boolean lockLow = true;
boolean takeLowTime;  

int pirPin = 3;    //the digital pin connected to the PIR sensor's output
int ledPin = 13;


/////////////////////////////
//SETUP
void setup(){
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(pirPin, LOW);

  //give the sensor some time to calibrate
  Serial.print("calibrating sensor ");
    for(int i = 0; i < calibrationTime; i++){
      Serial.print(".");
      delay(1000);
      }
    Serial.println(" done");
    Serial.println("SENSOR ACTIVE");
    delay(50);
  }

////////////////////////////
//LOOP
void loop(){

     if(digitalRead(pirPin) == HIGH){
       digitalWrite(ledPin, HIGH);   //the led visualizes the sensors output pin state
       if(lockLow){  
         //makes sure we wait for a transition to LOW before any further output is made:
         lockLow = false;            
         Serial.println("---");
         Serial.print("motion detected at ");
         Serial.print(millis()/1000);
         Serial.println(" sec"); 
         delay(50);
         }         
         takeLowTime = true;
       }

     if(digitalRead(pirPin) == LOW){       
       digitalWrite(ledPin, LOW);  //the led visualizes the sensors output pin state

       if(takeLowTime){
        lowIn = millis();          //save the time of the transition from high to LOW
        takeLowTime = false;       //make sure this is only done at the start of a LOW phase
        }
       //if the sensor is low for more than the given pause, 
       //we assume that no more motion is going to happen
       if(!lockLow && millis() - lowIn > pause){  
           //makes sure this block of code is only executed again after 
           //a new motion sequence has been detected
           lockLow = true;                        
           Serial.print("motion ended at ");      //output
           Serial.print((millis() - pause)/1000);
           Serial.println(" sec");
           delay(50);
           }
       }
  }

I do like Washburns very simplified version of this kind of system which was what I was going for in the code so thanks very much I will give it a try and let you know tomorrow if I can get it working or not.

I remember Ohms law in school but am having trouble applying it to my circuit as I am confused about how much resistance each component has, how much current it needs and how it should be wired etc. Here is an image of the components I have to make this work:

Three 220 ohm resistors with 5% tolerance (For the LEDs)
3 PIR Motion Sensors
3 LED's
Arduino Uno

I was wondering how these would be wired together all 3 motions sensors and 3 corresponding LEDs to make the circuit complete? If I can build the casing and unit from Perspex and wood etc and get it working I will post the project on here for all to try and enjoy if I can do it. Am just heading to bed and will try wiring it up tomorrow and testing the code thanks guys.

Henry

CWashburn:
The term 'motion sensor' is very loose. Do you mean a PIR motion sensor? If so, you could do something like this:

const int led1 = 2;//   change these to the pins you want

const int led2 = 3;
const int pir1 = 4;
const int pir2 = 5;

void setup(){
 
 pinMode(led1, OUTPUT);  // declare leds as outputs
 pinMode(led2, OUTPUT);  
 
 pinMode(pir1, INPUT);  // declare sensors as inputs
 pinMode(pir2, INPUT);
 
 digitalWrite(led1, LOW); // turn leds off
 digitalWrite(led2, LOW);
 
 digitalWrite(pir1, LOW);  // disable input pullups
 digitalWrite(pir2, LOW);
 
}

void loop(){
 
 if(digitalRead(pir1) == 1)  // if pir1 is activated
   digitalWrite(led1, HIGH);  // turn led1 on
 else
   digitalWrite(led2, LOW);  //otherwise, turn led1 off
 
 
 if(digitalRead(pir2) == 1) // if pir2 is activated
   digitalWrite(led2, HIGH); // turn led2 on
 else
   digitalWrite(led2, LOW);  //otherwise, turn led2 off
}

This is definitely the kinda simple code I am looking for Washburn thanks. Just hope to get the wiring sorted so I can try it tomorrow as I have no idea about electronic circuits to be honest.

Now that I think about it, if all you want is to turn on some LEDs, you could probably wire the LEDs directly to the PIR sensor's output pins, eliminating the Arduino. All that my code does is copy an input and assign the value to an output. You can check on your sensor module, but I believe many PIR sensor modules are made with the LM324 chip which is rated for 20mA output current (although I would go much lower, maybe 5 - 10mA).

The cheap PIR sensors I've seen already have a 1k or 1k5 current limiting resistor in series with the output.
So you can connect a LED directly between out and ground of the sensor.
Leave the sensitivity pot in the middle.
With the other pot, you can set "on" time between a few seconds and ~7 minutes.
Leo..

CWashburn:
Now that I think about it, if all you want is to turn on some LEDs, you could probably wire the LEDs directly to the PIR sensor's output pins, eliminating the Arduino. All that my code does is copy an input and assign the value to an output. You can check on your sensor module, but I believe many PIR sensor modules are made with the LM324 chip which is rated for 20mA output current (although I would go much lower, maybe 5 - 10mA).

Wawa:
The cheap PIR sensors I've seen already have a 1k or 1k5 current limiting resistor in series with the output.
So you can connect a LED directly between out and ground of the sensor.
Leave the sensitivity pot in the middle.
With the other pot, you can set "on" time between a few seconds and ~7 minutes.
Leo..

I thinkI am losing the rag with this gadget lol I have tried wiring and rewiring uploading again and again different bits of code but I think I am wiring it all wrong or something. I have this circuit diagram attached and I am unsure if I am wiring it correctly as nothing is happening at all with the sensor or the light using Washburns code from above but I definitely think its something I am doing wrong.

Here is the circuit....any ideas? Excuse the terrible diagram I have no idea about electronics at all:

thanks

henry

lol have given up on the project onto something bit more easier I think :slight_smile:

sorry to hear that you gave up so soon on this.

in my experience, many PIR outputs are HIGH in the 'normal' or 'no motion detected' condition.

I would recommend you look at the BUTTON sketch. pick one PIR and test it.
if it goes ON when you move movement and OFF with no movement, then you have everything set correct and are ready to move on to the next thing.

the alternative is to use serial and display the value on your serial monitor pop-up window.

one of the beautiful things about the Arduino is that it can invert a value with simplicity.

.

Hi guys,

I had given up on this topic way back in August as you can remember and I was correct in my wiring diagram that I had drawn but wrong in my implementation of the actual circuit when connecting it altogether.

I was sitting in work a few days ago, not even talking about anything to do with Arduino or electronics, when the idea came to me about how the circuit should be wired up, went home, tried it and voila it worked! I have 3 motion sensors turning on 3 separate LED's independently which for a beginner, I am very proud of :slight_smile:

I will post a video and some images over the next few days to show it working. I will make a small make shift display panel as a prototype before moving onto trying to make the product without the breadboard and actually solder parts together for it.

I thought that I could also, when I get this first part out of the road, add sensors that activate different coloured LED's on the display panel for the same room. These other sensors could monitor temperature and gas emissions and if they fall between certain values, set off the LED in the control panel or a buzzer for gas indicating their may be a fire or gas leak somewhere and will be able to pinpoint which room it is actually in.

For the minute the RED led's will indicate movement. In the future designs Blue for temperature going over a certain limit say 35 degrees for example and Yellow for gas readings being detected.

thanks

henry