Skip to main content

Arduino System: Reverse Parking Sensor

HELLO THERE!!!!

     How are you, guys? I hope everybody is fine and happy always. This week I am going to share to all of you to a simple system I made while learning the Arduino. I like to call it the reverse parking sensor. Basically, what the system do is that it detect distance(via HC-SR04) and produce readable output(via serial monitor) and audible output(via speaker). The items needed to build this system is:

Hardware:
1.Arduino (I used arduino Leonardo because my Arduino UNO is in another project)
2.HC-SR04 module
3.Piezo speaker



Software
1.Arduino IDE



Now, the schematics of the circuit is fairly simple as shown below:




The connections:
HC-SR04 to Arduino:
VCC-->5V
GND-->GND
echo-->pin 10
trig-->pin 9
Piezo to Arduino:
Red wire-->pin 4
black wire-->GND


Ok, the circuit assembly is done, what's next? The code of course!! The Arduino code for this system is a bit long but don't worry because its simple and easy to be understood:


int tonep = 4;
int trigp = 9;
int echop = 10;
int duration;
int distance;
int val = 0;//declare the pin I/O of the circuit 

void setup() {

  Serial.begin(9600);//serial communication at 9600 baud rate
  pinMode(tonep,OUTPUT);
  pinMode(trigp,OUTPUT);
  pinMode(echop,INPUT);
//declare which pin is I/O
}

void loop()
{
  digitalWrite (trigp,LOW);
  delayMicroseconds(5);
  digitalWrite(trigp,HIGH);
  delayMicroseconds(10);
  digitalWrite (trigp,LOW);//give the ultrasonic module initial startup
  duration = pulseIn(echop,HIGH);
  distance = (duration/2)/29.1;//duration formula

  while(Serial.available()){
    delay(1000);
    char c = Serial.read();
    distance += c;
  }//counter(not compulsory)
  
  if(distance >= 26 &&distance <= 30){//range of distance
    val = analogRead(distance);//read the ultrasonic module
       Serial.print("depth:     ");
   Serial.print(distance);
         Serial.print("cm");
          Serial.println();//print the distance
            tone(tonep, 1000,200);//tone for the speaker
             delay(1000);//delay so that the reading do not overload
  //same goes for other ranges below
  }  
   if( distance >= 20 && distance <= 25){
     val = analogRead(distance);
   Serial.print("depth:     ");
   Serial.print(distance);
         Serial.print("cm");
          Serial.println();
    tone(tonep,1000,100);
    delay(1000);
   
  }
   if( distance >= 10 && distance <= 19){
     val = analogRead(distance);
     Serial.print("depth:     ");
   Serial.print(distance);
         Serial.print("cm");
          Serial.println();
        tone(tonep,1000,50);
   delay(1000);
  }
  if(distance >= 1 && distance <= 9){

    val = analogRead(distance);
   Serial.print("depth:     ");
   Serial.print(distance);
         Serial.print("cm");
          Serial.println();
    tone(tonep,1000,0);
   delay(1000);
  }
   if (distance > 30 || distance <= 0){
    Serial.println("OUT OF RANGE");
     val = analogRead(distance);
     Serial.print("depth:     ");
   Serial.print(distance);
         Serial.print("cm");
          Serial.println();
              noTone(tonep);
              delay(1000);
  }
  delay(600);//delay to avoid overloading
  noTone(tonep);//notone
}


You can modify many things in the code such as the distance variable and the tone variables.You can also add LED's to enhance the project. After writing the code, upload to the Arduino and test it. Experimental videos are shown below:


























Comments

Popular posts from this blog

Arduino and Multi Function Shield: Pots,LEDs and buzzers

HELLO THERE!!!!!    How are you guys? I hope everyone is fine and in good mood always. This week, I continue my tinkerings with the Multi Function Shield. In this experiment, I used the potentiometer in the shield to control the LEDs in the shield. Without further wasting time, let's jump in straight to the experiment!! HARDWARE 1.ARDUINO UNO  2.MULTI-FUNCTION SHIELD SOFTWARE: 1. ARDUINO IDE CIRCUIT ASSEMBLY    The circuit assembly is fairly simple. Just attach the multi function shield on top of Arduino properly. Please attach the shield properly as failure to do so would cause the shield  not to function as intended. CODING THE ARDUINO: Let's refer to the multi-function shield image below: Referring to the image of the shield, it can be seen that the potentiometer (blue object near buttons) is connected to pin A0 (analog 0)     int pot = A0; //declaring the pot ...

Mixing Color with RGB LED!!

HELLO THERE!!!     Hi everybody!! How are you guys? This week, I am going to share with you guys a fun experiment that I did during the weekends. The objective of this experiment is to use the RGB LED to output different colors. Without wasting further time, let's get into the experiment!! HARDWARE: 1.Arduino UNO 2. 3 Potentiometer 3. RGB LED ( I used the Keyes RGB LED) SOFTWARE: 1.Arduino IDE CIRCUIT ASSEMBLY:   By referring to the image below: The RGB LED has 4 pins, 1 GND, 1 pin each for the color red, green and blue. RGB LED                      ----------> ARDUINO  GND(- sign of the pin)                  GND R,G,B                                              Any Digital pin(I used pin 9,10 and 11) T...

Arduino and Keyes KY-017 Mercury Tilt Sensor

HELLO THERE!!!     How are you guys? I hope everyone is fine and good as always. I am back in tinkering after a few months of hiatus( busy stuff :) ). So, today i would like to share with you guys on KY-017, which is a Keyes Mercury Tilt Sensor. KY-017 Sensor KY-017      The picture above shows the KY-017 Sensor from Keyes. It has 3 pins, A ground, A vcc, and A signal pin. If you look closely, there is a mercury ball inside the bulb like object. The mercury ball acts like a switch for this sensor. KY-017 Working Procedure: 1. When the sensor is not tilted, the mercury ball will be at the bottom of the bulb. This will complete the circuit and turns on the LED of the sensor. The output that is sent through the signal pin will be LOW. 2.When the sensor is tilted, the mercury ball will be at the top of the bulb(near at the sharper end). This will complete break circuit and turns off the LED of the sensor. The output that is sent through t...