Parking Buddy - Arduino Neopixel IOT Parking Assist

10,753

175

21

Have you ever wanted a high tech parking assistant? Its time to put away your hanging tennis ball and get into the 21st century with an electronic parking buddy. This project uses an ultrasonic sensor and a nexopixel ring to light up and complete the ring as your get closer to the sensor.. When you are at your maximum distance (closeness) the ring will be full, (fades from green to yellow.. If you get to close it will flash red to warn you your in panic mode!

Step 1: Gather Your Parts

So what will you need to create your own tiny tiny parking buddy!

1. Ultra Sonic Distance Sensor - HC-SR04 Less than $1 online
2. NeoPixel Ring - 24 x 5050 RGB LED with Integrated Drivers - ~ $17
3. Arduino nano or mini pro - $2-5
4. An enclosure - Free if you have a 3d printer, or find a DIY container
5. 5v Power-supply
6. 470 ish ohm resistor / 1000uf capactior
7. 3.3v regulator (if you go with the arduino micro pro)

I started the project using an arduino nano but later swapped it to a micro pro as i wanted it to run at 3.3v to simplify adding wifi to the project (optional future step). My next Addition will be having the sensor either host a webpage saying if a car is present or not.... or having the sensor update a larger system which i have not yet built :)

Step 2: Program Your Arduino

Copy the code below into your arduino sketch and upload to your board. This code was origionaly found on the mysensor site and modified to suite my project.



/**
 * This code has been modified from the original MySensor code to fit this project.
 * 
 * The MySensors Arduino library handles the wireless radio link and protocol
 * between your home built sensors/actuators and HA controller of choice.
 * The sensors forms a self healing radio network with optional repeaters. Each
 * repeater and gateway builds a routing tables in EEPROM which keeps track of the
 * network topology allowing messages to be routed to nodes.
 *
 * Created by Henrik Ekblad 
 * Copyright (C) 2013-2015 Sensnology AB
 * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
 *
 * Documentation: http://www.mysensors.org
 * Support Forum: http://forum.mysensors.org
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 *******************************
 *
 * REVISION HISTORY
 * Version 1.0 - Created by Henrik Ekblad
 * 
 * DESCRIPTION
 * Parking sensor using a neopixel led ring and distance sensor (HC-SR04).
 * Configure the digital pins used for distance sensor and neopixels below.
 * NOTE! Remeber to feed leds and distance sensor serparatly from your Arduino. 
 * It will probably not survive feeding more than a couple of LEDs. You 
 * can also adjust intesity below to reduce the power requirements.
 * 
 * Sends parking status to the controller as a DOOR sensor if SEND_STATUS_TO_CONTROLLER 
 * is defined below. You can also use this _standalone_ without any radio by 
 * removing the SEND_STATUS_TO_CONTROLLER define.
 */

//#define SEND_STATUS_TO_CONTROLLER  // Put a comment on this line for standalone mode

#include 
#include 

#ifdef SEND_STATUS_TO_CONTROLLER
// Enable debug prints to serial monitor
#define MY_DEBUG 

// Enable and select radio type attached
//#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69

#include 
#include 
#endif

#define NEO_PIN      6 // NeoPixels input pin

#define TRIGGER_PIN  3  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     2  // Arduino pin tied to echo pin on the ultrasonic sensor.

#define NUMPIXELS      24 // Number of nexpixels in ring/strip
#define MAX_INTESITY   20  // Intesity of leds (in percentage). Remeber more intesity requires more power.

// The maximum rated measuring range for the HC-SR04 is about 400-500cm.
#define MAX_DISTANCE 100 // Max distance we want to start indicating green (in cm)
#define PANIC_DISTANCE 50 // Mix distance we red warning indication should be active (in cm)
#define PARKED_DISTANCE 60 // Distance when "parked signal" should be sent to controller (in cm)

#define PARK_OFF_TIMEOUT 20000 // Number of milliseconds until turning off light when parked.

// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, NEO_PIN, NEO_GRB + NEO_KHZ800);

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.


//#ifdef SEND_STATUS_TO_CONTROLLER
//#define CHILD_ID 1
//MyMessage msg(CHILD_ID,V_TRIPPED);
//#endif
unsigned long sendInterval = 5000;  // Send park status at maximum every 5 second.
unsigned long lastSend;

int oldParkedStatus=-1;

unsigned long blinkInterval = 100; // blink interval (milliseconds)
unsigned long lastBlinkPeriod;
bool blinkColor = true;

// To make a fading motion on the led ring/tape we only move one pixel/distDebounce time
unsigned long distDebounce = 30; 
unsigned long lastDebouncePeriod;
int numLightPixels=0;
int skipZero=0;

