Arduino Motion Tracker

32,009

230

44

Introduction: Arduino Motion Tracker

Hi everyone!

This is my first arduino based instructable i hope you will like it:) I'm a big fan of the first Alien movie and the "old-sci-fi" gadgets, so I decided to make a fully operational portable motion-tracker. In this tutorial I will show you every step how I made it so you can make your own one. Plus at the end I will give you some advice according to my experiences so you can make an even better one. This was the first time I used a tft-lcd monitor and some faild attempt I was so happy when I realised how can I use it:)(Of course i will show you how can you use it properly)

I hope you are gonna enjoy this instructable and maybe some of you will make his/her own one. So let's start the making:)

Step 1: What You Need:

Materials and parts:

  • Arduino Mega (because of the pins )
  • 2.4" TFT display (I used one from mcufriend)
  • 3 pcs PIR sensor (HC-SR501)
  • 1pcs ultrasonic distance sensor (HC-SR04)
  • 1pcs piezo buzzer
  • 1pcs 100ohm resistor
  • some male-male jumper cable
  • many male-female jumper cable (for the display and the sensors)
  • 1pcs 11*11 cm junction box
  • 1pcs 15*11*7 cm junction box
  • 1pcs toggle switch
  • plastic sheet(I used some oddments)
  • a few screw with the screw nuts
  • 1 paif of bicycle handlebar grip
  • warning tape (for the good looking )
  • 1pcs 9v battery
  • 1pcs 9v battery clip
  • 1pcs Male Power Jack Plug 5.5 x 2.1mm
  • 2.1*5.5 male plug
  • some shrink tube
  • electrical tape
  • mini breadboard
  • pvc tube

Tools:

  • paint spary (coloring the junction boxes)
  • soldering iron
  • rotary tool
  • glue gun
  • Jig saw
  • Hole saw cutter
  • rasp
  • forceps

Step 2: The Circuit

The plan was a device what can sensing motion in three different way, so I needed three PIR motion sensors on the three different sides of the device. And an ultrasonic distance module on the front. For the sensors I used a part of the mini breadboard for the common 5V and common GND. And one of the 9V clip's cable soldered to the toggle switch so i can turn it ON/OFF. I soldered a 100Ohm resisitor to the piezo buzzer it protect the arduino board. I had to use an arduino MEGA because of the display it needs a lot of pins and an UNO doesn't have enough for the display and the sensors. Good to know the ultrasonic sensor maximum range is about 4 meter and the PIR motion sensor's maximum range is about 7 meter. But you can modify The PIR sensor's range and the delay time with 2 tiny potentiometer on the sensor. In the first picture you can see there is a lot of jumper wire so i mad a schematic picture with fritzing. It makes easier to connect correctly the sensors:)

Step 3: The Code

This part was a bit tricky, because when I tried to use the tft lcd screen always got a white screen. After some reading I realized it's not a rare problem if you use clone arduino board with not adafruit displays .I needed some hour to find the solution. (I find it in someone's instructable:) ). To save you some time you can download the modified libraries and the code what I used. After I learned how to avoid the whitescreen problem it was really fun to learn how to draw on the tft display. I'm sure i will do some other project with this type of displayshield. When I read about these sensors I noticed that they need some time to calibrate themself so to fill this time I write a "boot display" in the setup part. In the code you can check how to code a PIR sensor and the ultrasound module. I learned to use them from otherone's instructables and some great website:) I write a code that calculate the distance in cm so you need to rewrite it if you want to see it in inch. If you have any suggestion about to improve the code pls leave a comment:)

I put here 2 videos to show you the device in progress.

(Here the URLs so you can check it from phone too)

Boot monitor

Motion tracking

I tried to leave a comment for every important line or function, but if you have anny question about a code pls ask i will answer as soon as i can.

!IMPORTANT:This code is only working on arduino mega if you want to use it on an uno board you need to modify the SWTFT library uncomment uno_line and comment the mega_line!

(I want say a big thank you for these people who amended these libriaries)

Step 4: The Shell

For the shell of the device i used 2 junction boxes. The bigger one contains the arduino mega and the batteries. The other one contains the tft display. I painted the boxes with a paintspray. Good to know the plastic is becoming dry in a few hours, but on the rubber caps the paint can't be completly dry. It seems I shouldn't use this paint for rubber. After the painting I cutted 2 parts from an old unsed plastic sheet. With this 2 parts i fixed the 2 junction boxes with some screws and screw nuts. For the handle I used a piece of PVC tube. I cutted the surplusage. And I had to cut a line for the wires from the display and the distance module. I also cutted a rectangle shape hole on the top of the little junction boxe for the display. After the cutting with the jig saw I drilled the holes for the handle. Then i painted the parts. For the toggle switch i used the junction box's cutted part. After everything is dried i put the rubber caps back to their places.

