Gavin Awtrey
Published

Parking Sensor With Light Project

This project had the purpose of creating a parking sensor that uses an ultrasonic sensor and a RGB led light. Micah Ollis and Gavin Awtrey.

BeginnerShowcase (no instructions)213
Parking Sensor With Light Project

Things used in this project

Hardware components

Jumper wires (generic)
Jumper wires (generic)
×6
Photon 2
Particle Photon 2
×2
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Elegoo rgb led
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

Ultrasonic Sensor Schematic

This is the setup for the ultrasonic sensor to the photon 2.

RGB Led Light Schematics

This is the connection of the RGB led to the photon 2.

Graph of sensor data

This is a graph that shows the sensor picking up how close it is to an object in inches.

Graph of sensor data

This graph just shows a bigger amount of time of the graph of distance vs. time.

Code

Led Code

C/C++
int led = D0;

void setup() {
    
Particle.subscribe("Car_Park_Sensor", Car_Park_Sensor);
// subscribe to the ultrasonic sensor. Name is Skippy but sends data as "Car_Park_Sensor". 
// 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() {

}

void Car_Park_Sensor(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,"STOP")==0) {
        // if the car is under 12 inches away, turn your board LED and buzzer on
        digitalWrite(led,HIGH);
       
    }

    delay(500);
}

Sensor Code

C/C++
// defines pins numbers
#define trigPin	D2
#define echoPin	D6
// defines variables
long duration;
long distance;
void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  Serial.begin(9600); // Starts the serial communication
}
void loop() {
  // Clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance in inches per microsecond
  distance = duration * 0.013543 / 2;
  // Prints the distance on the Serial Monitor
  Serial.print("Distance: ");
  Serial.println(distance);
  
 if(distance<=12){
       Particle.publish("Car_Park_Sensor","STOP",PRIVATE);
    }
    else{
      Particle.publish("Car_Park_Sensor","Clear",PRIVATE);
      }


  // Get some data
  String data = String(distance);
  // Trigger the integration
  Particle.publish("Distance", data, PRIVATE);
  // Wait 1 seconds
  delay(500);

   }
             

Credits

Gavin Awtrey

Gavin Awtrey

1 project • 1 follower

Comments