تحكم تجربة 5 ⬇️
تحكم تجربة 5 ⬇️
تحكم تجربة 5 ⬇️
ITROUCTION:
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
1
Components Required
1 × Breadboard
•
• 1 × Arduino Uno R3
• 1 × ULTRASONIC Sensor (HC-SR04).
…………………………………………………………………………………………………………………………………
Project (1): Design MCU system to find distance of an object and print the
distance on LCD with 3 seconds update period?
#include <LiquidCrystal.h>
int trigger=8;
int echo=9;
LiquidCrystal lcd(12,11,5,4,3,2);
float time=0,distance=0;
void setup)( {
lcd.begin(16,2);
pinMode(trigger,OUTPUT);
pinMode(echo,INPUT);
lcd.print(" Ultra sonic");
lcd.setCursor(0,1);
lcd.print("Distance Meter);
delay(2000);
lcd.clear();
lcd.print(" Circuit Digest");
delay(2000); }
void loop() {
lcd.clear();
digitalWrite(trigger,LOW);
delayMicroseconds(2);
digitalWrite(trigger,HIGH);
delayMicroseconds(10);
digitalWrite(trigger,LOW);
delayMicroseconds(2);
time=pulseIn(echo,HIGH);
distance=time*0.034/2;
lcd.clear();
lcd.print("Distance");
2
lcd.print(distance);
lcd.print("cm");
lcd.setCursor(0,1);
lcd.print("Distance");
lcd.print(distance/1000);
lcd.print("m");
delay(1000); }
.…………………………………………………………………………………………………………………………………..
Project(2): Design MCU system to find distance of an object and print the
distance on LCD, when the distance is less than 20 cm, a green led is turn on
and when the distance become less than 12 cm, a red led should be turned on
and when it is less than 10 cm, a warning sound generated from buzzer is
turned on.
#define echoPin 9
#define trigPin 8 long duration;
int distance;
void setup() { pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
Serial.println("Ultrasonic Sensor HC-SR04 Test");
Serial.println("with Arduino UNO R3"); }
void loop() { digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration *0.034/2;
Serial.print(distance);
Serial.println("cm");
if(distance<20){
digitalWrite(3,1); }
else if(distance>20){
digitalWrite(2,1); } }
3
Code to Note:
The Ultrasonic sensor has four terminals - +5V, Trigger, Echo, and GND
connected as follows −
• Connect the +5V pin to +5v on your Arduino board.
• Connect Trigger to digital pin 7 on your Arduino board.
• Connect Echo to digital pin 6 on your Arduino board.
• Connect GND with GND on Arduino.
In our programs, we have displayed the distance measured by the sensor in
inches and cm via the serial port.
Result
You will see the distance measured by sensor in inches and cm on Arduino serial
monitor.