Skip to content
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. My Project
  3. Parking Sensor
  • Getting Started
  • Controller
  • Build
  • Hardware
  • Download/API
  • Forum
  • Store

Parking Sensor

Scheduled Pinned Locked Moved My Project
74 Posts 28 Posters 45.0k Views 18 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • hekH Online
    hekH Online
    hek
    Admin
    wrote on last edited by hek
    #1

    I've created a parking sensor of my NeoPixel led ring and a distance sensor.
    You can also send the parking status to your controller if you'd like.

    Components
    http://www.ebay.com/itm/371353140878?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT
    http://www.ebay.com/itm/1pcs-Ultrasonic-Module-HC-SR04-Distance-Measuring-Transducer-Sensor-for-Arduino-/251546073420?hash=item3a9150794c

    https://youtu.be/ykfTKI7a-H4

    Code:
    https://codebender.cc/sketch:138368

    RJ_MakeR 1 Reply Last reply
    10
    • hekH Online
      hekH Online
      hek
      Admin
      wrote on last edited by
      #2

      Video added

      Moshe LivneM 1 Reply Last reply
      0
      • hekH hek

        I've created a parking sensor of my NeoPixel led ring and a distance sensor.
        You can also send the parking status to your controller if you'd like.

        Components
        http://www.ebay.com/itm/371353140878?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT
        http://www.ebay.com/itm/1pcs-Ultrasonic-Module-HC-SR04-Distance-Measuring-Transducer-Sensor-for-Arduino-/251546073420?hash=item3a9150794c

        https://youtu.be/ykfTKI7a-H4

        Code:
        https://codebender.cc/sketch:138368

        RJ_MakeR Offline
        RJ_MakeR Offline
        RJ_Make
        Hero Member
        wrote on last edited by
        #3

        @hek That is awesome!

        RJ_Make

        1 Reply Last reply
        0
        • scalzS Offline
          scalzS Offline
          scalz
          Hardware Contributor
          wrote on last edited by
          #4

          Excellent!

          1 Reply Last reply
          0
          • hekH hek

            Video added

            Moshe LivneM Offline
            Moshe LivneM Offline
            Moshe Livne
            Hero Member
            wrote on last edited by
            #5

            @hek Ultra cool!!!!

            1 Reply Last reply
            0
            • DrJeffD Offline
              DrJeffD Offline
              DrJeff
              wrote on last edited by
              #6

              @hek Cool I figured you would come up with a practicle use for that LED ring! :smile:

              1 Reply Last reply
              0
              • TD22057T Offline
                TD22057T Offline
                TD22057
                Hardware Contributor
                wrote on last edited by
                #7

                OK - that is very cool. My wife has just decided we have to have this (after she lightly crushed one of my garage cabinets of course).

                1 Reply Last reply
                0
                • mikeeM Offline
                  mikeeM Offline
                  mikee
                  wrote on last edited by
                  #8

                  Really cool project, I´m ordering today :)

                  1 Reply Last reply
                  0
                  • rvendrameR Offline
                    rvendrameR Offline
                    rvendrame
                    Hero Member
                    wrote on last edited by
                    #9

                    awesome!

                    Home Assistant / Vera Plus UI7
                    ESP8266 GW + mySensors 2.3.2
                    Alexa / Google Home

                    1 Reply Last reply
                    0
                    • Sander StolkS Offline
                      Sander StolkS Offline
                      Sander Stolk
                      wrote on last edited by
                      #10

                      Awesome project but will the led always be on when your car is parked?
                      Or is there a timeout after the measurement to switch it of?

                      hekH 1 Reply Last reply
                      0
                      • Sander StolkS Sander Stolk

                        Awesome project but will the led always be on when your car is parked?
                        Or is there a timeout after the measurement to switch it of?

                        hekH Online
                        hekH Online
                        hek
                        Admin
                        wrote on last edited by
                        #11

                        @Sander-Stolk

                        Ha, yes, didn't think of that little detail.

                        Guess you could add a timeout which turns off the leds after a minute when "parked".

                        1 Reply Last reply
                        0
                        • Lawrence HelmL Offline
                          Lawrence HelmL Offline
                          Lawrence Helm
                          wrote on last edited by
                          #12

                          @hek About to make this sensor, very cool! I had already brought a 12v traffic light before I saw this, so now ordered an LED ring, as that makes a lot more sense getting closer to the target area. But could you help out regarding the implementation of the timeout, as I'm pretty terrible at programing :)

                          C 1 Reply Last reply
                          1
                          • R Offline
                            R Offline
                            ramarro
                            wrote on last edited by
                            #13

                            Super :+1: :clap:

                            1 Reply Last reply
                            0
                            • T Offline
                              T Offline
                              the_iman
                              wrote on last edited by
                              #14

                              Great! This will be my first project with Arduino!
                              Could you, please, post the wiring schematics.
                              Thanks!

                              1 Reply Last reply
                              0
                              • hekH Online
                                hekH Online
                                hek
                                Admin
                                wrote on last edited by
                                #15

                                http://www.mysensors.org/build/parking

                                1 Reply Last reply
                                1
                                • Lawrence HelmL Lawrence Helm

                                  @hek About to make this sensor, very cool! I had already brought a 12v traffic light before I saw this, so now ordered an LED ring, as that makes a lot more sense getting closer to the target area. But could you help out regarding the implementation of the timeout, as I'm pretty terrible at programing :)

                                  C Offline
                                  C Offline
                                  chilump
                                  wrote on last edited by
                                  #16

                                  @hek Great Job. Just wondering if you could point us to instructions on to add the time out feature.

                                  Thanks!

                                  1 Reply Last reply
                                  0
                                  • hekH Online
                                    hekH Online
                                    hek
                                    Admin
                                    wrote on last edited by
                                    #17

                                    My rig is disassembled now.

                                    You could add timeout like this (please feedback if it works so I can check it into github):

                                    /**
                                     * 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 <henrik.ekblad@mysensors.org>
                                     * 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 <Adafruit_NeoPixel.h>
                                    #include <NewPing.h>
                                    
                                    #ifdef SEND_STATUS_TO_CONTROLLER
                                    #include <SPI.h>
                                    #include <MySensor.h>
                                    #endif
                                    
                                    #define NEO_PIN      4 // NeoPixels input pin
                                    
                                    #define TRIGGER_PIN  6  // Arduino pin tied to trigger pin on the ultrasonic sensor.
                                    #define ECHO_PIN     5  // 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 5 // Mix distance we red warning indication should be active (in cm)
                                    #define PARKED_DISTANCE 20 // 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_KHZ400);
                                    
                                    NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
                                    
                                    #ifdef SEND_STATUS_TO_CONTROLLER
                                    #define CHILD_ID 1
                                    MySensor gw;
                                    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(115200);
                                      Serial.println("Starting distance sensor");
                                      pixels.begin(); // This initializes the NeoPixel library.
                                      Serial.println("Neopixels initialized");
                                    #ifdef SEND_STATUS_TO_CONTROLLER
                                      gw.begin();
                                      gw.sendSketchInfo("Parking Sensor", "1.0");
                                      gw.present(CHILD_ID, S_DOOR, "Parking Status");
                                    #endif
                                    }
                                    
                                    void loop() {
                                      unsigned long now = millis();
                                      
                                      int fullDist = sonar.ping_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<PARKED_DISTANCE;
                                        if (parked != oldParkedStatus && now-lastSend > sendInterval) {
                                          if (parked)
                                            Serial.println("Car Parked");
                                          else
                                            Serial.println("Car Gone");
                                    #ifdef SEND_STATUS_TO_CONTROLLER
                                          gw.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;i<NUMPIXELS;i++){
                                            pixels.setPixelColor(i, pixels.Color(0,0,0)); 
                                          }
                                        } else {
                                          if (displayDist == 0) {
                                            // No reading from sensor, assume no object found
                                            numLightPixels--;
                                          } else {
                                            skipZero = 0;
                                            int newLightPixels = NUMPIXELS - (NUMPIXELS*(displayDist-PANIC_DISTANCE)/MAX_DISTANCE);
                                            if (newLightPixels>numLightPixels) {
                                              // Fast raise
                                              numLightPixels += max((newLightPixels - numLightPixels) / 2, 1);
                                            } else if (newLightPixels<numLightPixels) {
                                              // Slow decent
                                              numLightPixels--;
                                            }
                                          }
                                      
                                          if (numLightPixels>=NUMPIXELS) {
                                            // Do some intense red blinking 
                                            if (now-lastBlinkPeriod > blinkInterval) {
                                              blinkColor = !blinkColor;
                                              lastBlinkPeriod = now;
                                            }
                                            for(int i=0;i<numLightPixels;i++){
                                              pixels.setPixelColor(i, pixels.Color(blinkColor?255*MAX_INTESITY/100:0,0,0)); 
                                            }              
                                          } else {
                                            for(int i=0;i<numLightPixels;i++){
                                              int r = 255 * i/NUMPIXELS;
                                              int g = 255 - r;     
                                              // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
                                              pixels.setPixelColor(i, pixels.Color(r*MAX_INTESITY/100,g*MAX_INTESITY/100,0)); 
                                            }
                                            // Turn off the rest
                                            for(int i=numLightPixels;i<NUMPIXELS;i++){
                                              pixels.setPixelColor(i, pixels.Color(0,0,0)); 
                                            }
                                          }
                                        }
                                        pixels.show(); // This sends the updated pixel color to the hardware.
                                      }
                                    }
                                    
                                    Dan S.D 1 Reply Last reply
                                    0
                                    • C Offline
                                      C Offline
                                      chilump
                                      wrote on last edited by
                                      #18

                                      Definitely, thanks

                                      1 Reply Last reply
                                      0
                                      • Andy PepA Offline
                                        Andy PepA Offline
                                        Andy Pep
                                        wrote on last edited by
                                        #19

                                        change the code a little bit and bingo you just made a light thermin .. cool for wearables :)

                                        1 Reply Last reply
                                        0
                                        • hekH hek

                                          My rig is disassembled now.

                                          You could add timeout like this (please feedback if it works so I can check it into github):

                                          /**
                                           * 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 <henrik.ekblad@mysensors.org>
                                           * 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 <Adafruit_NeoPixel.h>
                                          #include <NewPing.h>
                                          
                                          #ifdef SEND_STATUS_TO_CONTROLLER
                                          #include <SPI.h>
                                          #include <MySensor.h>
                                          #endif
                                          
                                          #define NEO_PIN      4 // NeoPixels input pin
                                          
                                          #define TRIGGER_PIN  6  // Arduino pin tied to trigger pin on the ultrasonic sensor.
                                          #define ECHO_PIN     5  // 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 5 // Mix distance we red warning indication should be active (in cm)
                                          #define PARKED_DISTANCE 20 // 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_KHZ400);
                                          
                                          NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
                                          
                                          #ifdef SEND_STATUS_TO_CONTROLLER
                                          #define CHILD_ID 1
                                          MySensor gw;
                                          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(115200);
                                            Serial.println("Starting distance sensor");
                                            pixels.begin(); // This initializes the NeoPixel library.
                                            Serial.println("Neopixels initialized");
                                          #ifdef SEND_STATUS_TO_CONTROLLER
                                            gw.begin();
                                            gw.sendSketchInfo("Parking Sensor", "1.0");
                                            gw.present(CHILD_ID, S_DOOR, "Parking Status");
                                          #endif
                                          }
                                          
                                          void loop() {
                                            unsigned long now = millis();
                                            
                                            int fullDist = sonar.ping_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<PARKED_DISTANCE;
                                              if (parked != oldParkedStatus && now-lastSend > sendInterval) {
                                                if (parked)
                                                  Serial.println("Car Parked");
                                                else
                                                  Serial.println("Car Gone");
                                          #ifdef SEND_STATUS_TO_CONTROLLER
                                                gw.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;i<NUMPIXELS;i++){
                                                  pixels.setPixelColor(i, pixels.Color(0,0,0)); 
                                                }
                                              } else {
                                                if (displayDist == 0) {
                                                  // No reading from sensor, assume no object found
                                                  numLightPixels--;
                                                } else {
                                                  skipZero = 0;
                                                  int newLightPixels = NUMPIXELS - (NUMPIXELS*(displayDist-PANIC_DISTANCE)/MAX_DISTANCE);
                                                  if (newLightPixels>numLightPixels) {
                                                    // Fast raise
                                                    numLightPixels += max((newLightPixels - numLightPixels) / 2, 1);
                                                  } else if (newLightPixels<numLightPixels) {
                                                    // Slow decent
                                                    numLightPixels--;
                                                  }
                                                }
                                            
                                                if (numLightPixels>=NUMPIXELS) {
                                                  // Do some intense red blinking 
                                                  if (now-lastBlinkPeriod > blinkInterval) {
                                                    blinkColor = !blinkColor;
                                                    lastBlinkPeriod = now;
                                                  }
                                                  for(int i=0;i<numLightPixels;i++){
                                                    pixels.setPixelColor(i, pixels.Color(blinkColor?255*MAX_INTESITY/100:0,0,0)); 
                                                  }              
                                                } else {
                                                  for(int i=0;i<numLightPixels;i++){
                                                    int r = 255 * i/NUMPIXELS;
                                                    int g = 255 - r;     
                                                    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
                                                    pixels.setPixelColor(i, pixels.Color(r*MAX_INTESITY/100,g*MAX_INTESITY/100,0)); 
                                                  }
                                                  // Turn off the rest
                                                  for(int i=numLightPixels;i<NUMPIXELS;i++){
                                                    pixels.setPixelColor(i, pixels.Color(0,0,0)); 
                                                  }
                                                }
                                              }
                                              pixels.show(); // This sends the updated pixel color to the hardware.
                                            }
                                          }
                                          
                                          Dan S.D Offline
                                          Dan S.D Offline
                                          Dan S.
                                          Hero Member
                                          wrote on last edited by
                                          #20

                                          @hek Received my LED ring in the mail over the weekend. Hooked it up and ran your code. Everything looks to be working great, including the timeout code. Now need to mount and test under real world conditions, i.e,. in the garage with the car. Has anyone done that yet?

                                          M TD22057T C 3 Replies Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          19

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.0k

                                          Posts


                                          Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular