How to Make Object Detector
Code :-
/* code started
code created by Technical idEas
#define buzzer=11
#define led=12
#define trigPin = 10;
#define ehoPin = 9;
16x2 lcd connection
rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
channel link :- https://youtube.com/channel/UCCJyR_wnt3SxhErsSUP9Wrw
*/
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
const int trigPin = 10;
const int echoPin = 9;
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
Serial.begin(9600);
lcd.begin(16,2);
lcd.setCursor(0, 0);
lcd.print(" Technical idEas ");
delay(5000);
}
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(" OBJECT");
Serial.println(distance);
if(distance<20){
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
lcd.begin(16,2);
lcd.setCursor(0, 0);
lcd.print(" DETECTED");
lcd.setCursor(0, 1);
lcd.print(" OBJECT");
delay(1000);}
else
{
digitalWrite(11, LOW);
digitalWrite(12, LOW);
lcd.begin(16,2);
lcd.setCursor(0, 1);
lcd.print("NO OBJECT ");
}
}
Comments
Post a Comment