Introduction: GrovePi+- Parking Sensor for Robot Car

Objective

Creating an adjustable distance parking sensor using a GrovePi+ board, an ultrasonic ranger, two LEDs, buzzer and and RGB LCD Display.

Functioning

The adjustable distance parking sensor measures the distance the sensor is from an object or obstacle and it will emit an LED from blue to red as the object is within range and closer to the target area.

Constraints used:

I have set up the target area to be less than 30 cm and the range to be less than 100 cm, but you can adjust the distance to any distance you like. When the sensor detects an object within the 100-cm range, the blue LED will light up. When the objects is within the 30-cm target area, the red LED will light up and the buzzer will buzz.

Materials:

  1. RaspBerry Pi 3
  2. GrovePi+
  3. Grove Ultrasonic Sensor
  4. Grove Red LED
  5. Grove Green LED
  6. Grove Buzzer
  7. Grove RGB LCD Display

Step 1: Connections and Libraries

Connections:

Connections made to the GrovePi+ with the sensors:

  1. Ultrasonic distance sensor (connected to D2)
  2. Green LED (connected to D5)
  3. Red LED (connected to D6)
  4. Buzzer (connected to the D8)
  5. RGB LCD (connected to any I2C port on the GrovePi+)

In order for the ultrasonic ranger data to display on the RGB LCD, you must import the following two lines:

import sys
sys.path.append("/home/pi/GrovePi/Software/Python/grove_rgb_lcd")

from grove_rgb_lcd import *

and write the following lines to your code:

distance = ultrasonicRead (ultrasonic_ranger)          
	print distance
	dist = int (distance)
	if dist> 100:
		setText ("distance =" + str (dist))
	elif dist> 30:
		setText ("distance =" + str (dist))
	else:
		setText ("distance =" + str (dist))

The RGB LCD backlight display will flicker when it's connected to the board while the board is powered on. To stop the RGB LCD display backlight from flickering, simply power off the unit and power it back on.

The entire code to make the adjustable distance parking sensor work, is given in the latter steps.

Step 2: SetRGB()

solid green background setRGB (0, 255, 0) with time.sleep (.5)

The function SetRGB is for changing the background color of the LCD display. You can have the background color with a solid color, shades of a color or random colors. I have SetRGB set to shade of white (255 - c, 255 - c, 255) with sleep time 0.0039 but if you want solid green color simply write (0, 255, 0). If you want random colors write the following: (random.randint (0, 255) , random.randint (0, 255), random.randint (0, 255)). For more color variations, check out Dexter Industries GitHub.

Step 3: Code:

Executing the code is easy. You can either use the sudo python command or use the python shell run module command by pressing F5 on your keyboard, which is much faster.