11/19/2023 0 Comments Ultrasonic sensor arduino test code![]() Echo to Arduino pin 13 Trig to Arduino pin 12. HC-SR04 Ping distance sensor VCC to arduino 5v GND to arduino GND. Remember we measure the time to reach the object and then the return journey, so here we are talking about 100cm (1M) round trip for this exampleġcm = 29.4mS so our timeOut value becomes 29. Copy the sketch to your Arduino and watch the blinky lights. Since sound travels at about 0.034 cm per microsecond and say we want to measure a maximum of 50 cm. When the robot is plugged into your computer, and you have an open serial monitor (select Tools from your Arduino IDE menu), you will see a continuous stream of output in the monitor describing the distance (in CM) of an object in front of the robot’s ultrasonic sensor (eyes): // Ultrasonic sensor pins define echoPin A0 define pingPin. We can set the timeout to coincide with a required max distance quite easily. If you are expecting to always range closer objects than the maximum (4M?), then to save time in your loop, you can change the value of timeOut as follows.ĭuration = pulseIn(echoPin, HIGH ) īy using a timeout, your program spends less time waiting for a reflection that isn't coming back or is too far away to be of use to you. The operation is not affected by sunlight or black material. It offers excellent non-contact range detection with high accuracy and stable readings in an easy-to-use package from 2 cm to 400 cm or 1 to 13 feet. Endless fun with ultrasonic rangers, and so cheap! The HC-SR04 ultrasonic sensor uses SONAR to determine the distance of an object just like the bats do. Connect the Trigger pin of the ultrasonic sensor to GPIO pin 3 of the Raspberry Pi Pico. ![]() delayMicroseconds(1000) - Removed this lineĭelayMicroseconds(10) // Added this line Connect a GND pin on the Raspberry Pi Pico to the GND pin of the ultrasonic sensor using a jumper wire. Original code improvements to the Ping sketch sourced from ĭigitalWrite(trigPin, LOW) // Added this line ![]() Echo to Arduino pin 13 Trig to Arduino pin 12ĥ60 ohm resistor to both LED NEG and GRD power rail
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |