Connor ChildersDylan Elliott
Published

Sensor Controlled Entrance and Stop LED

If you ever have trouble knowing how far to pull up into your garage, this is the product that can help.

IntermediateFull instructions provided8 hours156
Sensor Controlled Entrance and Stop LED

Things used in this project

Hardware components

Argon
Particle Argon
×2
PIR Sensor, 7 m
PIR Sensor, 7 m
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
LED Strip, NeoPixel Digital RGB
LED Strip, NeoPixel Digital RGB
×1
Breadboard (generic)
Breadboard (generic)
×2

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Maker service
IFTTT Maker service

Story

Read more

Schematics

PIR Sensor and LED Circuit

Ultrasonic Sensor Circuit

Code

Argon 1 (PIR and LED code)

C/C++
This code triggers the attached LED to turn on when the PIR motion sensor detects motion.
// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>

SYSTEM_MODE(AUTOMATIC);

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D6
#define PIXEL_COUNT 30
#define PIXEL_TYPE WS2812B

Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

int red;
int green;
int blue;

int inputPin = D2;               
int ledPin = D6;
int val = 0;  
int trigPin = D4;
int echoPin = D5;

void setup() {
     
  pinMode(inputPin, INPUT); 
  pinMode(ledPin, OUTPUT);
  
  digitalWrite(ledPin, LOW);
  strip.begin();
  
  

    pinMode(trigPin, OUTPUT);
    Particle.subscribe("tripStatus", red2);
    pinMode(echoPin, INPUT_PULLUP);


  
}

  void red2(const char *event, String data) {
    
     if (strcmp(data,"1")==0) {
    // if the sensor's threshold is breached, then turn your LED on
     colorAll(strip.Color(255,0,0),30);
    delay(1000);

  }
  else if (strcmp(data,"0")==0) {
    // if your sensor's beam is all clear, turn your board LED off
   colorAll(strip.Color(0,0,0),30);
   delay(1000);
 
}
}



  void loop(){

  
  val = digitalRead(inputPin);  
  
  if (val == LOW) {
    
    colorAll(strip.Color(0,0,0),30);
    Particle.publish("motion","0");
    delay(1000);
  }
  
  else if (val == HIGH) {            
    
    Particle.publish("motion" , "1");
    
    colorAll(strip.Color(0, 255, 0),30);
    delay(6000);
     } 
  
delay(1000);

}



void colorAll(uint32_t c, uint8_t wait) {
  uint16_t i;

  for(i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
  }
  strip.show();
  delay(wait);
}

Argon 2 (Ultrasonic Sensor Code)

C/C++
This code establishes the parameters for the ultrasonic sensor and sends the data received from the ultrasonic sensor to the cloud, which is received by Argon 1 to control the "stop" function of the LED. Both sets of data are recorded and published to the Particle app as an event. The events recorded from this code are used to plot the light on/off data in a google sheet.
// This #include statement was automatically added by the Particle IDE.
#include <HC_SR04.h>


double cm = 0.0;
bool beam_status = false;

int trigPin = D4;
int echoPin = D5;
int inputPin = D2;               
int ledPin = D6;
int val = 0; 

HC_SR04 rangefinder = HC_SR04(trigPin, echoPin);

void setup() {
  
  pinMode(inputPin, INPUT); 
  pinMode(ledPin, OUTPUT);
  
  digitalWrite(ledPin, LOW);
 
  
    pinMode(inputPin, OUTPUT);
    Particle.subscribe("motion",0);
    pinMode(ledPin, INPUT_PULLUP);
    
    Spark.variable("cm", &cm, DOUBLE);
}

void loop() 
{
    cm = rangefinder.getDistanceCM();
    if (cm<30){
        if (beam_status==false){
            
            Particle.publish("tripStatus", "1");
            beam_status = true;   
        }
    } else {
        if (beam_status==false){
            
        } else {
            Particle.publish("tripStatus", "0");
            beam_status = false;
        }
    }
    delay(100);
}

Credits

Connor Childers

Connor Childers

1 project • 1 follower
Dylan Elliott

Dylan Elliott

1 project • 1 follower

Comments

Add projectSign up / Login