So first we multiply the duration of this journey by the speed of sound in the air, ie 343 meters per second. this code will provide us with distance measurement and at the same time we will print it to the serial monitor int triggerPin = 11 // Trigger pin int echoPin = 12 // Echo pin long duration int distance void setup () Įxplanation of the formula Īs mentioned above, the module works by starting an ultrasound and waiting for the signal to return through space. We will use 2 cables according to the connection to control the sensor: Program and involvementĪs mentioned above, we don't need any libraries to work properly, we just need a little math. We can control the start of the ultrasound using the TRIG pin and then we monitor how long it takes for the signal on the ECHO pine to appear. We recommend studying for more information datasheet. Based on how long it takes to travel through space, we can estimate how far the obstacle is. The second receiving transducer detects the ultrasound and, by means of built-in components on the board, the ultrasound is interpreted into an electrical signal logic 1 at the output. This ultrasound travels through space and, if there is an obstacle nearby, bounces back towards the module. The human ear only hears audio signals up to 20KHz, so the sound is inaudible for us. The module generates a square signal for the transmitting transducer, which generates ultrasound at a frequency of approximately 40KHz. It is a transmitting and receiving ultrasonic speaker. The ultrasonic module HC-SR04 has 2 pieces of ultrasonic transducers built into the board.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |