Parking Sensor

  • 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.

  • Admin


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

  • Hero Member

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

    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.

  • @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.


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

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

  • Hero Member

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

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

  • 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 ๐Ÿ˜„ )

  • Hero Member

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

  • @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 ๐Ÿ˜„

  • Hero Member

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

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

  • Hero Member

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

  • Hero Member

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

  • Hero Member

  • @korttoma
    Yea from my calculations i would need to change batteries about once a month.
    And with the amount of sun here in sweden i don't think solar charger would help much sadly.

  • Admin

    But isn't the distance sensor rather power hungry as well?

    The dist-sensor but be awake all the time taking measurements (which needs to be interpreted by the MCU).. so sleep mode is not an option on this.

  • Contest Winner

    @hek said:

    But isn't the distance sensor rather power hungry as well?

    You could wake it with a reed switch attached to the garage door...

    door open, sense and display until steady state and go to sleep on a timeout or door closed interrupt

  • Hardware Contributor

    @BulldogLowell said:

    You could wake it with a reed switch attached to the garage door...

    door open, sense and display until steady state and go to sleep on a timeout or door closed interrupt

    I like that idea. I was planning on having garage door sensors tied in with this anyway. FYI here is a link to the ultrasonic module docs which list 15mA as the current draw.

  • Hero Member

    Just to add my two cents, as I have a window nearby, I'm planning to run my parking sensor with a solar battery bank, like this one.

    I'm waiting for the ring now. It is the last piece missing ๐Ÿ˜‰

  • This was fun to build ๐Ÿ™‚

    However, my HC-SR04 is making a high pitch sound when distance is close and a more static sound when distance is further. I have tried with 3 different modules and 2 different Nanos and 2 different power sources. Is this normal?

  • Hero Member

    @msebbe It's normal for a ๐Ÿถ or a bat. ๐Ÿ˜† Either you have really good hearing, or there's something wrong with your HC-SR04. The ultrasound is supposed to be well above human hearing range (40 KHz). My HC-SR04 is quiet and I don't hear any sound from it.

  • Contest Winner


    building on @Sparkman , perhaps it is some kind of resonance... something attached with a natural frequency that is excited by the vibrations of the speaker.

  • Admin


    I could hear mine as well when being close to it.

  • @Sparkman

    It is correct that I have really good hearing.. But if I use the distance sensor sketch the HC-SR04 is not making any sound at all, first now with this sketch I hear it. Could it have something to do with the LED-strip I got from china?

  • Hero Member

    Was checking out operation of parking sensor after changing MAX_Distance to 200 from original 100--wanted earlier start from wall. Also changed the Panic distance to 60--more space from wall during testing. Noticed that the led ring did not start from 1 pixel and increase from there as the distance closed. It started at 7 lit pixels. Examined the formula for newLightPixels and made a change which corrected this.

    The current newLightPixels formula is:

    int newLightPixels = NUMPIXELS - (NUMPIXELS*(displayDist-PANIC_DISTANCE)/MAX_DISTANCE);

    The portion of the newLightPixels formula (displayDist-PANIC_DISTANCE)/MAX_DISTANCE) is intended to map the interval between PANIC_DISTANCE and MAX_DISTANCE to the interval (0,1). In other words, when you are at the PANIC_DISTANCE it should calculate to 0 and when you are at MAX_DISTANCE it should calculate to 1, advancing linearly between the two values as the distance closes and vice versa. Clearly when a displayDist = PANIC_DISTANCE, the numerator of the division of the formula calculates to 0. However when displayDist = MAX_DISTANCE, it does not calculate to 1.

    In order to correct this I changed the portion of the formula to:
    Note the only difference is subtracting the PANIC_DISTANCE from the MAX_DISTANCE in the denominator. Now when the displayDist = MAX_DISTANCE, the formula returns the value 1. So the proposed new newLightPixels formula is:


    I tested it both by plugging values into the formula and in operation of the Parking Sensor. Now the leds climb smoothly from 0 as you enter the MAX_DISTANCE zone. rather than starting at some number other than 1 (7 in my case).

  • Cool, I had this happen as well, so great fix! Now all I need it to do is talk to domoticz, not picking it up yet... ๐Ÿ™‚

  • Hero Member

    Have one more proposed change to parking sensor code. Noticed that even when I was standing still there seemed to be quite a few changes in number of leds lit. In checking the internet, learned that variability of distance readings was particularly a problem for those using the sensor in robots. The preferred solution seemed to be taking the median of several readings.

    Fortunately, the Newping library has a built in function to address this issue by taking the median of several readings (default = 5). So I modified the code as follows:

    // int fullDist = sonar.ping_cm(); original code
    unsigned int fullDist = (sonar.ping_median() / US_ROUNDTRIP_CM);
    // Get average distance for 5 pings, convert to cm
    // US_ROUNDTRIP_CM = distance sound travels in cm/sec

    As a result, the jumping around of the number of leds appears to have decreased significantly and the response is much more stable. Hope this helps others.

  • @Dan-S. Thanks for your investigation! I made the changes and it seems to work well!

    About the high pitch sound I mentioned earlier; I changed NEO_KHZ400.

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



    This removed the annoying high pitch sound ๐Ÿ˜„

  • Hero Member

    @msebbe Glad everything worked out well for you. Your comment made me think about changing mine to 800 also. From what I could glean from looking on the internet, 800 is more appropriate for newer devices, e.g., the led ring. So I am going to change to 800 also. Thanks.

  • Just built this with my 4 year old. She loved it! She did the project management and directed me which wire goes where. Got to start them young!

    I was really shocked at the brightness of the LED ring. I mean, I knew it would be bright from looking at the videos, but wow.

    My setup was to connect my UNO to the PC, load code and branch power directly from the UNO's 5v pin. I had no cap or resistor in place either (neither was there a radio hooked-up). This was just a bench-top proof of concept and it worked right out the box (after I soldered leads to the ring). I went through all the adafruit example codes and worked without a hitch. I may, or may not, exceeded WAF level 10. Now she is giving me more projects for these "neopixel" lights.

  • Admin

    My girls like liked the neopixels as well ๐Ÿ˜‰

  • Hero Member

    Had some issues with the operation of my parking sensor which I resolved and now it seems to be working perfectly.
    Thought I would pass on what I did in the hope that it might help others having the same problem.

    There were 2 issues.

    The first issue was random lighting of the led ring after the car was pulled out of the garage and the door was closed. My guess was that the sensor, in the absence of having the solid car to bounce off of, was picking up stray sensor ping echoes from other objects in the garage. Checking on internet revealed that others using the HC-SR04 Distance sensor had experienced this problem. Checking further, I discovered that there were updates to the NewPing library, the latest being version V1.7 and specifically that V1.6 included an update to the sonar.ping_median function used for distance measurement in the parking sensor code. The MySensors library current version is V1.5. After I updated to V1.7 I no longer had random readings when the car was not in the garage. First problem solved.
    bolded textSo I would recommend updating to NewPing V1.7.

    I then reinstalled the parking sensor in the garage for further testing. Everything appeared to be going well but when I returned to park my car in the garage later in the day I was greeting by the led ring flashing bright red with all its leds which is supposed to be a panic signal that the car was parked as close as it should be. But I had just entered the garage and was not anywhere near the range of being parked. Took the sensor down and brought it in for testing. Found out that everything worked fine except if it was left on in the condition where it was not sensing any object in range for an extended period of time, it went into the flashing led mode. Too me it had the symptom that given enough time, a variable was being overrun (an integer variable exceeding its capacity). Checking over the code I noted the following lines:

    if (displayDist == 0) {
    // No reading from sensor, assume no object found

    So everytime the displayDist = zero (and it is zero when no object is detected) numLightPixels is decremented by 1. So if there is no car in the garage (and since I had fixed the random detection problem), the sensor returns a steady stream of zeros to indicate there is no car in the garage and the numLightPixels is decremented with no limit. Given enough time it will eventually decrement to -32,768 at which point it rolls over to +32,767 and at that point the red leds will all flash in the panic mode. To fix this, I changed the above code to read:

    if (displayDist == 0) {
    // No reading from sensor, assume no object found
    //Make sure you donโ€™t go below zero
    if (numLightPixels>0) {

    So now it wonโ€™t decrement numLightPixels below 0. That solved the problem.

    There is also one related efficiency change I made. At the beginning of the loop there is code to skip 10 zero readings:

    if (displayDist == 0 && skipZero<10) {
    // Try to filter zero readings

    I changed that code to skip all zero readings if numLightPixels is less the one (i.e., 0), since if numLightPixels is at zero all of the pixels are already off and if the sensor continues to read zeroes, they should all be skipped (donโ€™t go through the rest of the loop) until a nonzero reading is obtained (something is found).

    if (displayDist == 0 && numLightPixels<1) {
    // Filter zero readings

    Mounted the sensor in the garage again and now everything works perfectly. Hope this helps someone else.

  • Haven't had the chance to put this in the garage yet, but awesome work!

  • This sketch doesn't support MQTT right? Has anyone maybe a version of this sketch which outputs MQTT? Or could you guys maybe guide me on how I would do it?

  • Hardware Contributor

    @msev said:

    This sketch doesn't support MQTT right? Has anyone maybe a version of this sketch which outputs MQTT? Or could you guys maybe guide me on how I would do it?

    MySensors uses radios to communicate with a gateway over RF. The gateway can be set up to convert those messages to/from MQTT (or use software to convert the serial messages to/from MQTT). So there aren't going to be any sensor sketches with MQTT in them. If you use an ESP, then you could send MQTT directly but then you're on WIFI and don't need MySensors.

  • I meant for the esp8266.

    @TD22057 said:

    @msev said:

    This sketch doesn't support MQTT right? Has anyone maybe a version of this sketch which outputs MQTT? Or could you guys maybe guide me on how I would do it?

    MySensors uses radios to communicate with a gateway over RF. The gateway can be set up to convert those messages to/from MQTT (or use software to convert the serial messages to/from MQTT). So there aren't going to be any sensor sketches with MQTT in them. If you use an ESP, then you could send MQTT directly but then you're on WIFI and don't need MySensors.

  • Admin

    Should work, start with the MQTT ESP gateway (in development branch) and copy the relevant parts from the parking sensor example.

  • @hek I'll try, then I'll show the sketch for fixing mistakes :D...Also Newping library doesn't work on ESP, so I'll have to use Ultrasonic library. ๐Ÿ˜•

  • @chilump Do you have a picture of your final product (or a wiring schematic)? I just discovered this project and don't want to reinvent the wheel.

  • Hero Member

    The wiring should be quite strait forward and mentioned in form of comments in the sketch:

    #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.

    Basically pin 4 on the arduino goes to the input pin on the NeoPixel LED ring

    The distance sensor is also described here ->

    Is there something else that is not clear how it should be connected?

  • @korttoma This is a total newb question, but it is all about the power. I've done stuff with Pi's before, but this is my first foray into the arudino world. Everything I've read says to power the ring apart from the Arduino (don't use the 5v pin). I am going to use an Uno and I thought I could get a 9v 2a wart and power the board through the barrel connector, using a regulator jumpered off the wart before the board to step down to 5v. However this is all guess work on my part. I figured people have done this, if I saw a finished product I could figure out the rest myself. Thanks for the help.

  • Hero Member

    @mjbok yeah, there is some discussion earlier in this tread about the current consumption of the LED ring and there is no way any 5V pin on the Arduino can deliver the current needed so yes a separate voltage regulator from a 9V wart sounds like a good plan. Just make sure you have common GROUND and some capacitors to filter out disturbance.

    btw, I found an article about powering NeoPixels here ->

  • @korttoma I plan to do something like this (quick and dirty with MSpaint). I've ordered all my parts, now just wait.

    0_1464757950042_parking sensor.jpg

  • Hero Member

    Yeah, that's how I would do it also, just make sure your 5V regulator can handle enough current.

  • Has anyone done this project without the neopixel? I am looking to use one or more LEDs to simulate... maybe green yellow red.

    I tried to start peeling off the neopixel sections, but ended up ruining the sketch.

    Care to share the code for the non-nepixel model?


  • Hey There, I'm getting ready to play around with this once a few more parts arrive to give me ideas on other potential uses for distance sensor and LEDs, but one thing i'm confused about.

    The sketch mentioned using pins 4, 5 and 6.

    Adafruit and all docs i've seen and played around with mention that neopixels need a PWM pin to operate.

    Pin 4 doesn't appear to be PWM (on pro mini)

    I see that trig and echo are typically wired to 5 & 6 in most cases which are PWM.
    so in short, not enough PWM pins .

    Are the neopixels still working because the signal is being sent at "full" brightness?

  • Hero Member

    Unlike the dumb rgb strips neopixels don't need a pwm pin to dim and mix colours. Each rgb led has its own controller chip.

  • MySensors Evangelist

    Received all the parts let's see if we can build a working 2.0.0 solution ๐Ÿ˜‰

  • Here a working example with a 16-Bit ring with radio because the misses hit the fence for the second time this year with the car.
    alt text
    alt text
    alt text
    Sensor in action <--Video

  • Admin

    Wooo, cool to see it live!

Log in to reply

Suggested Topics

  • 5
  • 4
  • 4
  • 6
  • 17
  • 6
  • 3
  • 1