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 and led pins int l1 = 13; int l2

Arduino Beginner Experiments: Arduino and Light Blocking Sensor

HELLO THERE!!!     How are you guys? I hope everyone is fine and in a good mood always. This week, I would like to share with you guys my experiment on Arduino and Light Blocking Sensor. The objective of this experiment is to receive feedback from the sensor ( Digital and Analog) What is Light Blocking Sensor?      A linear hall sensor is a type of sensor which responds when the sensor is blocked out from light. The sensor is different for LDR's as LDR's responds to the amount of light it received while the light blocking sensor responds if the light is blocked out or not from the sensor.It can be used for both digital and analog measurements. HARDWARE: 1.Arduino UNO 2. Light Blocking Sensor SOFTWARE: 1.Arduino IDE CIRCUIT ASSEMBLY   Let's refer to the image of the blocking sensor below: The Connection of the Sensor to the Arduino is shown below: SENSOR  ----->       ARDUINO Signal      ------>     Any Analog/Digital pin

Arduino Tinkering : Controlling multiple LED with multiple potentiometers

HELLO THERE!!!!            How are you guys? I hope everyone is fine and well always. For this week's post, I would like to share with you guys a simple tinkering on Arduino, LED, and potentiometers. The objective of the experiment is to light up different amount of LED's with different intensity by controlling two potentiometers. Before starting, of course, we need to know what items are needed. The items needed are: 1. Arduino UNO   2. 4 to 5 LEDs 3. 2 Potentiometers The software used in this experiment is: 1. Arduino IDE. Now that all the hardware and software are obtained, let's go to the schematics of the circuit. The circuit is quite simple actually. The long legs of the LED's were connected to PWM pins while the shorter legs were connected to ground. The potentiometers however have three legs. The middle leg is connected to the analog pins (A0, A1) while the other two legs were connected to 5V and GND respectively. Don't w