all about Ultrasonic sensor

 Hi friends.

here is the diagram :- 




here is code :-

----------------------------------------------------

/*

 * Distance measurement using HC SR04 ultrasonic sensor and i2c 16x2 lcd

 * ER BROS LAB

 */


#include <Wire.h>

#include <LiquidCrystal_I2C.h>


#define trigger 12

#define echo 13


LiquidCrystal_I2C lcd(0x27, 16, 2);


float t = 0, distance = 0;


void setup()

{

  lcd.begin();

  lcd.backlight();

  delay(100);

  pinMode(trigger, OUTPUT);

  pinMode(echo, INPUT);

  lcd.print("Ultra sonic");

  lcd.setCursor(0, 1);

  lcd.print("Distance Meter");

  delay(2000);

  lcd.clear();

  lcd.print("ER BROS LAB");

  delay(2000);

}


void loop()

{

  lcd.clear();

  digitalWrite(trigger, LOW);

  delayMicroseconds(2);

  digitalWrite(trigger, HIGH);

  delayMicroseconds(10);

  digitalWrite(trigger, LOW);

  delayMicroseconds(2);

  t = pulseIn(echo, HIGH);

  distance = t * 340 / 20000;

  lcd.clear();

  lcd.print("Distance:");

  lcd.print(distance);

  lcd.print("cm");

  lcd.setCursor(0, 1);

  lcd.print("Distance:");

  lcd.print(distance / 100);

  lcd.print("m");

  delay(1000);

}

-----------------------------------------------------------

Information of sensor :-

https://cdn.sparkfun.com/datasheets/Sensors/Proximity/HCSR04.pdf

datasheet of lm324 :-

https://www.ti.com/lit/ds/snosc16d/snosc16d.pdf 

datasheet of max3232 :-

https://pdfserv.maximintegrated.com/en/ds/MAX3222-MAX3241.pdf



if you have any crazy idea, don't hesitate to comment it . we read all comments and also reply if possible.

follow on instagram 


THANK YOU

Comments

Popular posts from this blog

OLED display interface with Arduino

Binary Clock

timer switch