Overview
Use the FunHouse and an ultrasonic distance sensor to assist you when parking your vehicle in your garage or other permanent parking space.
This project uses the FunHouse to read a distance sensor and then guide the driver with colored LEDs and sounds!
Page last edited March 08, 2024
Text editor powered by tinymce.
Build the FunHouse Parking Assistant
You'll use the three JST PH 3-Pin ports on the FunHouse to control the ultrasonic distance sensor and the NeoPixel strip.
Cable Prep
The distance sensor uses power, ground, a digital output (to control pings), and a digital input (to read the signal). You can wire these four connections by using two of the JST ports.
Prep two of the cables by removing the ground from one and the power from the other as shown. Pry up the plastic tab holding the crimp connector and then slide the wire out of the housing.
Alternately, you can simply leave the extra two wires in place and simple insulate their ends to prevent accidental shorting.
You can plug the sensor into the JST cables directly, or use extension cables to connect the JST wires to the ultrasonic sensor as shown here:
You're now ready to code the FunHouse Parking Assistant using CircuitPython.
Page last edited March 08, 2024
Text editor powered by tinymce.
Code the FunHouse Parking Assistant
Install CircuitPython
The first thing to do is install CircuitPython on your Funhouse. Follow this guide to get it set up with the latest release version.
Text Editor
Adafruit recommends using the Mu editor for using your CircuitPython code with the Funhouse. You can get more info in this guide.
Shhhh... Secrets
In order for the Funhouse to connect to the internet, you'll need to include a secrets.py file on the board that contains your WiFi access point ssid and password, as well as your AIO key.
Follow this guide page to get your secrets.py file set up.
Download the Project Bundle
Your project will use a specific set of CircuitPython libraries and the code.py file. In order to get the libraries you need, click on the Download Project Bundle link below, and uncompress the .zip file.
# SPDX-FileCopyrightText: Copyright (c) 2021 John Park for Adafruit
#
# SPDX-License-Identifier: MIT
# FunHouse Parking Assistant
import time
import board
import adafruit_hcsr04
import neopixel
from adafruit_funhouse import FunHouse
SLOW_DISTANCE = 30 # distance (in centimeters) when you should slow
STOP_DISTANCE = 8 # distance when you should hit those brakes
GREEN = 0x00FF00
AMBER = 0xF0D000
RED = 0xFF0000
funhouse = FunHouse(default_bg=None, scale=3)
funhouse.peripherals.dotstars.brightness = 0.05
funhouse.peripherals.dotstars.fill(GREEN)
pixel_pin = board.A2
num_pixels = 30
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.3, auto_write=False)
sonar = adafruit_hcsr04.HCSR04(trigger_pin=board.A0, echo_pin=board.A1)
while True:
try:
print((sonar.distance,))
if sonar.distance > SLOW_DISTANCE:
funhouse.peripherals.dotstars.fill(GREEN)
pixels.fill(GREEN)
pixels.show()
elif sonar.distance < SLOW_DISTANCE and sonar.distance > STOP_DISTANCE:
funhouse.peripherals.dotstars.fill(AMBER)
pixels.fill(AMBER)
pixels.show()
funhouse.peripherals.play_tone(1000, 0.3)
elif sonar.distance < STOP_DISTANCE:
funhouse.peripherals.dotstars.fill(RED)
pixels.fill(RED)
pixels.show()
funhouse.peripherals.play_tone(2600, 0.3)
except RuntimeError:
print("Retrying!")
time.sleep(0.01)
Next, drag the contents of the uncompressed bundle directory onto you microcontroller board CIRCUITPY drive, replacing any existing files or directories with the same names, and adding any new ones that are necessary.
First, you'll load the necessary libraries, including adafruit_hcsr04 for using the ultrasonic distance sensor.
import time import board import adafruit_hcsr04 import neopixel from adafruit_funhouse import FunHouse
Variables
Next, you'll set variables for the distance thresholds, in centimeters. You can adjust these as necessary for your particular garage/parking space and vehicle.
SLOW_DISTANCE = 30 # distance (in centimeters) when you should slow STOP_DISTANCE = 8 # distance when you should hit those brakes
GREEN = 0x00FF00 AMBER = 0xF0D000 RED = 0xFF0000 funhouse = FunHouse(default_bg=None, scale=3) funhouse.peripherals.dotstars.brightness = 0.05 funhouse.peripherals.dotstars.fill(GREEN) pixel_pin = board.A2 num_pixels = 30 pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.3, auto_write=False)
Sonar
The ultrasonic distance sensor is set up on the FunHouse A0 pin for triggering a ping, and A1 for receiving the echo.
sonar = adafruit_hcsr04.HCSR04(trigger_pin=board.A0, echo_pin=board.A1)
Main Loop
Here's what happens in the main loop of the program. Inside of a try-except loop, the sonar.distance value is checked.
If it is greater than the SLOW_DISTANCE the NeoPixels are set to green.
If it is less than the SLOW DISTANCE and greater than the STOP DISTANCE, the NeoPixels are set to yellow and the FunHouse speaker plays a medium tone.
If the distance is less than the STOP_DISTANCE, the NeoPixels are set to red and the tone plays at a higher pitch.
while True:
try:
print((sonar.distance,))
if sonar.distance > SLOW_DISTANCE:
funhouse.peripherals.dotstars.fill(GREEN)
pixels.fill(GREEN)
pixels.show()
elif sonar.distance < SLOW_DISTANCE and sonar.distance > STOP_DISTANCE:
funhouse.peripherals.dotstars.fill(AMBER)
pixels.fill(AMBER)
pixels.show()
funhouse.peripherals.play_tone(1000, 0.3)
elif sonar.distance < STOP_DISTANCE:
funhouse.peripherals.dotstars.fill(RED)
pixels.fill(RED)
pixels.show()
funhouse.peripherals.play_tone(2600, 0.3)
except RuntimeError:
print("Retrying!")
time.sleep(0.01)
Page last edited March 08, 2024
Text editor powered by tinymce.
Use the Parking Assistant
Depending on your parking space or garage, your options will vary for mounting the FunHouse, ultrasonic distance sensor, and NeoPixel strip.
In the example shown here, there is a post that provides a convenient mounting point, and isn't something we want to hit with the bumper!
It's good to start with a temporary mounting method, such as the gaffer's tape seen here. This allows you to test out the mounting positions to make sure you get a good distance read and that the NeoPixel strip is visible to the driver.
After testing and getting the sensor height to match your vehicle's bumper, you may want to use something a little more permanent, such as double stick, high-strength tape.
Now, you can pull in as close as you need with ease by listening to the beeps and watching the NeoPixels change from green to yellow to red!
This demonstration was done at an outside parking space -- this project works most easily inside a garage -- if you need to set it up in the outdoors, you'll want to use a water resistant enclosure, such as this one, to protect from the elements.
Page last edited March 08, 2024
Text editor powered by tinymce.