Kyler MashburnRichard KuntzJack Flynn
Published

Particle Argon Digital and Analog Parking Sensor

Setting up and Building a parking sensor with Particle Argons, digital, and analog sensors.

IntermediateFull instructions provided5 hours7
Particle Argon Digital and Analog Parking Sensor

Things used in this project

Hardware components

Argon
Particle Argon
×3
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×3
Ultrasonic Sensor - HC-SR04
SparkFun Ultrasonic Sensor - HC-SR04
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×3
Resistor 220 ohm
Resistor 220 ohm
×1
Resistor 1k ohm
Resistor 1k ohm
×1
LED (generic)
LED (generic)
×2
Pololu Carrier with Sharp GP2Y0A60SZLF Analog Distance Sensor 10-150cm, 5V
×1
GIKFUN 6X6X5MM TACT SWITCH PUSH BUTTON FOR ARDUINO PCB PACK OF 50PCS EK1019
×1

Software apps and online services

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

Story

Read more

Schematics

Analog Distance Sensor Schematic

Ultrasonic Schematic

LED and Button Schematic

Code

Analog Distance Sensor Code

C/C++
#include <math.h>;

SYSTEM_THREAD(ENABLED);


double counts =0;
double inches =0;
double filterinch=0;
double filtercount=0;
double filterconstant=60; //increase this term in increase filtering.  0 = no filtering.. 60 = good,do not get too high or you get bad data and errors from rounding


void setup() {
    
 Particle.subscribe("Power", MY_DEVICES); //subscribes to the published statement in the LED Code
 Particle.variable("countsseen",counts);
 Particle.variable("filtercount",filtercount);
 Particle.variable("inchesseen",inches);
 Particle.variable("filterinch",filterinch);
 Serial.begin(230400);
 //delay(5000);



}

void loop() {

 counts = analogRead(A0);
 //calibration entered from excel spreadsheet.
 //inches = 0;
 inches = -0.6487*pow(counts,3) - 31.907*pow(counts,2)-544.3*counts + 3965;
 //y = 0.00000120x2 - 0.00856652x + 18.34594023
 
 filterinch = ((filterinch*filterconstant)+inches)/(filterconstant+1);
 filtercount = ((filtercount*filterconstant)+counts)/(filterconstant+1);
 
 if (filtercount >= 575) {
     Particle.publish("In Range - Activate Light", "InRange", PUBLIC);
 }
 else (filtercount < 574); {
     Particle.publish("In Range - Activate Light", "OutRange", PUBLIC);
     
 }
 //Serial.print("counts ");
 //Serial.print(counts);
 //Serial.print(" filtercounts ");
 //Serial.print(filtercount);
 //Serial.print(" inches ");
 //Serial.print(inches);
 //Serial.print(" filterinches ");
 //Serial.println(filterinch);
 delay(1500);
}

LED and Button Code

C/C++
int led = D7;
int ledstate = 0;
int button = D2;
int buttonstate = LOW;


void setup() {

Particle.subscribe("In Range - Activate Light", MEGR3171ParkingSensor);

Serial.begin(9600);

pinMode(button, INPUT);

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

void loop() {
Particle.publish("Power", PRIVATE);
}



void MEGR3171ParkingSensor(const char*event, const char *data)
{
    if (strcmp(data, "OutRange")==0){
        
        digitalWrite(led, LOW);
    }
    else if (strcmp(data, "InRange")==0){
        digitalWrite(led, HIGH);
    }
    else {
        
        
    }
}

Ultrasonic Code

C/C++
#define RCWL1601_PIN_TRIG D2
#define RCWL1601_PIN_ECHO D6

int sound = 0;

void setup() {
    
    Serial.begin(9600);
    
    pinMode(RCWL1601_PIN_TRIG, OUTPUT);
    pinMode(RCWL1601_PIN_ECHO, INPUT);
    
   // Particle.subscribe("Button Clicked", loop); //subscribes to the button being clicked in led code

}

void loop() {
    
    long timeTaken, distance;
    digitalWrite(RCWL1601_PIN_TRIG, LOW);
    delayMicroseconds(2);
    digitalWrite(RCWL1601_PIN_TRIG, HIGH);
    delayMicroseconds(10);
    digitalWrite(RCWL1601_PIN_TRIG, LOW);
    timeTaken = pulseIn(RCWL1601_PIN_ECHO, HIGH);
    distance = (timeTaken/2)/29.1;
    
    
    
    
    
    if(distance<=60){
        Particle.publish("In Range - Activate Light", "InRange", PUBLIC);
    }
    else{
        Particle.publish("In Range - Activate Light", "OutRange", PUBLIC);
    
    }
    delay(5000);

}

Credits

Kyler Mashburn

Kyler Mashburn

1 project • 0 followers
Richard Kuntz

Richard Kuntz

1 project • 0 followers
Jack Flynn

Jack Flynn

1 project • 0 followers

Comments

Add projectSign up / Login