arduino with ultrasonic sensor
Arduino with ultrasonic sensor
circuit diagram
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;
}
Searches related to arduino ultrasonic sensor
arduino ultrasonic sensor project
ultrasonic sensor arduino code with led
ultrasonic sensor arduino library
ultrasonic sensor arduino code with buzzer
hc-sr04 ultrasonic sensor
distance measurement using ultrasonic sensor and arduino code
3 pin ultrasonic sensor arduino code
ultrasonic sensor arduino code for obstacle detection
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;
}
arduino ultrasonic sensor project
ultrasonic sensor arduino code with led
ultrasonic sensor arduino library
ultrasonic sensor arduino code with buzzer
hc-sr04 ultrasonic sensor
distance measurement using ultrasonic sensor and arduino code
3 pin ultrasonic sensor arduino code
ultrasonic sensor arduino code for obstacle detection
Comments
Post a Comment