Step 5: Assembling

The first step was the cabling. That was a bit meticulous work. Because there wasn't soo much place and i needed to put every jumper cable into the proper hole. After that i putted the buzzer and the left and right PIR sensor into the junction box, connect to the arduino. Good to know these sensors really sensitive so i had to overshadow them somehow. For that i used the rubber caps. I cutted a little hole on them as you see on the pictures. I fixed the sensors with some electric tape. I also used electric tape to fix the utrasonic module and the front PIR sensor. I cutted in half and vertical the bicycle grips for the handler. I don't like wasting so i used the unused grip part as a spacer for the display in the smaller junction box. I hided the orange edges of the display with some black electric tape. I glued one of the unused rubber cap to the bottom of the device so it can hide the end of the green pvc tube. For the good look i put some yellow/black warning tape on the device. Last step was to unplug the usb connector and plug the male power jack plug. Switch it ON and start Tracking motion:)

I bought the snesors and the arduino from ebay the other materials from local home improvement store. The final cost of the device is about 15-20 USD.

The final conclusion of the project is you can make literally everything what you want with the proper arduino board and some sensor and module. You can make a better looking shell if you have a 3D printer and your device could have a longer working time if you replace the 9v battery with a rechargeable or Lipo battery. And with a bigger display it looks better. Or if you use more distance mesure module you can mesure the distance in multiple way.

Now you now how to make a Motion Tracker if one of you make his/her own please leave a "I made it" comment and share with me the result. I would love to see your own gadgets.

Maybe this device will help you avoid Xenomorphs.

If you have any question please feel free asking me!

Happy making:)

Beyond the Comfort Zone Contest

Participated in the
Beyond the Comfort Zone Contest

Be the First to Share

    Recommendations

    • Make It Bridge

      Make It Bridge
    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge
    • Big and Small Contest

      Big and Small Contest

    44 Comments

    0
    mskubisz
    mskubisz

    Question 9 days ago on Step 5

    is there a pinout for the screen to the arduino? Can't seem to sort out the wiring between them...

    0
    Dylan91
    Dylan91

    Answer 8 days ago

    Hello! I did not create wiring for the display, because if you check the system wiring again and the pins of the display you will realize that you can only connect it one way.

    0
    MartynekD
    MartynekD

    4 weeks ago on Step 5

    Is it possible to use different 2,4 tft display than mcufriend?

    0
    GabrielV91
    GabrielV91

    7 weeks ago

    I got it to work with a 3.5" screen from adafruit on a 3d print file from thingiverse. The code that approximates this look which is screen size agnostic is:

    /***************************************************
    This is our GFX example for the Adafruit ILI9341 Breakout and Shield
    ----> http://www.adafruit.com/products/1651

    Check out the links above for our tutorials and wiring diagrams
    These displays use SPI to communicate, 4 or 5 pins are required to
    interface (RST is optional)
    Adafruit invests time and resources providing this open source code,
    please support Adafruit and open-source hardware by purchasing
    products from Adafruit!

    Written by Limor Fried/Ladyada for Adafruit Industries.
    MIT license, all text above must be included in any redistribution
    ****************************************************/
    // Code provided by Smoke And Wires
    // http://www.smokeandwires.co.nz
    // IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY
    // CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD.
    // SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP.


    #include "SPI.h"
    #include "Adafruit_GFX.h"
    #include "Adafruit_ILI9341.h"
    #include <Adafruit_TFTLCD.h> // Hardware-specific library
    // these are for ili9341 chips
    // For the Adafruit shield, these are the default.
    //#define TFT_DC 9
    //#define TFT_CS 10
    //#define TFT_MOSI 11
    //#define TFT_CLK 13
    //#define TFT_RST 12
    //#define TFT_MISO 8
    //#define TFT_CS 10
    // The control pins for the LCD can be assigned to any digital or
    // analog pins...but we'll use the analog pins as this allows us to
    // double up the pins with the touch screen (see the TFT paint example).
    #define LCD_CS A3 // Chip Select goes to Analog 3
    #define LCD_CD A2 // Command/Data goes to Analog 2
    #define LCD_WR A1 // LCD Write goes to Analog 1
    #define LCD_RD A0 // LCD Read goes to Analog 0
    #define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin

    // When using the BREAKOUT BOARD only, use these 8 data lines to the LCD:
    // For the Arduino Uno, Duemilanove, Diecimila, etc.:
    // D0 connects to digital pin 8 (Notice these are
    // D1 connects to digital pin 9 NOT in order!)
    // D2 connects to digital pin 2
    // D3 connects to digital pin 3
    // D4 connects to digital pin 4
    // D5 connects to digital pin 5
    // D6 connects to digital pin 6
    // D7 connects to digital pin 7
    // For the Arduino Mega, use digital pins 22 through 29
    // (on the 2-row header at the end of the board).

    // Assign human-readable names to some common 16-bit color values:
    #define BLACK 0x0000
    #define BLUE 0x001F
    #define RED 0xF800
    #define GREEN 0x07E0
    #define CYAN 0x07FF
    #define MAGENTA 0xF81F
    #define YELLOW 0xFFE0
    #define WHITE 0xFFFF
    // defines pins numbers
    const int trigPin = 22;
    const int echoPin = 23;
    const int pirPin = 13;
    const int pirPinL = 12;
    const int pirPinR = 10;
    const int Spin = 16;
    // defines variables
    long duration;
    int distance;
    // Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
    //Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
    // If using the breakout, change pins as desired
    //Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
    // below is the invocation for the 3.5" lcd
    Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
    void setup() {
    pinMode(pirPin, INPUT);//Input from the PIR sensors
    pinMode(pirPinL, INPUT);
    pinMode(pirPinR, INPUT);
    pinMode(trigPin, OUTPUT); // Output for the triggerpins
    pinMode(Spin, OUTPUT); // pin for the piezo buzzer
    pinMode(echoPin, INPUT); // Input from the Ultrasound sensors
    Serial.begin(9600);
    //below line is for the ili9341 display
    // uint16_t identifier = tft.read16();
    // this is for the 3.5" screen ID
    uint16_t identifier = tft.readID();
    tft.begin(identifier);
    tft.setRotation(3);
    txt();
    tft.setRotation(0);
    tft.fillScreen(BLACK);
    }
    void loop(void) { table(); // render bars
    // check if motion detected
    int myHeight = tft.height(); int myWidth = tft.width();
    // ping(us(), myHeight*1/2);
    if (digitalRead(pirPin) == HIGH) { ping(us(), myHeight*1/2); table(); p_s(); digitalWrite(pirPin,LOW); }
    if (digitalRead(pirPinL) == HIGH) { sideL(); table(); p_s(); digitalWrite(pirPinL,LOW); }
    if (digitalRead(pirPinR) == HIGH) { sideR(); table(); p_s(); digitalWrite(pirPinR,LOW); }
    }
    void table()//create the monitor
    { int myHeight = tft.height(); int myWidth = tft.width();
    tft.drawLine(10,10, myWidth-10, myHeight*1/2, GREEN);
    tft.drawLine(myWidth-10, myHeight*1/2, 10, myHeight-10, GREEN);
    tft.drawCircle(myWidth, myHeight*1/2, myWidth*1/8, GREEN);
    tft.drawCircle(myWidth, myHeight*1/2, myWidth*1/4, GREEN);
    tft.drawCircle(myWidth, myHeight*1/2, myWidth*7/16, GREEN);
    tft.drawCircle(myWidth, myHeight*1/2, myWidth*5/8, GREEN);
    tft.drawCircle(myWidth, myHeight*1/2, myWidth*7/8, GREEN);
    }
    void txt() {//Starting :)
    tft.fillScreen(BLACK);
    tft.setCursor(60, 20);
    tft.setTextColor(WHITE);
    tft.setTextSize(5);
    tft.println("B2-LAB");
    tft.setCursor(20, 80);
    tft.setTextColor(GREEN);
    tft.setTextSize(3);
    tft.println("MOTION-TRACKER");
    tft.setCursor(10,130);
    tft.setTextColor(RED);
    tft.setTextSize(2);
    tft.println("^VERTICAL WHEN OPERATING^");
    tft.setCursor(60, 150);
    tft.setTextColor(GREEN);
    tft.setTextSize(2);
    tft.print("Calibrate Sensors");
    tft.setCursor(10, 170);
    tft.setTextSize(3);
    for(int i=0;i<16;i++)
    {
    tft.print(".");
    delay(200);
    }
    }
    void ping(int dis, int x) { //Display the motion
    tft.fillCircle(dis, x, 10, GREEN);
    // Serial.println(x);
    delay(100);
    tft.fillCircle(dis, x, 10, BLACK);
    }
    int us()//ultrasound distance device control
    {
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    // Sets the trigPin on HIGH state for 10 micro seconds
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);// Reads the echoPins, returns the sound wave travel time in microseconds
    distance = duration * 0.034 / 2; // Calculating the distance
    return (240 - (distance * 0.7));//This needed for the proper displaying
    }
    //right PIR sensor event
    void sideR() { int myHeight = tft.height(); int myWidth = tft.width();
    tft.fillTriangle(myWidth, myHeight*1/2+5, myWidth, myHeight*3/8, myWidth*13/16-25, myHeight*3/8, GREEN);
    delay(100); tft.fillTriangle(myWidth, myHeight*1/2+5, myWidth, myHeight*3/8, myWidth*13/16-25, myHeight*3/8, BLACK); }
    //left PIR sensor event
    void sideL() { int myHeight = tft.height(); int myWidth = tft.width();
    tft.fillTriangle(myWidth, myHeight*1/2-5, myWidth, myHeight*5/8, myWidth*13/16-25, myHeight*5/8, GREEN);
    delay(100); tft.fillTriangle(myWidth, myHeight*1/2-5, myWidth, myHeight*5/8, myWidth*13/16-25, myHeight*5/8, BLACK); }
    void p_s() { digitalWrite(Spin,HIGH); delay(100); digitalWrite(Spin,LOW); }//Tracking sound effect

    0
    trevorlr
    trevorlr

    Question 1 year ago

    I'm struggling with the swtft.h library. Exactly how do I incorporate that so that I can use the motion tracker code

    0
    trevorlr
    trevorlr

    Answer 1 year ago

    I've already resolved this but thank you very much for responding. This is an awesome project. Works great. I used an eleego 2.8 and the mcufriend_kbv.

    0
    Dylan91
    Dylan91

    Answer 1 year ago

    Hi. Exactly what does it mean "struggling"? I did not used setup more than 4 yars so please provide me a bit more information:D

    0
    Mcfly1720
    Mcfly1720

    Question 3 years ago

    Hello guys,
    sorry I probably ask a stupid question but I can not get the white screen and put the software for the detector on the map. Can someone help me please?

    Thank you Dylan for the project it's so cool man.

    0
    Xenodude
    Xenodude

    Question 4 years ago

    Hey, how well does it actually work? if It's still put together, could you post a video of you actually showing off if "tracking" something?

    Only realized this AFTER ordering the mega lol

    0
    Dylan91
    Dylan91

    Answer 4 years ago

    Hey. There is video where it's tracking my leg:D But you are right i could make some better video, but i built it almost 2 years ago so now it's in pieces because i needed the MEGA for my 3D printer. But when i used this tracker it worked preatty well in a 4-5 meter range, with a little sensor noise, maybe a better code can solve this problem.

    0
    Xenodude
    Xenodude

    Answer 4 years ago

    Thanks man, will post pics when the damn mega arives ;-;

    1
    Mancave683
    Mancave683

    Question 4 years ago

    I tried this and am getting a white flashing screen. You said something about this, could you tell me more how to fix. I am using your code. An Arduino mega((elegoo) and an 2.6/2.8" ttf LCD shield(adafruit TP28017). Thanks for any help, I am rather new to this.

    white screen.JPG
    0
    Dylan91
    Dylan91

    Answer 4 years ago

    Hi! Happy to see someone try to make it:) To be honest i made this almost 2 years ago so i can't remember every details, but as i know i had to search for another library because i used clone devices. So i had to try it with couple of libraries until i got a working one. I hope you will find a working one for your tft soon:)

    0
    Glyngsdal_inovations

    Would it be possible to incorporate the Lidar-lite 3 system into this? It costs $151.99, and supposedly has a range of 40 meters or 131 Feet.

    0
    Dylan91
    Dylan91

    Reply 5 years ago

    Hy! I'm not an arduino expert , but i saw some example for arduino-lidar prjoects , so i guess it could work. however if you spend 150$ for the lidar it isn't a wast to buy an arduino for a few bucks. here is a link about this kind of project: https://www.youtube.com/watch?v=UvpuN_iOHkI

    0
    LordneverW
    LordneverW

    5 years ago

    how much did it cost to make? would ever build one to sell? and if so how much.

    0
    Dylan91
    Dylan91

    Reply 5 years ago

    Sorry for the slow response, but i had a pretty busy period in my life. So it's cost about 15$, but i really believe the spirit of DIY, so i gave you every information to make one for yourself, if you scroll down a bit you can see someone is already started to build one. Happy making!

    0
    BrianH116
    BrianH116

    6 years ago

    I need this!!

    I've downloaded everything but it proper scares me now I've looked at it. This will be my first project with Arduino

    0
    Dylan91
    Dylan91

    Reply 6 years ago

    If you never ever used an arduino i guess you need some practice. But i'm sure you can easily make it:) If you have any question pls feel free to ask it i will answer as soon as i can.

    hint: i think the best training if you try to use the different sensors separatedly. I think i left enough comment in the cod, but you can find tons of tutorials for the arduino sensors. Good luck for the making.

    P.S. pls send me a picture if ready.

    0
    BrianH116
    BrianH116

    Reply 6 years ago

    Thank you v much, that would be a great help. If you don't mind, when im ready to order my components, if you could just check my list to make sure im ordering the right bits and pieces that would be a great help! I dont want to spend a ton on my first project just in case i mess up ;) and the world of Arduino boards is still a minefield to me.