NEWBIE - Creating a Motion Sensor Array and Creating GUI to show output in rooms

Hi guys,

I just bought my arduino UNO a few weeks ago and am starting to get bits and bobs together for a project I have in mind. I bought the Arduino Project book for dummies as well to help me if I am stuck as a reference guide and have been reading all the projects in it comprising of lots of different sensors to spark my imagination.

What I want to do is: Create a motion sensor array that when motion is detected, send a message to a software program or to a local webpage hosted on a computer (whatever is easier to design and execute) which notifes us that there is motion detected in each room.

For an example of what I would like it to do, please check the attached jpeg. Say we have 3 square rooms all joined together and a door straight through te middle of each leading into the other. The person walks from ROOM 1 TO ROOM2. When the person starts moving, the software has a diagram of 3 squares on screen with room names, which change to red when motion is detected. When the person enters ROOM 2, the sensor in ROOM 1 then will display no motion detected after say another check after so many seconds say 2 seconds. Same happens again in ROOM 3 when the person walks from ROOM 2 to ROOM 3.

The system I have is to be used in large buildings to help detect motion after hours when the place is closed and any security guards in the lobby who stay overnight ot protect the offices can see any motion in any room in the building or corridors. This can alert them to unauthorized people being in the building after it is closed, where cleaning crews etc may be currently working and also during a fire alarm to detect whether the building has been fully evacuated or not. Receptionists or security personnel will have this graphical user interface showing movements hopefully in the event of a fire alarm, making their way to the fire exit locations, and coming down floor by floor the closest fire evacuation point. Also in large container ships to monitor for pirates who may have boarded unknowningly if the captain of large ships know where his crew currently is and there is abnormal activity or movement detected well below decks etc it could arouse suspicion or raise an alarm much sooner to stop them getting away.

Of course every building is different and the layout for this GUI showing the motion locations will be unique to every building and will be sketched out on paper then converted into birds eye view plans of each floor they are installed in.

I was wondering how I would create this, feeding the sensor data to the PC downstairs and creating the User interface for the software, reading in the sensor values.
Also:

How many sensors can I connect to one arduino? are they only connected motion sensors through the 5 analogue pins or can I connect 13 to the digital pins as I only need to know two conditions, like the binary values it can produce and accept a 1 and 0, similar to motion detected YES or NO?

Lets get my head around this single layout first and then will talk about maybe an arduino for each floor and connecting them together as I dont think one arduino could handle so many connection. Check out my diagram and see what you think.

As I am a newbie I would like to thank you all in advance for your help and look forward to working with and sharing your ideas.

Henry

How many sensors can I connect to one arduino?

One per pin.

are they only connected motion sensors through the 5 analogue pins

There is either motion, or there isn't. They are digital devices.

Break the project into stages. Get the PIR sensors working, first. Then, think about what you would send to the PC to show the status of all n PIR sensors. Think about when you will send data. Every millisecond? Every second? Every minute? Every time there is a change? Some choices make more sense than others.

Then, write an application that can read the serial port, and draw the pretty pictures you want.

Hi Paul's thanks for the advice I think I am getting a little bit too excited and carried away at the thought of creating something I am trying to make it all work at once but its a bit daunting that way :slight_smile:

I have ordered 4 motion sensors off eBay and will take your advice to get them working first and see the values returned. The arduino will be connected to the monitoring PC via USB which acts as a serial port I found out.

I have fundamental experience of c# and c++ so hopefully when it comes to writing some of the code it should be easy to understand.

You have just opened my eyes to when to check for when to send data I am guessing if movement is detected then send data to say its been found in a room changing the green room to red colour, but if movement has not been detected then there has been no change from its original setting so send no data?

Thanks for helping hand sensors should b here in few days or early next week will let you know how I get on and probably advice on reading from serial ports into either c# or c++ program. Thanks again man :slight_smile:

Motion Sensors have arrived and ordered jumper cables off Ebay 40 male to female for £2.24 not bad price.

Bought Breadboard from maplins as well which is a BREADBOARD AD101, one power BUS and 408 connection points. Dimensions 52 * 81 * 9 mm.

Next I was wondering lastly what kind of resistor I need for the motion sensors to protect them? Or do they not require any?

The motion sensor components details are:

