0

Alien Isolation Arduino based motion tracker
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Alien Isolation Arduino based motion tracker

by knoxvilles_Joker on Tue Apr 17, 2018 6:43 am

OK, found this instructable:
http://www.instructables.com/id/Arduino ... Isolation/

Here is the code:
Code: Select all | TOGGLE FULL SIZE
//#include <FreeDefaultFonts.h>
#include <MCUFRIEND_kbv.h>
#include <TFT_HX8357GLUE.h>
#include <UTFTGLUE.h>
#include <Adafruit_GFX.h>    // Core graphics library
#include "SWTFT.h" // Hardware-specific library

// defines pins numbers
// THESE ARE FOR THE ULTLRASONIC
const int trigPin = 30;
const int echoPin = 32;


// THESE ARE FOR THE INFRA RED
const int pirPin = 43;
const int pirPinL = 45;
const int pirPinR = 47;

// THIS IS FOR THE SPEAKER BLACK WIRE, RED TO VCC
const int Spin = 34;

// defines variables

// Code provided by Smoke And Wires
// http://www.smokeandwires.co.nz
// This code has been taken from the Adafruit TFT Library and modified for use with our TFT Shield
// For original code / licensing please refer to
// https://github.com/adafruit/TFTLCD-Library


// attempting inverse push
// pushCommand(0x00B4)
// abandonded for tft.begin(9320) vs tft.begin(0x5408)
// 0x5408 is correct chip ID but doesn't work correctly.
// 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
long duration;
int distance;

MCUFRIEND_kbv tft;

void setup(void) {
  pinMode(pirPin, INPUT);//Input from the PIR sensors
  pinMode(pirPinL, INPUT);
  pinMode(pirPinR, INPUT);
  pinMode(trigPin, OUTPUT); // Output for the triggerpins
  pinMode(Spin, OUTPUT);
  pinMode(echoPin, INPUT); // Input from the Ultrasound sensors
  Serial.begin(9600);//Start the serial communication
  tft.reset();
  delay(500);
  uint16_t identifier = tft.readID();
  //Serial.print(F("LCD driver chip: ")); //You can check the driver of your tft monitor
  Serial.println(identifier, HEX);
  //tft.begin(identifier);
  tft.begin(0x9320);
  delay(500);
  delay(500);
  txt();
  tft.setRotation(0);
  tft.fillScreen(BLACK);
}

void loop(void) {

  table();
  if (digitalRead(pirPin) == HIGH)// check if motion detected
  {
    ping(us(), 160);
    table();
    p_s();
    digitalWrite(pirPin,LOW);
  }
  else{//if no motion in front check the left and right sides
  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
{

  tft.drawLine(10, 10, 240, 160, GREEN);
  tft.drawLine(240, 160, 10, 310, GREEN);
  tft.drawCircle(240, 160, 40, GREEN);
  tft.drawCircle(240, 160, 80, GREEN);
  tft.drawCircle(240, 160, 140, GREEN);
  tft.drawCircle(240, 160, 200, GREEN);
}

void txt() {//Starting :)
  tft.setRotation(3);
  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);
 
  for(int i=0;i<16;i++)
  {
    tft.print(".");
    delay(1000);
  }
 
  /* THIS SECTION CLEARS THE SCREEN AND SETS THE ROTATION BACK */
 
  tft.fillScreen(BLACK);
  tft.setRotation(0); 
}

void ping(int dis, int x) { //Display the motion
 
  tft.fillCircle(dis, x, 10, GREEN);
  Serial.println(x);
  delay(1000);
  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
}

void sideR()//right PIR sensor event
{
  tft.fillTriangle(240,160,240,120,195,130,GREEN);
  //tft.fillCircle(230, 160, 40, GREEN);
  delay(200);
  tft.fillTriangle(240,160,240,120,195,130,BLACK);
  //tft.fillCircle(230, 160, 40, BLACK);
}

void sideL()//left PIR sensor event
{
  tft.fillTriangle(240,160,240,200,195,190,GREEN);
  //tft.fillCircle(230, 160, 40, GREEN);
  delay(200);
  tft.fillTriangle(240,160,240,200,195,190,BLACK);
  //tft.fillCircle(230, 160, 40, BLACK);
}

void p_s()//Tracking sound effect
{
  digitalWrite(Spin,HIGH);
  delay(100);
  digitalWrite(Spin,LOW);
}


I will post more findings as I get time. I have multiple other builds and this one just popped up on my radar here recently. I was advised that there are some issues with the setup and build and I will have to vet, build, and troubleshot the setup at a later point. I am merely sharing for the community to have available.

knoxvilles_Joker
 
Posts: 76
Joined: Wed Mar 01, 2017 9:15 pm

Please be positive and constructive with your questions and comments.