Skip to content
  • MySensors
  • 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

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.
  • 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
      • hekH Online
        hekH Online
        hek
        Admin
        wrote on last edited by
        #21

        Thanks for the feedback, pushed the timeout changes it to github now.

        1 Reply Last reply
        0
        • Dan S.D Dan S.

          @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 Offline
          M Offline
          msebbe
          wrote on last edited by msebbe
          #22

          @Dan-S. I am going to do this but with a rgb led strip instead of a ring.

          1 Reply Last reply
          0
          • Dan S.D Dan S.

            @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?

            TD22057T Offline
            TD22057T Offline
            TD22057
            Hardware Contributor
            wrote on last edited by
            #23

            @Dan-S. said:

            Has anyone done that yet?

            Not yet, but I've got plans, big plans :) - I'm working on a leak detector now but when that board is done, I'm going to build an "ultimate garage" PCB that will have the the parking LED, distance sensor, temp/humidity, garage door location sensors, garage door open/close relay, and will automatically close the garage door after a timeout unless a button is pressed.

            Here's the way I think about the parking problem: the car moves through 3 different areas: 1) entering garage (not safe), 2) safe to park (far enough in, but not too far), 3) danger - too far. But how do you know what sensor values those correspond to? Especially since mounting the sensor in different areas, at different angles, and with different vehicles will change those values. So if you hold down a button on the sensor, it puts it into config mode. Move the car to the start of the safe area, and push the button to record that sensor reading. Then move the car to the end of the safe parking area and push the button again to record that sensor reading. Then have the software dynamically update the LED ranges to respond to those sensors. Something like: in area 1), illuminate more and more LED's as the car moves through the area. When the car hits area 2), flash the ring green 3 times, then fully illuminate all LED's in green. As the car moves through area 2), decrease the number of LED's illuminated until it hits area 3) where all the LED's flash red.

            1 Reply Last reply
            1
            • Dan S.D Dan S.

              @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?

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

              @Dan-S. Would you mind providing a little detail on your build? I'm totally new and having problems trying to figure out a few things

              Do I need a capacitor? If so will 22uf do and where do I hook it up.

              I really just looking for a few detailed pics so I can hook things up correctly

              Thanks

              hekH Dan S.D 2 Replies Last reply
              0
              • F Offline
                F Offline
                FreakOfNature
                wrote on last edited by
                #25

                My brother just bought a house and I am going to sucker him into taking up this project by building this for him. I want to add some gas sensors and would like advice on best ones to add. I want to monitor CO, LPG, Butane, and fumes you would get off regular old automotive gas.

                1 Reply Last reply
                0
                • C chilump

                  @Dan-S. Would you mind providing a little detail on your build? I'm totally new and having problems trying to figure out a few things

                  Do I need a capacitor? If so will 22uf do and where do I hook it up.

                  I really just looking for a few detailed pics so I can hook things up correctly

                  Thanks

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

                  @chilump

                  Yes, a cap on the led ring won't hurt. I soldered mine directly on the ring between GND/VCC. 22uF is probably fine.

                  1 Reply Last reply
                  0
                  • C chilump

                    @Dan-S. Would you mind providing a little detail on your build? I'm totally new and having problems trying to figure out a few things

                    Do I need a capacitor? If so will 22uf do and where do I hook it up.

                    I really just looking for a few detailed pics so I can hook things up correctly

                    Thanks

                    Dan S.D Offline
                    Dan S.D Offline
                    Dan S.
                    Hero Member
                    wrote on last edited by
                    #27

                    @chilump I am moving from the prototype setup to the garage setup. The first picture shows the LED ring connections. I used solid copper wire because it facilitated what I wanted to do. I squeezed the ends of the wire to flatten them and bent them 90 degrees to make it a bit easier to solder to the solder pads on the led ring. The pads are marked D1,5V,GND and D0. D0 is not used in this application. These are the most difficult connections to make.

                    Connections.jpg ```
                    I mounted the ring on a square piece of 1/4 in particle board, drilling holes to feed the wires through. It only has a primer coat on it in the picture.
                    mount1.jpg
                    I will connect a 100uf between the 5v and ground connectors behind the board so it cannot be seen and then mount it on the garage wall.
                    Mount2.jpg
                    Hek's 22uf recommendation is probably good enough, but in reading about led ring applications an the internet 100uf was recommended for Adafruit neopixel rings. How much you need is dependent on the led intensity and how rapidly the signal will be changing--for this case 22uf should be ok.

                    I put the distance sensor in one of the standard cases.
                    distance.jpg

                    As far as wiring to the Arduino is concerned Hek spells all that out on the mysensor home page if you click on parking sensor. DI of the led ring goes to D4 on Arduino, Trig and echo of the distance sensor got to D6 and D5 of the Arduino respectively. Don't wire the led 5V to the Arduino. It should come directly from the power supply since when the leds are full on they can consume more power than the Arduino can supply. I plugged the Vcc and grnd connections from the distance sensor directly into the Ardouino's pins that were so marked. To be on the safe side I plan on using a 5V 2A DC power supply for this application. All grounds must be common.

                    C 2 Replies Last reply
                    1
                    • Dan S.D Dan S.

                      @chilump I am moving from the prototype setup to the garage setup. The first picture shows the LED ring connections. I used solid copper wire because it facilitated what I wanted to do. I squeezed the ends of the wire to flatten them and bent them 90 degrees to make it a bit easier to solder to the solder pads on the led ring. The pads are marked D1,5V,GND and D0. D0 is not used in this application. These are the most difficult connections to make.

                      Connections.jpg ```
                      I mounted the ring on a square piece of 1/4 in particle board, drilling holes to feed the wires through. It only has a primer coat on it in the picture.
                      mount1.jpg
                      I will connect a 100uf between the 5v and ground connectors behind the board so it cannot be seen and then mount it on the garage wall.
                      Mount2.jpg
                      Hek's 22uf recommendation is probably good enough, but in reading about led ring applications an the internet 100uf was recommended for Adafruit neopixel rings. How much you need is dependent on the led intensity and how rapidly the signal will be changing--for this case 22uf should be ok.

                      I put the distance sensor in one of the standard cases.
                      distance.jpg

                      As far as wiring to the Arduino is concerned Hek spells all that out on the mysensor home page if you click on parking sensor. DI of the led ring goes to D4 on Arduino, Trig and echo of the distance sensor got to D6 and D5 of the Arduino respectively. Don't wire the led 5V to the Arduino. It should come directly from the power supply since when the leds are full on they can consume more power than the Arduino can supply. I plugged the Vcc and grnd connections from the distance sensor directly into the Ardouino's pins that were so marked. To be on the safe side I plan on using a 5V 2A DC power supply for this application. All grounds must be common.

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

                      @Dan-S. Thank you very much for taking the time to take pics and write up your project! Can't wait to get home to try.

                      Thanks!!!!

                      @hek Thanks for the info on 22uf and thanks for thinking up this project. Great tool for me and my kids.

                      1 Reply Last reply
                      0
                      • Dan S.D Dan S.

                        @chilump I am moving from the prototype setup to the garage setup. The first picture shows the LED ring connections. I used solid copper wire because it facilitated what I wanted to do. I squeezed the ends of the wire to flatten them and bent them 90 degrees to make it a bit easier to solder to the solder pads on the led ring. The pads are marked D1,5V,GND and D0. D0 is not used in this application. These are the most difficult connections to make.

                        Connections.jpg ```
                        I mounted the ring on a square piece of 1/4 in particle board, drilling holes to feed the wires through. It only has a primer coat on it in the picture.
                        mount1.jpg
                        I will connect a 100uf between the 5v and ground connectors behind the board so it cannot be seen and then mount it on the garage wall.
                        Mount2.jpg
                        Hek's 22uf recommendation is probably good enough, but in reading about led ring applications an the internet 100uf was recommended for Adafruit neopixel rings. How much you need is dependent on the led intensity and how rapidly the signal will be changing--for this case 22uf should be ok.

                        I put the distance sensor in one of the standard cases.
                        distance.jpg

                        As far as wiring to the Arduino is concerned Hek spells all that out on the mysensor home page if you click on parking sensor. DI of the led ring goes to D4 on Arduino, Trig and echo of the distance sensor got to D6 and D5 of the Arduino respectively. Don't wire the led 5V to the Arduino. It should come directly from the power supply since when the leds are full on they can consume more power than the Arduino can supply. I plugged the Vcc and grnd connections from the distance sensor directly into the Ardouino's pins that were so marked. To be on the safe side I plan on using a 5V 2A DC power supply for this application. All grounds must be common.

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

                        @Dan-S. Can a single 5v 2a adapter be used? In that case would everything be wired to the single power adapter?

                        Dan S.D mjbokM 2 Replies Last reply
                        0
                        • C chilump

                          @Dan-S. Can a single 5v 2a adapter be used? In that case would everything be wired to the single power adapter?

                          Dan S.D Offline
                          Dan S.D Offline
                          Dan S.
                          Hero Member
                          wrote on last edited by
                          #30

                          @chilump I hope so since that's exactly how I intend to use it. I will wire the arduino and the led ring directly (and separately ) to the adaptor. I don't want to have to deal with 2 separate power supplies.

                          C 1 Reply Last reply
                          1
                          • Dan S.D Dan S.

                            @chilump I hope so since that's exactly how I intend to use it. I will wire the arduino and the led ring directly (and separately ) to the adaptor. I don't want to have to deal with 2 separate power supplies.

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

                            @Dan-S. Thanks for the guidance! Looking forward to getting it working

                            1 Reply Last reply
                            0
                            • L Offline
                              L Offline
                              leothlon
                              wrote on last edited by
                              #32

                              This is looking great!
                              But i'm not seeing any "sleeping" is there anyway to have this using the external interrupts on the arduino so it can be running on battery?
                              ( sorry if i'm mistaken, i'm new to arduino :D )

                              korttomaK 1 Reply Last reply
                              0
                              • L leothlon

                                This is looking great!
                                But i'm not seeing any "sleeping" is there anyway to have this using the external interrupts on the arduino so it can be running on battery?
                                ( sorry if i'm mistaken, i'm new to arduino :D )

                                korttomaK Offline
                                korttomaK Offline
                                korttoma
                                Hero Member
                                wrote on last edited by
                                #33

                                @leothlon that LED ring would burn through your batteries quite fast.

                                • Tomas
                                L 1 Reply Last reply
                                0
                                • korttomaK korttoma

                                  @leothlon that LED ring would burn through your batteries quite fast.

                                  L Offline
                                  L Offline
                                  leothlon
                                  wrote on last edited by
                                  #34

                                  @korttoma
                                  Even if it's only active for about 3-4minutes per day?
                                  The problem is i got no way of getting power to where i want to place it.
                                  And also if i did it would have to be something like 230V to usb adapter.
                                  And plugging one of those in outside seems like a fire hazzard (even indoors they are known to start fires).

                                  What if i hook it up to a small solar panel to charge the batteries?

                                  Otherwise i guess i'll just have to stick with the old tennisball on a string method :D

                                  korttomaK 1 Reply Last reply
                                  0
                                  • L leothlon

                                    @korttoma
                                    Even if it's only active for about 3-4minutes per day?
                                    The problem is i got no way of getting power to where i want to place it.
                                    And also if i did it would have to be something like 230V to usb adapter.
                                    And plugging one of those in outside seems like a fire hazzard (even indoors they are known to start fires).

                                    What if i hook it up to a small solar panel to charge the batteries?

                                    Otherwise i guess i'll just have to stick with the old tennisball on a string method :D

                                    korttomaK Offline
                                    korttomaK Offline
                                    korttoma
                                    Hero Member
                                    wrote on last edited by
                                    #35

                                    @leothlon I'm not saying it can not be done but according to the datasheet the LED chip can consume up to 20mA ( http://www.adafruit.com/datasheets/WS2812.pdf ). So with 24 of them you will be looking at almost 500mA for just the LEDs.

                                    http://ncalculators.com/electrical/battery-life-calculator.htm

                                    btw, there is another thread about safe AC DC transformers here

                                    • Tomas
                                    Dan S.D 1 Reply Last reply
                                    0
                                    • korttomaK korttoma

                                      @leothlon I'm not saying it can not be done but according to the datasheet the LED chip can consume up to 20mA ( http://www.adafruit.com/datasheets/WS2812.pdf ). So with 24 of them you will be looking at almost 500mA for just the LEDs.

                                      http://ncalculators.com/electrical/battery-life-calculator.htm

                                      btw, there is another thread about safe AC DC transformers here

                                      Dan S.D Offline
                                      Dan S.D Offline
                                      Dan S.
                                      Hero Member
                                      wrote on last edited by
                                      #36

                                      @korttoma The online documentation I read said:

                                      "The pin labeled PWR +5V is the power input pin, and should be connected to a suitable power supply. An input voltage of 5 V is used to power the ring, and each LED on the ring can draw up to 50 mA at 5 V when outputting white at full brightness. That means the ring could draw up to a maximum of around 1.2 A."

                                      Although Hek's code does not operate all the pixels at full white brightness, I decided to play extra safe and use a 2A supply.

                                      korttomaK 1 Reply Last reply
                                      0
                                      • Dan S.D Dan S.

                                        @korttoma The online documentation I read said:

                                        "The pin labeled PWR +5V is the power input pin, and should be connected to a suitable power supply. An input voltage of 5 V is used to power the ring, and each LED on the ring can draw up to 50 mA at 5 V when outputting white at full brightness. That means the ring could draw up to a maximum of around 1.2 A."

                                        Although Hek's code does not operate all the pixels at full white brightness, I decided to play extra safe and use a 2A supply.

                                        korttomaK Offline
                                        korttomaK Offline
                                        korttoma
                                        Hero Member
                                        wrote on last edited by
                                        #37

                                        @Dan-S. Yeah I'm sure thats true. Please post a link to the documentation if you can find it. Anyhow I guess we can agree that running this device on batteries would be difficult.

                                        • Tomas
                                        Dan S.D L 2 Replies Last reply
                                        0
                                        • korttomaK korttoma

                                          @Dan-S. Yeah I'm sure thats true. Please post a link to the documentation if you can find it. Anyhow I guess we can agree that running this device on batteries would be difficult.

                                          Dan S.D Offline
                                          Dan S.D Offline
                                          Dan S.
                                          Hero Member
                                          wrote on last edited by
                                          #38

                                          @korttoma link text

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          15

                                          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
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular