Christa LoucksWeston Byng
Published

DIY Parking Sensor

Need help parking your car? Look no further. The DIY parking sensor will alert you when you are completely in the space.

BeginnerWork in progress997
DIY Parking Sensor

Things used in this project

Hardware components

Ultrasonic Sensor - HC-SR04
SparkFun Ultrasonic Sensor - HC-SR04
×1
Jumper wires (generic)
Jumper wires (generic)
×5
Argon
Particle Argon
×2
USB Cable, USB Type C Plug
USB Cable, USB Type C Plug
×2
Resistor 220 ohm
Resistor 220 ohm
×2
5 mm LED: Red
5 mm LED: Red
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Google Sheets
Google Sheets
SmartThings service
IFTTT SmartThings service

Story

Read more

Schematics

HC-SR04 Circuit Setup: Particle Argon 1

This circuit shows how the Ultrasonic Sensor is connected to the Particle Argon.

LED Circuit Setup: Particle Argon 2

The LED circuit setup shows how to connect the LED to the particle argon. When the car is < 60 cm away from the ultrasonic sensor, the particle argon will listen for the event called "Breach". Then, it will set off the red LED to alert the driver that they are in the parking spot.

Code

HC-SR04 Sensor Code: Particle Argon 1

C/C++
This is the code used for the ultrasonic sensor. The distance between the car and sensor is determined. If the car is < 60 cm away, the particle argon publishes an event called "Breach", meaning the driver needs to stop. If the car is > 60 cm from the sensor, the particle argon publishes an event called "Clear". This means the driver should pull forward into the place more.
// Pin Definitions

#define HCSR04_PIN_TRIG	D2
#define HCSR04_PIN_ECHO	D6

int sound = 0;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
 
  pinMode(HCSR04_PIN_TRIG, OUTPUT);
  pinMode(HCSR04_PIN_ECHO, INPUT);
 
}

void loop() {
  // put your main code here, to run repeatedly:
  long timeTaken, distance;
  digitalWrite(HCSR04_PIN_TRIG, LOW);
  delayMicroseconds(2);
  digitalWrite(HCSR04_PIN_TRIG, HIGH);
  delayMicroseconds(10);
  digitalWrite(HCSR04_PIN_TRIG, LOW);
  timeTaken = pulseIn(HCSR04_PIN_ECHO, HIGH);//determine distance of wave
  distance = (timeTaken/2)/29.1;//using timeTaken calc distance of object

  /*determine corressponding leds to light up with respect to the distance
  of object*/


    if(distance<=60){
       Particle.publish("MEGR3171_IOTGROUP18_ParkingSensor","Breach",PUBLIC);
    }
    else{
      Particle.publish("MEGR3171_IOTGROUP18_ParkingSensor","Clear",PUBLIC);
      }
    delay(1000);
   }
        
        

LED Code: Particle Argon 2

C/C++
This code is used to alert the driver when they are too far away from the parking spot, or when they are too close. If the car is < 60 cm away, this particle argon will trigger the LED. This is accomplished when subscribed particle argon 2 listens for the event data from particle argon 1. It listens for "Breach", then takes action to alert the driver.
int led = D7;
int state = 0;



void setup() {
    
Particle.subscribe("MEGR3171_IOTGROUP18_ParkingSensor", Wbyng_3171_ParkingSensor_Handler);
// subscribe to the HC-SR04 sensor. Name is MEGR3171_IOTGROUP18_ParkingSensor 
// The handler name is used below for the void loop. Make sure name is identical. 

Serial.begin(9600);

pinMode(led, OUTPUT);
digitalWrite(led, LOW);

}


void loop () { 
// Nothing happens for this sketch
}

void Wbyng_3171_ParkingSensor_Handler(const char *event, const char *data)
{
   digitalWrite(led,HIGH);
   
    if (strcmp(data,"Clear")==0) {
        
        // if the car is far away, then turn your board LED and buzzer off
       digitalWrite(led,LOW);
    }
    else if (strcmp(data,"Breach")==0) {
        // if the car is under 60 cm away, turn your board LED and buzzer on
        digitalWrite(led,HIGH);
       
    }
    else {
      
        // if the data is something else, don't do anything.
        // Really the data shouldn't be anything but those two listed above.
    }
    delay(1000);
}

Credits

Christa Loucks

Christa Loucks

1 project • 0 followers
Weston Byng

Weston Byng

1 project • 0 followers

Comments

Add projectSign up / Login