LESSON 11 - The Mesurment Distance with Arduino And HC-SR04

In this lesson, I've explained The distance measurment with aduino and HC-SR04 module. I've mesured the distance in centimeter and inch.



Ultrasonic Ranging Module HC - SR04


Product features:

Ultrasonic ranging module HC - SR04 provides 2cm - 400cm non-contact measurement function, the ranging accuracy can reach to 3mm. The modules includes ultrasonic transmitters, receiver and control circuit. The basic principle of work:

(1) Using IO trigger for at least 10us high level signal,

(2) The Module automatically sends eight 40 kHz and detect whether there is a pulse signal back.

(3) IF the signal back, through high level , time of high output IO duration is the time from sending ultrasonic to returning.

Test distance = (high level time×velocity of sound (340M/S) / 2,

Wire connecting direct as following:
  • 5V Supply 
  • Trigger Pulse Input 
  • Echo Pulse Output 
  • 0V Ground 
Electric Parameter 
Working Voltage
DC 5 V
Working Current
15mA
Working Frequency
40Hz
Max Range
4m
Min Range
2cm
MeasuringAngle
15 degree
Trigger Input Signal
10uS TTL pulse
Echo Output Signal
Input TTL lever signal and the range in proportion
Dimension
45*20*15mm


Figure 1 - HC-SR04 Module

BUZZER
It is a tiny speaker that produces a "beep" sound proportional to the size of the electronic signal applied to it. There are two types, one with a circuit and one without a circuit. A stronger sound output is obtained from the one with a circuit.
Figure 2 - Buzzer

The Circuit of Measurment Distance 
Firstly, I've connect the LCD display and the i2C module in Figure 3. Then I've set up the circuit in Figure 4.

Figure 3 - The LCD display and I2C Module

Figure 4 - The circuit of distance mesurement

ARDUINO UNO Program

#include <LiquidCrystal_I2C.h>
#include <Wire.h>

const int trig = 2, echo = 3, buzzer=6; 
float zaman,cm,inc ;

 // LCD ekan Tanımlanıyor (The initialization LCD Display)
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3, POSITIVE);

void setup() 
      pinMode(trig, OUTPUT);
      pinMode(echo, INPUT);
      pinMode(buzzer,OUTPUT);
      lcd.begin (16,2); 
void loop() 
      digitalWrite(trig, HIGH);
      delay(15);
      digitalWrite(trig, LOW);
      zaman = pulseIn(echo, HIGH); // Ses Dönüş Zamanı - time to echo 
      cm = zaman / 58;  //cm hesabı - time to centimetres
      inc=zaman/148;    //inç hesabı - time to inches
      
    // cm olarak mesafeyi LCD ekrana Yazdırmak- Distance in cm on LCD
      lcd.setCursor(0,0);  
      lcd.print("cm :"); 
      lcd.setCursor(4,0); 
      lcd.print(cm); 
    // inç olarak mesafeyi LCD ekrana Yazdırmak- Distance in inch on LCD 
      lcd.setCursor(0,1);  
      lcd.print("inc:"); 
      lcd.setCursor(4,1); 
      lcd.print(inc); 
    //cm ile Buzzer ile mesafe kontrolü - Distance control with buzzer in cm
      if( cm>10)
       {
          noTone(buzzer);
        }
       if( cm<=10)
       {
          tone(buzzer, 500,100);
        }
       if( cm<=5)
        {
          tone(buzzer, 500,1000);
         }
     delay(500);
}

Project Files
You can download project files by clickin the links.


Video Of Lesson



Hiç yorum yok:

Yorum Gönder