void setup() {
  Serial.begin(9600);
  Serial.println("Starting distance sensor");
  pixels.begin(); // This initializes the NeoPixel library.
  Serial.println("Neopixels initialized");
}

//#ifdef SEND_STATUS_TO_CONTROLLER
//void presentation()  {
//  sendSketchInfo("Parking Sensor", "1.0");
//  present(CHILD_ID, S_DOOR, "Parking Status");
//}
//#endif

void loop() {
  unsigned long now = millis();
  unsigned int fullDist = (sonar.ping_median() / US_ROUNDTRIP_CM);
//  Serial.println(fullDist);
  int displayDist = min(fullDist, MAX_DISTANCE);
  if (displayDist == 0 && skipZero<10) {
    // Try to filter zero readings
    skipZero++;
    return;
  }
  // Check if it is time to alter the leds
  if (now-lastDebouncePeriod > distDebounce) {
    lastDebouncePeriod = now;

    // Update parked status
    int parked = displayDist != 0 && displayDist sendInterval) {
      if (parked)
        Serial.println("Car Parked");
      else
        Serial.println("Car Gone");
//#ifdef SEND_STATUS_TO_CONTROLLER
//      send(msg.set(parked)); 
//#endif
      oldParkedStatus = parked;
      lastSend = now;
    }

    if (parked && now-lastSend > PARK_OFF_TIMEOUT) {
      // We've been parked for a while now. Turn off all pixels
      for(int i=0;inumLightPixels) {
          // Fast raise
          numLightPixels += max((newLightPixels - numLightPixels) / 2, 1);
        } else if (newLightPixels=NUMPIXELS) {
        // Do some intense red blinking 
        if (now-lastBlinkPeriod > blinkInterval) {
          blinkColor = !blinkColor;
          lastBlinkPeriod = now;
        }
        for(int i=0;i

Step 3: Printing and Installing the Enclosure

Next Build your circuit and print the attached case. I designed it a smidge small so scale it up by 3% when you print it and it should fir perfectly. (STL Files attached)

The attached visual schematic is using an arduino nano. If you wish to use the arduinoi micro pro you need to add a 3.3v regulator to power the boards VIN. otherwise the schematic is identical.

I tried to keep things as tight as possible and soldered most of it inside of the new housing. I also removed the majority of the pin headders from and soldered wires directly to it to make things a little more compact. Depending where you buy your components they may come with pin headers not yet soldered to save you the work :)

Step 4: Testing

Its time to plug it in and test it out!

To set your minim and maximum distance edit these lines of the sketch


// The maximum rated measuring range for the HC-SR04 is about 400-500cm.

#define MAX_DISTANCE 100 // Max distance we want to start indicating green (in cm)
#define PANIC_DISTANCE 50 // Mix distance we red warning indication should be active (in cm)
#define PARKED_DISTANCE 60 // Distance when "parked signal" should be sent to controller (in cm)



These values control when your ring starts to light up, when its full and when it flashes red for the panic distance.. Play with them until the distance is right for your specific setup.

Share

    Recommendations

    • 1 Hour Challenge

      1 Hour Challenge
    • Colors of the Rainbow Contest

      Colors of the Rainbow Contest
    • Pets Challenge

      Pets Challenge

    21 Discussions

    0
    None
    bender2k

    2 years ago

    Is it possible that there is something wrong in the code?

    I built 2 of the sensors and they work perfect for days.

    But sometimes they are flashing red for hours. Even if there is nohting within 5m to the sensor.

    This stops after some hours and the sensor works again.

    When it is flashing red all the time, it can not be stopped with moving something to the sensor and it can not be stopped with covering the sensor!

    When it works normally the LEDs turn off, when covering the sensor, because there is no Signal recognised. So i dont think it is a sensor Problem.

    3 replies
    0
    None
    grant.steven.watsonbender2k

    Reply 1 year ago

    I also get this problem. Tried it on two different sets of hardware with the same problem.

    Works fine at first, but over the course of idling with nothing in sensor range for a few hours, the neopixel ring begins to flash red. Moving something into sensor range doesn't have any effect on it, but a quick power cycle sorts it out for another few hours.

    Any idea what could be going wrong?

    0
    None
    les92111grant.steven.watson

    Reply 11 months ago

    Hey Bender2k/Grant, I had the same issue! I have noticed that this code is actually from

    https://github.com/mysensors/MySensorsArduinoExamp... but has a few lines commented out. So perhaps there in lies the problem. However, I noticed another credits/kudos to Rick at

    https://github.com/rvrickv/Arduino-Garage/blob/mas... for putting up a great example that even lets you change the parking distance without reflashing! Go check out his code.

    One thing to note, is the code doesn't seem to run on the arduino nano. So I have posted my version/fork of it. I have changed it to remove the remember the distance to eeprom (since nano doesnt support) and changed it so the lighting is more significant. It works really well and running for a day now without the issue of constant flashing.

    To answer the question i know i'm going to get, why more significant? Lets discuss 2 variables first. Measure the closest distance the vehicle can be to the sensor in cm - this is where it will blink red (in my case 31cm). Then measure the maximum distance where you could park safely (in my case 53cm). So in my case I will take 53-31=22 and add that value (22) to 53 for 75. This gives me the distance where the display will show.

    #define PARKING_DISTANCE 31 // Default parking distance
    #define MAX_DISTANCE 75 // Sensor is less precise at longer distances

    Why this way. When you hit 75 cm the display starts up, you know the parking assistant is working. It is showing the leds in yellow so you know its not yet safe to park. When you get to 53 (1/2 the leds displayed) the leds become green -safe to park and the led circle continues growing green until you hit the danger area (31) when it blinks red.

    https://github.com/iammenotyou/Arduino-Garage

    Instructions: Put both files in the same directory, open parkingsensor_w_led.ino and flash. Hope this helps!

    0
    None
    bender2kgrant.steven.watson

    Reply 12 months ago

    Yes! Exactly the same! I have the same error with an ATTiny85 and with an Arduino Nano.

    I recorded the trigger and echo signals with an osilloscope and have seen, that the signal length and frequency slightly changes over time, but i have not enough experience to find the root cause in the code. I could not solve it...

    I had the hope, the inventor of the instructable will fix it, but there is no response.... :(

    0
    None
    K1NG7

    2 years ago

    Hello I am trying the code that you provided but it keepings giving me.

    (Error compiling for board Arduino/genuine micro)

    Why is that?

    0
    None
    Sergio JaredV

    2 years ago

    Great idea, but why does the title says IOT? And why did you put the sensor and the neopixel ring in the same enclosure? I think it would be better to have the neopixel ring somewhere near the car panel, separate from the sensor, to easily see the warning. Maybe for another application that enclosure would be perfect.

    2 replies
    0
    None
    shiftlineSergio JaredV

    Reply 2 years ago

    I wanted an all in one "tiny" unit. As long as its around hood hight it will see the car, and you can see the light. I will update this with the IOT part once my wifi chip shows up. the one ihad was having issues.. I want it to post a status if there is a car parked or not :)

    0
    None
    SmG7shiftline

    Reply 2 years ago

    I see it's been a few months now since you mentioned you were waiting for a new wifi chip so you could redo this with IOT. Has that been done yet? I'd like to set mine up that way if possible and wondered if you can share your instructions for doing it that way yet. Thanks.

    0
    None
    bender2k

    2 years ago

    Is it possible to add a button to Set the Trigger distance?
    Also, ist it possible to use a AT Tiny?

    2 replies
    0
    None
    shiftlinebender2k

    Reply 2 years ago

    Yes it could be done. I also thought of adding a little potentiometer (dial) to adjust it.

    0
    None
    bender2kshiftline

    Reply 2 years ago

    A single button would be nice for teaching the stop (red Flash) distance!

    I got it working using a ATTiny85, its nice.

    One question: The update rate of the LED ring or the ultrasonic module is very slow. (also with an Arduino Nano)

    There is a reaction delay of 1-2s and also a refresh delay of the LEDs. You can see it in the Video. When u go to fast to the module, 3-4LEDs turn on at one time. That's not very smooth.

    Can it be increased/improved?

    0
    None
    shiftlinemsenn77

    Reply 2 years ago

    One may be the top and bottom. I want to make a slightly smoother version of the case.. I will re-post it once updated :)

    0
    None
    xvicente

    2 years ago

    >hanging tennis ball

    Good idea!

    0
    None
    Leemson

    2 years ago

    Is there a cheap Alternative for the neopixel Ring?

    1 reply
    0
    None
    LeemsonLeemson

    Reply 2 years ago

    WS2812B Module Strip 24 Bits 24 X WS2812 5050 RGB LED Ring Lamp Light with Integrated Drivers ws2812 RGB 24 FZ1556

    http://s.aliexpress.com/63eIfiQv

    $3.99 incl. Shipping (Germany)

    0
    None
    WannaDuino

    2 years ago

    i wil make it,

    but on another gpo pin i wil attach an beeper to, from low to hard noise.

    0
    None
    Nextprojectawesome

    2 years ago

    This is a great idea. Well done! Guess I know what Im building Sunday!

    0
    None
    shiftline

    2 years ago

    If you back in! Thanks for the vote :)

    0
    None
    Tecwyn Twmffat

    2 years ago

    I presume you're looking at this gadget in your rear view mirror? A nice simple solution! Gets my votes.