Caleb ThayerSamuel Dubois
Published © GPL3+

Parking Sensors Retrofit

This project uses the Particle board to sense the distance from the rear of the vehicle to another object nearby when parking.

BeginnerFull instructions provided2 hours796
Parking Sensors Retrofit

Things used in this project

Hardware components

Photon
Particle Photon
×1
5 mm LED: Yellow
5 mm LED: Yellow
×1
5 mm LED: Red
5 mm LED: Red
×1
5 mm LED: Green
5 mm LED: Green
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
DC/DC Converter, Buck Regulator
DC/DC Converter, Buck Regulator
×1
Jumper wires (generic)
Jumper wires (generic)
×10
Resistor 220 ohm
Resistor 220 ohm
×5

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

Circuit Diagram

live graph

Thingspeak api key

Thingspeak Channel Settings

Webhook settings

webhook advanced settings

Code

Photon 1 code

C/C++
/*
 * Project parkingsensor
 * Description:Measures distance and controls LED lights
 * Author:Caleb Thayer & Sam Dubois
 * Date: 04/01/19
 */
//initiate 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() {
//sets pins
    pinMode(redPin, OUTPUT);
    pinMode(yellowPin, OUTPUT);
    pinMode(greenPin, OUTPUT);
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);
    pinMode(D7, OUTPUT);
    Serial.begin(9600);
}


void loop() {

//gets data from unltrasonic sensor
 delay(15);
    digitalWrite(trigPin, LOW);
    delayMicroseconds(4);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(15);
    digitalWrite(trigPin, LOW); 
    duration = pulseIn(echoPin, HIGH);
//converts sensor data from duration into inches
    inch = (duration/2) / 74; 
//compares distance (inch) to set ranges to control leds and trigger second photon    
    if (inch <= 1000){ 
        
        if (inch > 42){ 
            //flashes green led
            digitalWrite(greenPin, HIGH); 
            delay(200);
            digitalWrite(greenPin, LOW);
        }
        else if (inch > 18 && inch <= 42){ 
            //flashes yellow led
            digitalWrite(yellowPin, HIGH); 
            delay(200);
            digitalWrite(yellowPin, LOW);
        }
        else if (inch > 6 && inch <=18 ){ 
            //flashes red led
            digitalWrite(redPin, HIGH);
            delay(200);
            digitalWrite(redPin, LOW);
        }
        else if (inch <=6) {
            //publishes event to trigger second photon
            Particle.publish("buzzer_controller", "1");
            //publishes event to send data to thingspeak
            Particle.publish("Buzzer", "ON", PRIVATE);
            //flashes red led
            digitalWrite(redPin, HIGH); 
            delay(1000);
            digitalWrite(redPin, LOW);
            
        }
    }
    else{
       delay(800);
    }
  
}
          

Photon 2 code

C/C++
//Photon 2 recieves signal that car has reached red LED zone
//triggers 2 red LEDs to flash and buzzer to sound

void setup() {
pinMode(D1,OUTPUT);
pinMode(D2,OUTPUT);
pinMode(D3,OUTPUT);

digitalWrite(D1,LOW);
Particle.subscribe("buzzer_controller", buzz, "550040001051373331333230");
delay(1000);
//subscribe to photon 2
}
void buzz(const char *event, const char *data)
//if the event buzz occurs buzzer_controller gets published

{digitalWrite(D1,HIGH);
digitalWrite(D2,HIGH);
digitalWrite(D3,HIGH);

delay(500); //Time on
digitalWrite(D1,LOW);
digitalWrite(D2,LOW);
digitalWrite(D3,LOW);
delay(500); //time off

}
void loop() 
{
    

}

Credits

Caleb Thayer

Caleb Thayer

1 project • 0 followers
Samuel Dubois

Samuel Dubois

1 project • 0 followers

Comments