Arduino Ultrasonic Sensor with Servo Motor: Interactive Distance Measurement!

  Рет қаралды 41

Bhasaki Robotech

Bhasaki Robotech

Күн бұрын

Пікірлер: 2
@bobbytaylor5850
@bobbytaylor5850 16 күн бұрын
How could you measure the width of the object with the ultrasonic sensor?
@bhasakirobotech1926
@bhasakirobotech1926 15 күн бұрын
// Define the pins connected to the ultrasonic sensor const int trigPin = 9; const int echoPin = 10; // Variables to store the two distance measurements long distance1 = 0; long distance2 = 0; void setup() { Serial.begin(9600); // Start the serial communication pinMode(trigPin, OUTPUT); // Set the trigPin as an output pinMode(echoPin, INPUT); // Set the echoPin as an input } void loop() { // Take the first distance measurement at the first edge of the object Serial.println("Place sensor at the first edge and press any key..."); while (Serial.available() == 0) {} // Wait for user input distance1 = measureDistance(); Serial.print("Distance at first edge: "); Serial.print(distance1); Serial.println(" cm"); // Wait for user to move the sensor to the other edge Serial.println("Move the sensor to the other edge and press any key..."); while (Serial.available() == 0) {} // Wait for user input distance2 = measureDistance(); Serial.print("Distance at second edge: "); Serial.print(distance2); Serial.println(" cm"); // Calculate the width (distance traveled by the sensor) long width = abs(distance2 - distance1); Serial.print("Width of the object: "); Serial.print(width); Serial.println(" cm"); // Add a delay for readability delay(2000); } // Function to measure the distance using the ultrasonic sensor long measureDistance() { digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); // Read the echoPin and calculate the distance long duration = pulseIn(echoPin, HIGH); long distance = duration * 0.034 / 2; // Speed of sound is 0.034 cm/us return distance; }
I Made The Ultimate Cheating Device
9:39
ChromaLock
Рет қаралды 1,4 МЛН
How to Control a 12V Motor with Arduino: Easy Wiring & Code Examples
44:13
КОГДА К БАТЕ ПРИШЕЛ ДРУГ😂#shorts
00:59
BATEK_OFFICIAL
Рет қаралды 8 МЛН
Twin Telepathy Challenge!
00:23
Stokes Twins
Рет қаралды 47 МЛН
The Singing Challenge #joker #Harriet Quinn
00:35
佐助与鸣人
Рет қаралды 35 МЛН
COMP 1002: Finding files.
18:58
Franklin Bristow
Рет қаралды 8
Hacking a weird TV censoring device
20:59
Ben Eater
Рет қаралды 3,2 МЛН
I coded one project EVERY WEEK for a YEAR
13:13
Carter Semrad
Рет қаралды 710 М.
Have you ever seen soldering THIS close?
9:53
Robert Feranec
Рет қаралды 651 М.
Making pop rocks from scratch (is complicated)
29:42
NileBlue
Рет қаралды 3,7 МЛН
How RADARs use CFAR to detect targets
7:00
Marshall Bruner
Рет қаралды 20 М.
#1099 How I learned electronics
19:55
IMSAI Guy
Рет қаралды 1,3 МЛН