Pyro-electric PIR sensor BISS0001
Low-power, static power 65uA
Wide voltage range, DC 5V-20V
Repeatable / not repeatable trigger mode selection
Easy to use, power + - signal output
7 m sensing range
110 degree angle sensor
Operating voltage range of 5-20V DC voltage
65uA quiescent current
High output level 3.3 V / Low 0V
Non-repeatable trigger L trigger / H Repeat Trigger
Board small size 38 * 28mm

I hope the jumper cables simply plug into the arduino and connect to the sensor straight away without any spacing issues at the connector pins never done this before my first projects so will see if I been stupid or not and ordered wrong kinda wires lol

You have just opened my eyes to when to check for when to send data I am guessing if movement is detected then send data to say its been found in a room changing the green room to red colour, but if movement has not been detected then there has been no change from its original setting so send no data?

There will be a state change from no motion to motion, when motion is detected. Some time later, there will be another state change, from motion to no motion, when no motion has been detected for a while. Send data on both state changes.

ah right ok I see, I found a way online to read serial connections to the arduino so hopefully when I get the hardware part of it setup can get some data coming through to the arduino API. Hopefully if I get it working can post it on here for others to share or modify too thanks :).

Could also incorporate smoke sensors etc into the program I want to build buthave several arduinos only having motion sensors connected to it coming into central pc, then another arduino or two all with only smoke sensors feeding into same computer but hats probably long way away, time to get the first step working first :slight_smile:

I think the programming would be easier at both ends if you just send the state of all sensors to the PC everytime. If there are 16 sensors just send a string of 16 1s and 0s separated by commas. The order will identify which room each belongs to. More sophisticated schemes are available but may not be necessary.

Your Arduino should detect changes the instant they happen but there is probably no value in sending the data to the PC more often than, say, once every 5 seconds.

You should think of some means to identify faulty sensors - perhaps send a 2 (instead of 1 or 0).
And also for the PC to detect a failure in the whole Arduino, or the comms link.

...R

Hi Robin, thanks for the advice :slight_smile: I have taken some arduino code available for the motion sensors on the forum from an instructables I found and have taken out the LED pin output reference as I do not have a seperate LED to output to. I know ther is one on the board but when I finished each array I want to encase the arduino in a box so you wont see the internal built in LED.

Okay so here is the code for the one motion sensor that is connected to PIN 3.

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


void setup(){
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  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);
  }
  
  
  void loop(){

     if(digitalRead(pirPin) == HIGH)
     {
         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)
        {       
        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);
           }
       }
  }

You can see the output it gives me in the attached PICTURE for this post. It tells me when motion has been detected, and when it has stopped detecting it.

Now I was wondering if someone could help me get this one sensor to begin with to link to the images at the start of the post so if I drew a box on screen that is green, when motion is detected it turns red. Or I could have when motion is NOT detected it displays the green box as a standalone image, then when motion IS detected, it swaps to the red image in its place.

Any ideas on how to go about this would be greatly appreciated and what program to use or do it in, whether a web page would be best to do it in or make it easier? Let me know thanks in advance.

Henry

whether a web page would be best to do it in or make it easier?

No, a web page would just add several layers of complexity.

You have serial output now, going to the Serial Monitor application. Now, you need to replace the Serial Monitor application with your own application that read from the serial port and draws pretty pictures.

You might want to modify the Arduino code to include the room number, room name, room description, or something that identifies where the motion was observed.

Your application will read the serial data, and turn the appropriate square (based on the data you are not yest sending) the appropriate color (based on whether the motion started or ended, and what time it is now).,

Thanks Paul, am definitely liking the support from this forum a lot :slight_smile: definitely one of most active places I have found for help.

I been searching for about 15 mins there and found this cool instructable how to interface the arduino serial data with a C# program. Luckily I had visual studio express 2010 still installed so am doing it now the steps listed. If you would like to check it out it is available here and uses a windows form to create the program in which would be simpler I think than the webpage what do you think paul?

The link is: http://www.instructables.com/id/Interfacing-your-arduino-with-a-C-program/?ALLSTEPS

Just creating a basic form here with one square and if can get it working I will post it up to see if I can program it to change colour. I have done c++ courses before and Microsoft Software Fundamentals MTA using c# so hpefully it will come in useful here :slight_smile:

I like the room name and number idea Paul, when I add the other sensors I will do this for sure so it can perhaps report back in a message window beside the layout of a floor or office in text where the motion was detected and what time at, along with room number and name, depending on what sensor is activated :slight_smile:

