bubblemanster
Published © GPL3+

Parking Indicator With Ultrasonic Sensor

Motion-activated ultrasonic sensor parking indicator tightly compacted onto an Elegoo Arduino Uno with a prototyping shield on top.

IntermediateProtip160
Parking Indicator With Ultrasonic Sensor

Things used in this project

Hardware components

Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Arduino UNO
Arduino UNO
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Wiring Schematic

Code

parking_system.ino

Arduino
// Include NewPing Library
#include "NewPing.h"

#define TRIGGER_PIN 3
#define ECHO_PIN 2
#define BLUE 9
#define GREEN 10
#define RED 11
#define MAX_DISTANCE 75	

// NewPing setup of pins and maximum distance.
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

void setup() {
  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);
  digitalWrite(RED, LOW);
  digitalWrite(GREEN, LOW);
  digitalWrite(BLUE, LOW);
}

int redValue;
int greenValue;
int blueValue;

void loop() {
	int distance=sonar.ping_cm();
  int colour_val=map(distance, 0, MAX_DISTANCE, 1, 5);

  #define delayTime 10 // fading time between colors

  redValue = 0; // choose a value between 1 and 255 to change the color.
  greenValue = 0;
  blueValue = 0;

  if(colour_val == 1){
    redValue=255;
    greenValue=0;
    blueValue=0;
  }
  else if(colour_val == 4){
    redValue=0;
    greenValue=255;
    blueValue=0;
  }
  else if(colour_val == 2){
    redValue=100;
    greenValue=100;
    blueValue=0;
  }
  else if(colour_val == 3){
    redValue=100;
    greenValue=100;
    blueValue=0;
  }
  else if(colour_val == 5){
    redValue=0;
    greenValue=255;
    blueValue=0;
  }

  analogWrite(GREEN, greenValue);
  analogWrite(BLUE, blueValue);
  analogWrite(RED, redValue);

	delay(500);
}

Credits

bubblemanster
1 project • 1 follower
Contact

Comments

Please log in or sign up to comment.