Maria TapiaDaniel Law
Published

Lane Tech HS- Front Gate sensor

This will alert you when the gate is open so you can go close it.

BeginnerFull instructions provided4 hours165
Lane Tech HS- Front Gate sensor

Things used in this project

Hardware components

Argon
Particle Argon
×1
Breadboard (generic)
Breadboard (generic)
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×4
Resistor 221 ohm
Resistor 221 ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×2

Software apps and online services

IFTTT
I used the IFTTT network to send me an email whenever the argon published an event. The event was triggered when the distance between the gate and sensor was more than 2 inches.
Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

Breadboard Diagram

Code

Front Gate Sensor

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <HC-SR04.h>

/*
 The HC-SR04 device is a 5V device. So, VIN (which is 5V when connected to a USB power supply)
 is used to power it. Also, the "Echo" pin will present a 5V pulse, which can be connected
 to any of the D* GPIO pins, as they are 5V tolerant. However, they cannot be connected to
 non-5V tolerant pins, like the A* pins, even if in digitial mode.

 This example expects the wiring to be as follows:
    Argon  HC-SR04
    GND     GND
    VUSB    VCC
    A0      Trig
    D5      Echo
*/
// trigger / echo pins
const int triggerPin = A0;
const int echoPin = D5;

HC_SR04 rangefinder = HC_SR04(triggerPin, echoPin);

void setup()
{
    Serial.begin(9600);
    rangefinder.init();
}

void loop()
{
    unsigned long start = micros();
    float inch = rangefinder.distInch();
    unsigned long calcTime = micros() - start;
    Serial.printf("Range finding duration: %lu | Distance in inches: %.2f\n", calcTime, inch);
    delay(500);
    
    // checks for when distance is more the 2 inches 
    if (inch>2)
    {
      // this would allow you to clearly see when the distance > 2 inches      //when looking at the serial monitor 
      
        Serial.printf(" The Gate is open, go close the gate! ");
        
        // delay so you won't get too many emails 
  
        delay (1000);
        
        // event is published
        Particle.publish("closeFrontGate", "The front gate is open! Go close it!",PRIVATE);
       
    }
}

Credits

Maria Tapia

Maria Tapia

2 projects • 1 follower
Daniel Law

Daniel Law

18 projects • 7 followers
Teacher. Maker. Citizen of the planet.

Comments

Add projectSign up / Login