Ultrasonic Sensor With Led


Connections



Trig = 7 of Arduino

Echo = 6 of Arduino

Vcc = 5v of Arduino

GND = GND of Arduino


Code

const int pingPin = 7; // Trigger Pin of Ultrasonic Sensor const int echoPin = 6; // Echo Pin of Ultrasonic Sensor void setup() { Serial.begin(9600); // Starting Serial Terminal } void loop() { long duration, inches, cm; pinMode(pingPin, OUTPUT); digitalWrite(pingPin, LOW); delayMicroseconds(2); digitalWrite(pingPin, HIGH); delayMicroseconds(10); digitalWrite(pingPin, LOW); pinMode(echoPin, INPUT); duration = pulseIn(echoPin, HIGH); inches = microsecondsToInches(duration); cm = microsecondsToCentimeters(duration); Serial.print(inches); Serial.print("in, "); Serial.print(cm); Serial.print("cm"); Serial.println(); delay(100); } long microsecondsToInches(long microseconds) { return microseconds / 74 / 2; } long microsecondsToCentimeters(long microseconds) { return microseconds / 29 / 2; }

Download Code Here

Recent Posts

See All

This article will be beginner friendly, only this time in the Linux console. The material is presented, in my experience, from the most frequently used to the rarest. As in the previous article about

In this PowerShell tutorial I will provide you with practice-oriented knowledge about PowerShell. Would you like to do your IT tasks better and more efficiently and would you like to use PowerShell fo

Following the previous tutorial in which we looked at the log4j vulnerability in VMWare vSphere server, I got some questions about how to set up a malicious LDAP server on Linux. The attacker controll

Techtronics101

Hi, thanks for stopping by!

HI!! Our main goal for this website and our channel is to teach and educate everyone on cybersecurity for free. I will upload all my new tutorials and new courses on my blog and on my Youtube Channel. 

Join us in the general discussions to get answers to your queries from the community.
​Sign up here and subscribe to my Youtube channel to stay updated.

Let the posts
come to you.

Thanks for submitting!

  • YouTube