0% found this document useful (0 votes)
3 views1 page

Arduino Ultrasonic Distance Sensor Code

The document contains an Arduino code that measures distance using ultrasonic sensors. It initializes pins for triggering and receiving signals, calculates distance in centimeters and inches, and controls an output based on the measured distance. If the distance is less than 20 cm, it turns off an output pin; otherwise, it keeps it on.

Uploaded by

Akash r Kulkarni
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Arduino Ultrasonic Distance Sensor Code

The document contains an Arduino code that measures distance using ultrasonic sensors. It initializes pins for triggering and receiving signals, calculates distance in centimeters and inches, and controls an output based on the measured distance. If the distance is less than 20 cm, it turns off an output pin; otherwise, it keeps it on.

Uploaded by

Akash r Kulkarni
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

//EAZYTRONIC.

COM

const int trigPin = 10;


const int echoPin = 11;
long duration;
int distanceCm, distanceInch;
void setup()
{

[Link](9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(7,OUTPUT);
digitalWrite(7,HIGH);
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distanceCm= duration*0.034/2;
distanceInch = duration*0.0133/2;
[Link]("Distance: ");
[Link](distanceCm);
delay(500);

if(distanceCm <20)
{
digitalWrite(7,LOW);

if(distanceCm >20)
{
digitalWrite(7,HIGH);

You might also like