Benjamin CampbellZack Mayes
Published

PIR Motion Detector

Motion detector that triggers a change to an LCD screen.

BeginnerProtip1,015
PIR Motion Detector

Things used in this project

Hardware components

Argon
Particle Argon
×2
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
particle antenna
×2
Jumper wires (generic)
Jumper wires (generic)
×19

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
ThingSpeak API
ThingSpeak API
Fritzing

Story

Read more

Schematics

Argon 1 (PIR Motion Sesnor)

Argon 2 (LCD Screen)

Code

LCD code

Arduino
Controls LCD and response to input from other argon
// This #include statement was automatically added by the Particle IDE.


#include "application.h"
#include <LiquidCrystal.h>
/*
  LiquidCrystal Library - Hello Sparky
 
 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the
 Hitachi HD44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.
 
 This sketch prints "Hello World!" to the LCD
 and shows the time.
 
  The circuit:
 * LCD RS pin to digital pin D0
 * LCD EN pin to digital pin D1
 * LCD D4 pin to digital pin D2
 * LCD D5 pin to digital pin D3
 * LCD D6 pin to digital pin D4
 * LCD D7 pin to digital pin D5
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 * connect R/W (pin 5) to ground
 
 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe
 modified 8 Feb 2010
 by Tom Igoe
 
 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/LiquidCrystal
 */


// Make sure to update these to match how you've wired your pins.
//pinout on LCD [RS, EN, D4, D5, D6, D7];
// pin nums LCD  [ 4,  6, 11, 12, 13, 14];
// Shield Shield [RS, EN, D4, D5, D6, D7];
// Spark Core    [D3, D5, D2, D4, D7, D8];
LiquidCrystal lcd(D0, D1, D2, D3, D4, D5);
int temperature;
int ledwork;
void analogvalue(const char *event, const char *data )
{
    String pew = data;
    temperature = pew.toInt();
}


void setup() {
  
        Particle.subscribe("PIRMOTION", analogvalue, ALL_DEVICES);
  // set up the LCD's number of columns and rows:
  lcd.begin(16,2);
  // Print a message to the LCD.
Particle.publish("led", ledwork, ALL_DEVICES);
  
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):

  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  if ( temperature > 3000 ) {
    lcd.begin(16,2);
    lcd.print("I love Golf");
      delay (1000);
    ledwork = 1;
      
    }
    else {
        lcd.begin(16,2);
        lcd.print("sleeping...");
        led = 0;
    }
  }

PIR Motion Detector Code

Arduino
Code for the motion detector, and publishes to the other argon.
// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>

// This #include statement was automatically added by the Particle IDE.


int analogvalue = 0;

int led2 = D7; // Instead of writing D7 over and over again, we'll write led2
// This one is the little blue LED on your board. On the Photon it is next to D7, and on the Core it is next to the USB jack.



unsigned long myChannelNumber = 919100;
const char * myWriteAPIKey = "T0CB3GU5EV6G4373";


void setup()
{
  Particle.variable("analogvalue", analogvalue);

  pinMode(A0, INPUT);
  
  // Subscribe to the integration response event
  Particle.subscribe("hook-response/Motion", myHandler, MY_DEVICES);
  
   pinMode(led2, OUTPUT);
  
  
}
void myHandler(const char *event, const char *data) {
  // Handle the integration response
}


void loop()
{
  // Read the analog value of the sensor (TMP36)
  analogvalue = analogRead(A0);


Particle.publish("Motion", String(analogvalue), ALL_DEVICES);
  delay(1000);
Particle.subscribe("led", ledwork, ALL_DEVICES);
  // below: if the lcd is changed, the value of ledwork will be 1, and then blink the led on the motion argon.
  if ledwork = 1 {
        
        digitalWrite(led2, HIGH);

      // We'll leave it on for 1 second...
      delay(1000);

      // Then we'll turn it off...
    
      digitalWrite(led2, LOW);

      // Wait 1 second...
      delay(1000);
      
  }
  

}

Credits

Benjamin Campbell

Benjamin Campbell

1 project • 1 follower
Zack Mayes

Zack Mayes

1 project • 1 follower

Comments