Max MeniusAdam CockeColin Davis
Published © GPL3+

Argon Park Assist

If you have ever pulled into a shallow parking spot and not known where to stop, if so, then this is for you.

IntermediateFull instructions provided12 hours297
Argon Park Assist

Things used in this project

Hardware components

Breadboard (generic)
Breadboard (generic)
×3
Argon
Particle Argon
×3
Resistor 330 ohm
Resistor 330 ohm
×4
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×2
Jumper wires (generic)
Jumper wires (generic)
×1
buzzer 5v
×1

Software apps and online services

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

Hand tools and fabrication machines

Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires

Story

Read more

Custom parts and enclosures

Shell Case

Functions as holster for breadboard inside.

Bumper Case

Functions as holster for Argons outside the vehicle.
Due to 3D printer issues a full set of cases was not manufactured.

Sensor Cover

Functions to cover argons outside the vehicle

Schematics

Motion Sensor Circuit

Buzzer Circuit

Code

hc-sr04.ino

C/C++
This runs the distance sensors and publishes the events with the data.
// This #include statement was automatically added by the Particle IDE.
#include <HC-SR04.h>

double cm = 0.0;
bool beam_status = false;

int trigPin = D4;
int echoPin = D5;

HC_SR04 rangefinder = HC_SR04(trigPin, echoPin);
void setup(){

    Spark.variable("cm", &cm, DOUBLE);
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT_PULLUP);
}

void loop() 
{
     cm = rangefinder.distCM();
    if (cm<40){
        if (beam_status==false){
        
            Particle.publish("MEGR3171_parkingsensor_306_stop",String(cm));
            beam_status = true;   
        }
    } else {
        if (beam_status==false){
            
        } else {
            Particle.publish("MEGR3171_parkingsensor_306_clear","Clear");
            beam_status = false;
        }
    }
    delay(1050);

   
    
    
}

buzzerandleds.ino

C/C++
When the event to stop is sensed from the other argon's, the led and buzzer turn on.
void setup() 
  

//buzzers for front and rear sensors
{
    pinMode(D7,OUTPUT);
    Particle.subscribe("MEGR3171_parkingsensor_306_clear",highfunc);
    Particle.subscribe("MEGR3171_parkingsensor_306_stop",lowfunc);
   pinMode(D6,OUTPUT);
}


void highfunc(const char *event, const char *data)
{
    tone(D7,0,0); //buzzer silent
    digitalWrite(D6,LOW);
}

void lowfunc(const char *event, const char *data)
{
    tone(D7,3500,2000); //buzzer making noise

 digitalWrite(D6,HIGH); // led lights for front and rear sensors
 



    
    
}

hc-sr04.cpp

C/C++
This is a library code that is used to run the distance sensor.
//
//    HC-SR04.cpp
//    Purpose: Implementation of the HC-SR04 driver
//
//    Author: Richard Nash
//    Version: 1.0.1

#include "HC-SR04.h"
#include "Particle.h"

HC_SR04::HC_SR04(int trigPin, int echoPin)
{
    this->trigPin = trigPin;
    this->echoPin = echoPin;
}

void HC_SR04::init()
{
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);
}

float HC_SR04::distCM()
{
    // Speed of sound is approx 343 m/s
    // 343 m/s * 100 cm/m * 0.000001 s/us / 2.0 trips
    const float uSecondsToCM = ((340.0f * 100.0 * 0.000001f) /  2.0f);
    unsigned long timeUntilLow = triggerAndMeasurePulse();
    if (timeUntilLow == 0) return NO_SIGNAL;
    return (float)timeUntilLow * uSecondsToCM;
}

float HC_SR04::distInch()
{

    // Speed of sound at 70 degrees F is approximately 1128 ft/s
    // 1128 ft/s * 12 inch/ft * 0.000001 s/us / 2.0 trips
    const float uSecondsToInch = ((1128.0f * 12.0 * 0.000001f) /  2.0f);
    unsigned long timeUntilLow = triggerAndMeasurePulse();
    if (timeUntilLow == 0) return NO_SIGNAL;
    return (float)timeUntilLow * uSecondsToInch;
}

unsigned long HC_SR04::triggerAndMeasurePulse()
{
    // Response pulse usually starts in under 500 uSecs, wait up to 2ms to be sure.
    const unsigned long timeoutHigh = 2000;
    // Response pulse should be shorter than about 29ms (allow 5 meter as limit)
    const unsigned long timeoutLow = 29000;
    unsigned long start, duration;

    // Timing is crucial here, so cannot allow other threads or interrupts
    // Maximum ammount of time in this block is limitted to 10 + 2,000 + 29,000 uS
    // Or 31 milliseconds
    ATOMIC_BLOCK() {
        // Send the 10 uSec pulse
        pinSetFast(trigPin);
        delayMicroseconds(10);
        pinResetFast(trigPin);

        start = micros();
        while (pinReadFast(echoPin) != HIGH) {
            duration = micros() - start;
            if (duration >= timeoutHigh) {
                // Didn't recieve a pulse
                return 0;
            }
        }

        start = micros();
        while (pinReadFast(echoPin) != LOW) {
            duration = micros() - start;
            if (duration >= timeoutLow) {
                // Pulse lasted longer than the 4 meter range limit
                return 0;
            }
        }
        return duration;
    }
}

hc-sr04.h

C/C++
This is a library code that is used to run the distance sensor.
//
//    HC-SR04.h
//    Purpose: HC-SR04 driver
//
//    Author: Richard Nash
//    Version: 1.0.1

// This class provides the trigger and timing to use the range
// finder. See the usage example in this library for how to use it.

#pragma once

 class HC_SR04
 {
 public:
   // No default Constructor, need to specify the pins
   HC_SR04() = delete;

   // Constructor
   // Parameters:
   // trigPin : The pin the Trig signal is connected to
   // echoPin : The pin the Echo signal is connected to
   HC_SR04(int trigPin, int echoPin);

   // Call this function in the setup() routine to set the pin modes.
   void init();

   // NOTE: Both distCM() and distInch() block threading AND interrupts for a
   // short period of time. That time can be up to approximately 31 milliseconds

   // Returns the range distance in centimeters OR NO_SIGNAL if range finding
   // failed.
   float distCM();

   // Returns the range distance in inches OR NO_SIGNAL if range finding
   // failed.
   float distInch();

   // Sentinal value for no distance returned
   const float NO_SIGNAL = -1.0f;

 private:
   int trigPin;
   int echoPin;
   unsigned long triggerAndMeasurePulse();
 };

Credits

Max Menius
1 project • 2 followers
Contact
Adam Cocke
1 project • 2 followers
Contact
Colin Davis
1 project • 2 followers
Contact
Thanks to Wesley Goodwin.

Comments

Please log in or sign up to comment.