Watch this space :slight_smile: lol

Hazzman:
I like the room name and number idea Paul,

I dealt with this issue earlier. If you send the data from all the sensors everytime it is not necessary to identify the room number. The PC will know that the 3rd number always relates to room 26 (for example) and sending all the data everytime will make it easier to monitor system failure.

What I have in mind is that the PC will receive a string something like this "1,0,0,0,2,0,0,0" - assuming there are 8 rooms. It means that the first room has detected motion but none of the others have, and room 5 has a fault.

...R

Ah yes now I get it Robin thats a good idea, would you know how to read them into the C# program? Been fiddling about with it for past 2 hours and have just got it to confirm that the port “COM3” is open and if it is change the text in the form to confirm that. When I disconnect the Arduino and try to run the program, it crashes and wont execute because there is no error handling code.

Would you know how to read the data from the arduino, store it in a variable as the instructable I was following is not very clear on this and brings up an error saying that the functions are not in the library.

Here is two screenshots of what I have so far attached with the cod ein second screenshot

Thanks.

Making slight progress have amended my code in C# and the arduino and uploaded it to only return a code such as “–” and “++” when motion is detected. The only problem is the windows form only displays when motion is detected and it only detects motion once, does anyone know which kind of loop to includ ein the C# program to keep updating the rooms and make them appear even when motion isnt detected?

here is the code for c# here:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;

namespace arduinotest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            //opening the serial port
            serialPort1.Open();
            if (serialPort1.IsOpen)
            {
                label1.Text = "Serial Port Connection Is Established";
            }

            string read = serialPort1.ReadLine();
            label2.Text = read;
            serialPort1.Close();

            if (label2.Text != "--")
            {
                label3.Text = "Motion has been detected";
                pictureBox1.Image = arduinotest.Properties.Resources.accountantmotion;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

And here is the modified arduino code uploaded to the UNO board:

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


void setup(){
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  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);
  }
  
  
  void loop(){

     if(digitalRead(pirPin) == HIGH)
     {
         if(lockLow)
         {  
         //makes sure we wait for a transition to LOW before any further output is made:
         lockLow = false;            
         Serial.println("--");
         delay(50);
         }         
         takeLowTime = true;
       }

     if(digitalRead(pirPin) == LOW)
        {       
        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("++");      //output
           delay(50);
           }
       }
  }

Will give it a rest for tonight getting sore head thinking about it :slight_smile:

Any thoughts greatly appreciated, will change the “++” and “–” to the numbers 0 1 or 2 like Robin mentioned earlier maybe tomorrow :slight_smile:

thanks, getting there slowly but surely maybe.

Henry

accountantofficemotiondetected.jpg

hmm thinking of giving up been staring at it past few nights for hours lol

I can get the pir sensor sometimes to work in a windows form, some problems are:

The form doesnt automatically display unless movement is detected

The program is not being updated by the read line method as I am unsure which kind of loop to use tried the while, do while loop with no affect. I have a text field showing me what each character or number teh arduino is sending when movement is detected and when its not but is not updated in real time

Also probably due to not recieving real time data only the first motion detected, the image is always red as motion detected and doesnt swap to green when the second broadcast of no movement is detected. Strange.

Anyway its driving me nuts might need to give up try something easier, or it could be because I am not using latest version of Visual Studio 2012? I am using 2010 express....

Henry

I’m not sure why I missed this Thread yesterday or the day before.

I use Linux so I don’t know C#.

This demo shows how to communicate with an Arduino using Python. The principle will be the same in all languages. You should be able to write a simple C# program to do the same thing as the Python program. Using this program the string of 1s and 0s would look like “<1,0,0,0,2,0,0,0>” and the receiving code would strip out the < and >.

I suggest you concentrate on getting the data from the Arduino and leave the GUI stuff to one side until that works.

When you have received the string of 1s and 0s it will be entirely a matter for C# programming to make use of the data.

The concept I had in the earlier post was to generate a string with Comma Separated Values (CSV) as most programming languages have a function to easily split it into its parts.

…R

Edit 04 Jan 2015 - belatedly fixed the link - apologies to all

Can you tell me how this application worked for you? It sounds like something similar we are doing and I am interested in your feedback on what you created.