Project showcase
Garage Parking Stop Light

Garage Parking Stop Light © GPL3+

Pull into your garage and have a distance sensor tell you when to stop and give feedback through a regular stop light interface.

  • 2,440 views
  • 0 comments
  • 10 respects

Components and supplies

Necessary tools and machines

Apps and online services

About this project

I've seen several of these both online for sale and other implementations, and so I thought I'd give it a try. I had all the parts for this project laying around except for the Novelty Stop Light, so with a quick Amazon order, that was resolved.

Now let me be clear. My wife has NO issues parking in the garage; let me say this at the outset. There was no need - just an impulse to create. I guess you can call this the "disclaimer" to keep me out of trouble.

The following steps where taken.

1. Deconstruction: included removal of battery connections and minimal internal chips.

2. Concept Testing: included wiring up to the Arduino and testing both the distance sensor and the output to the LEDs.

3. Final Build and Deployment: included drilling holes and mounting the ultrasonic sensor, soldering everything onto a stand alone board and final testing.

I had planned on replacing the existing LEDs with some that I had, but the existing ones (2 per light) seemed to work great without any addition or modifications.

Code

Arduino codeArduino
/*
Stop Light Code v. 1.0
By Richard Noordam
Richard.Noordam@gmail.com
Based on several base modules cobbled together.
*/

#define pinLedRed 12
#define pinLedYellow 11
#define pinLedGreen 10
#define TRIGGER 7
#define ECHO    8
#define theDelay 250
int redDistance;
int greenDistance;
int misReadValue;
int retDistance;
int compareDistance;

void setup() {
  //initialize values
  redDistance = 150;
  greenDistance = 350;
  misReadValue = 0;
  // set serial baud rate
  Serial.begin (9600);
  // set pin modes
  pinMode(pinLedRed, OUTPUT);     // Initialize RedLed pin as an output
  pinMode(pinLedYellow, OUTPUT);     // Initialize the Yellow pin as an output
  pinMode(pinLedGreen, OUTPUT);     // Initialize the Green pin as an output
  pinMode(TRIGGER, OUTPUT);
  pinMode(ECHO, INPUT);
  // set start position of LED pins
  digitalWrite(pinLedRed, LOW);     // turn Red off
  digitalWrite(pinLedYellow, LOW);  // turn Yellow off
  digitalWrite(pinLedGreen, LOW);   // turn Green off
  delay(3000);
}

// the loop function runs over and over again forever

// get distance from hc-sr04 ultrasonic distance sensor.
int getDistance(){
 long duration, distance;
  digitalWrite(TRIGGER, LOW);  
  delayMicroseconds(2); 
  digitalWrite(TRIGGER, HIGH);
  delayMicroseconds(10); 
  digitalWrite(TRIGGER, LOW);
  duration = pulseIn(ECHO, HIGH);
  distance = (duration/2) / 29.1;
  return (int)distance;
}
// turn on yellow LED
void yellowOn(){
    //Serial.println("Yellow");
    digitalWrite(pinLedGreen, LOW);    // turn Green OFF
    digitalWrite(pinLedYellow, HIGH);   // turn Yellow ON
    digitalWrite(pinLedRed, LOW);      // turn Red OFF
}
// turn on green LED
void greenOn(){
    //Serial.println("Green");
    digitalWrite(pinLedGreen, HIGH);    // turn Green on
    digitalWrite(pinLedYellow, LOW);   // turn Yellow OFF
    digitalWrite(pinLedRed, LOW);      // turn Red OFF
}
// turn on red LED
void redOn(){
    //Serial.println("Red");
    digitalWrite(pinLedGreen, LOW);    // turn Green OFF
    digitalWrite(pinLedYellow, LOW);   // turn Yellow OFF
    digitalWrite(pinLedRed, HIGH);      // turn Red ON
}

String returnColor(int myDistance){
  String retColor = "ERROR";
  if (myDistance > 0 and myDistance < redDistance){
    retColor = "Red";
  }
  if (myDistance >= redDistance and myDistance < greenDistance){
    retColor = "Yellow";
  }
  if (myDistance >= greenDistance){
    retColor = "Green";
  }
  if (retColor == "ERROR"){
    Serial.print("NoColor: Error, Range Failure:");
    Serial.println(myDistance);
    // so it turns green if too far.
    retColor = "Green";
  }
  return retColor;  
}
String color;

void loop() {
  
  retDistance = getDistance();
  Serial.print("Distance:");
  Serial.print(retDistance);
  color = returnColor(retDistance);
  Serial.print(":   Color:");
  Serial.println(color);
  // turn on green if long distance
  if (color == "Green"){
    greenOn();
  }
  if (color == "Yellow"){
    yellowOn();
  }
  if (color == "Red"){
    redOn();
  }
  delay(theDelay);                    
}

Schematics

RYG Stoplight Fritz
rygstoplight_2VeljVvR7o.fzz

Comments

Similar projects you might like

The "Tennis Ball" Garage Stop Light

Project tutorial by Stuart Mace

  • 9,678 views
  • 2 comments
  • 36 respects

Parking Sensor with Arduino

Project showcase by VINICIUS LOPES

  • 11,020 views
  • 4 comments
  • 17 respects

Arduino Automated Parking Garage

Project tutorial by ashraf_minhaj

  • 4,179 views
  • 11 comments
  • 24 respects

Controlling LED light intensity using smartphone light senso

Project tutorial by Nikola Travis

  • 1,841 views
  • 0 comments
  • 3 respects

Smart Parking System

Project in progress by Md. Khairul Alam

  • 43,048 views
  • 32 comments
  • 104 respects

Smart Parking

Project showcase by Kaustubh Agarwal

  • 29,252 views
  • 14 comments
  • 43 respects
Add projectSign up / Login