using millis() in ultrasonic sensor program in tamil
Coding #define trig 5 #define echo 4 void setup() { Serial.begin(9600); pinMode(trig,OUTPUT); pinMode(echo,INPUT); pinMode(13,OUTPUT); pinMode(12,OUTPUT); digitalWrite(12,HIGH); delay(2000); } void loop() { digitalWrite(13,HIGH); digitalWrite(12,LOW); delay(1000); digitalWrite(13,LOW); digitalWrite(12,HIGH); delay(2000); long duration , distance; digitalWrite(trig,LOW); delay(2); digitalWrite(trig,HIGH); delay(2); digitalWrite(trig,LOW); duration= pulseIn(echo,HIGH); distance=(duration/2)/29.1; Serial.println(distance); }
Comments
Post a Comment