Steven SwaglerClay Peterson
Published

MEGR 3171 IOT Parking Sensor

Device that alerts you to stop and turns on a "porch light" when you pull into your parking spot.

IntermediateFull instructions provided4 hours1,141
MEGR 3171 IOT Parking Sensor

Things used in this project

Hardware components

Photon
Particle Photon
×2
Male/Male Jumper Wires
×16
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Relay Module
×1
5 mm LED: Red
5 mm LED: Red
×1
5 mm LED: Yellow
5 mm LED: Yellow
×1
5 mm LED: Green
5 mm LED: Green
×1
Resistor 221 ohm
Resistor 221 ohm
×3
Home-made LED pannel
×1

Software apps and online services

Google Sheets
Google Sheets
Maker service
IFTTT Maker service

Story

Read more

Custom parts and enclosures

LED Stop Light

Mount for the LED Light Arrays

This the mount for the LED light arrays that are harvested form the $1 LED flash lights at walmart

Schematics

Photon 2: Circuit Diagram for Porch Light and Data Plotting

Relay used is shown in the parts list.

Photon 1: Circuit Diagram for Distance Sensor and Light Tree

Code

Photon 2: Porch Light LED Code

C/C++
This code is used for Photon 2. It turns on the LED light and send a notification for the graphing aspect and for Photon 1 to know when to flash the light tree and thus turn off.
//Photon 2, Turns on the LED porch light and sends a publish that IFTTT will
//pick up and that Photon 2 will pick up to flash the light tree

void setup() {
pinMode(D7,OUTPUT); //Setting up which pin will be used for the output
digitalWrite(D7,LOW);//Setting the default state of the pin to low/off
Particle.subscribe("StevenSwaglerLED", HI, "42002d001051363036373538");
//setting up the subscribe to search for the first photon and then search
//for the publish of StevenSwaglerLED
}
void HI(const char *event, const char *data)
//if the event HI occurs (StevenSwaglerLED is published and found)
//then it will turn on/ turn to high the D7 pin output
{digitalWrite(D7,HIGH);
//The next line of code published an event ClayPetersonLED 
//with the data of "1" for the spreadsheet. "1" is light on nothing is light off
Particle.publish("ClayPetersonLED","1");
delay(60000); //Time the light should be on. The next line turns the D7 pin off
digitalWrite(D7,LOW);
Particle.publish("ClayPetersonLED","0"); //to publish only to spreadsheet 
//(since data on listening photons only run if data == 1)
}
void loop() {
    

}

Photon 1: Vehicle distance reader

C/C++
fhgffddjd
//Defining variables
unsigned long duration, inch, setdistance, setdistanceinch, diff;
int trigPin = 2;
int redPin = 3;
int yellowPin = 4;
int greenPin = 5;
int echoPin = 6;

void setup()
{
    //Defining inputs and outputs
    pinMode(redPin, OUTPUT);
    pinMode(yellowPin, OUTPUT);
    pinMode(greenPin, OUTPUT);
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);
    pinMode(D7, OUTPUT);
    Particle.subscribe("ClayPetersonLED",LEDOn,"4b0023000351353530373132");
    setdistanceinch = 0;
    Serial.begin(9600);
}

void loop()
{
    delay(10); //lines 23 - 30 output and collect the soundwave, get a duration in
    //terms of microseconds, convert that time to distance since we know how fast sound travels
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW); 
    duration = pulseIn(echoPin, HIGH);
    inch = (duration/2) / 74; //divides time in half since wave has to go both there and back,
    //divides by 74 since that is the time it takes for sound to travel one inch.
    diff = (abs(inch - setdistanceinch)); //This will gather a change in distance from when the
    //red light zone was last activated so we can determine if the car is parked or not. This is
    //absolute to solve the problem of it losing the distance right when it takes the setdistance
    //measurement and the setdistance being 10+ feet away
    
    if (diff >= 4 && inch <= 1000){ //only runs if car has moved four inches since last in the red 
    //light zone and is closer than 7 feet
    setdistanceinch = 0; //redefine our set distance to zero so we can move into red zone if the 
    //setdistance was previously set to 20-24 inches
        
        if (inch > 60){ // if greater than 5 feet, turn on green light
            digitalWrite(greenPin, HIGH);  
            delay(200);
            digitalWrite(greenPin, LOW);
        }
        else if (inch > 24 && inch <= 60){ //if greater than 2 feet but less than or equal to 5 feet, 
        //turn on yellow light
            digitalWrite(yellowPin, HIGH);  
            delay(200);
            digitalWrite(yellowPin, LOW);
        }
        else if (inch <= 24){ //if less than 2 feet, turn on red light, publish an event so LED photon
        //can see we are in red zone, and define a setdistance where we are parked.
            Particle.publish("StevenSwaglerLED", "1");
            digitalWrite(redPin, HIGH);  
            delay(5000); //delay 5 seconds to allow the driver to park in the red zone before capturing
            //parking distance (set distance)
            digitalWrite(redPin, LOW);
            setdistanceinch = inch; //defines parked distance so we must change from this (EITHER direction) 
            //4 inches before lighting code will run again.
        }    
    }
    else{
       delay(500); //delay half second when outside of 7 foot range
    }
    
}

    
void LEDOn(const char *event, const char *data) //turns all lights on tree on for 5 seconds after
//receiving event that LED has turned on
{
    if (strcmp(data,"1")==0){
    delay(5000); //must be same as line 49
    digitalWrite(greenPin, HIGH);
    digitalWrite(yellowPin, HIGH);
    digitalWrite(redPin, HIGH);
    delay(10000); //turns lights off and waits 10 seconds before going back to check again
    digitalWrite(greenPin, LOW);
    digitalWrite(yellowPin, LOW);
    digitalWrite(redPin, LOW);
    }
    else{
    }
    
}

Credits

Steven Swagler

Steven Swagler

1 project • 0 followers
Clay Peterson

Clay Peterson

1 project • 0 followers

Comments

Add projectSign up / Login