* The following trigPin/echoPin cycle is used to determine theĭistance of the nearest object by bouncing soundwaves off of it. PinMode(LEDPin, OUTPUT) // Use LED indicator (if required) Long duration, distance // Duration used to calculate distance Int minimumRange = 0 // Minimum range needed Int maximumRange = 200 // Maximum range needed This is actually twice the raw value to the object, because the sound must get to the object, and then we need to receive the echo signal. This will be a raw value, so we will need to scale that into a distance by dividing the value by 58.2. Then it will measure the duration between the trigger and the echo. The code below will set up the trigger pin as an output (pin 8), and the echo pin as input on pin 7. Your HC-SR04 has a range of 2cm to 400cm. We also need to make the connections for the trigger, and for the echo pins, so the trigger pin will be connected to I/O pin 8, and the echo will be connected to pin 7. We will connect 5v to the VCC pin, and GND on the Uno to GND on the sensor. Beginner Protip 1 hour 908,361 Things used in this project Story Ultrasonic Sensor HC-SR04 is a sensor that can measure distance. It can be an Ultrasonic Range Sensor or any purposes. If you wish for more accurate measurements, you can incorporate a temperature sensor, and change your calculations accordingly. You will learn how to interface Ultrasonic Sensor HC-SR04 with Arduino. ![]() The speed of sound will change with temperature, but we will keep this simple, and assume room temperature. ![]() By the time difference between the pulse and the echo, we can calculate the distance if we know the speed of sound. We can then listen for the echo from an object. Ultrasonic distance sensors provide a sound that is above the pitch at which the human ear can hear.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |