Git Product home page Git Product logo

experiment--04-interfacing-digital-output-with-arduino-ultrasonic-sensor's Introduction

EXPERIMENT-NO--05-Distance measurement using Ultrasonic sensor

AIM:

To interface an ultrasonic pair and measure the distance in centimeters , calculate the error

COMPONENTS REQUIRED:

  1. ultrasonic sensor module HC-SR04
  2. 1 KΩ resistor
  3. Arduino Uno
  4. USB Interfacing cable
  5. Connecting wires

THEORY:

The HC-SR04 ultrasonic sensor uses SONAR to determine the distance of an object just like the bats do. It offers excellent non-contact range detection with high accuracy and stable readings in an easy-to-use package from 2 cm to 400 cm or 1” to 13 feet.

The operation is not affected by sunlight or black material, although acoustically, soft materials like cloth can be difficult to detect. It comes complete with ultrasonic transmitter and receiver module. Technical Specifications Power Supply − +5V DC Quiescent Current − <2mA Working Current − 15mA Effectual Angle − <15° Ranging Distance − 2cm – 400 cm/1″ – 13ft Resolution − 0.3 cm Measuring Angle − 30 degree

The ultrasonic sensor uses sonar to determine the distance to an object. Here’s what happens:

The ultrasound transmitter (trig pin) emits a high-frequency sound (40 kHz). The sound travels through the air. If it finds an object, it bounces back to the module. The ultrasound receiver (echo pin) receives the reflected sound (echo). The time between the transmission and reception of the signal allows us to calculate the distance to an object. This is possible because we know the sound’s velocity in the air. Here’s the formula:

distance to an object = ((speed of sound in the air)*time)/2 speed of sound in the air at 20ºC (68ºF) = 343m/s

FIGURE 01 CIRCUIT OF INTERFACING ULTRASONIC SENSOR

image

PROCEDURE:

  1. Connect the circuit as per the circuit diagram
  2. Connect the board to your computer via the USB cable.
  3. If needed, install the drivers.
  4. Launch the Arduino IDE.
  5. Select the board (If you the board is arduino uno, select accordingly).
  6. Select your serial port, accordingly ( E.g. COM5 )
  7. Open the file of the program and verify the error , clear if any errors that are existing
  8. Upload the program and check for the physical working.
  9. Ensure safety before powering up the device
  10. Plot the graph for the output voltage vs the resistance

PROGRAM

const int trigpin=10;
const int echopin=9;
int red=7;
int green=6;
long duration;
int distance;

void setup()
{
  pinMode(trigpin, OUTPUT);
  pinMode(echopin, INPUT);
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  digitalWrite(trigpin, LOW);
  delay(20); // Wait for 1000 millisecond(s)
  digitalWrite(trigpin, HIGH);
  delay(20); 
  digitalWrite(trigpin, LOW);
  duration=pulseIn(echopin,HIGH);
  distance=duration*0.034/2;
  Serial.println(distance);
  Serial.println("cm");
  
  if(distance>5)
  {
	digitalWrite(red, HIGH);
  delay(200);
    digitalWrite(red, LOW);
  delay(200);
  }
  else
  {
	digitalWrite(green, HIGH);
  delay(200);
    digitalWrite(green, LOW);
  delay(200);
  }
}

Circuit:

WhatsApp Image 2024-03-07 at 11 06 39_d44b9d9c

WhatsApp Image 2024-03-07 at 11 32 08_517d9767

Distance vs measurement table

image

Average error = sum/ number of readings

WhatsApp Image 2024-03-07 at 11 31 36_33c777ff

WhatsApp Image 2024-03-07 at 11 31 36_3e41d034

RESULTS

Thus the program for the distance measurement using Ultrasonic sensor is been implemented successfully.

experiment--04-interfacing-digital-output-with-arduino-ultrasonic-sensor's People

Contributors

vasanthkumarch avatar ragu-123 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.