![]() This function executes infinite times, which means executes forever unless purposefully interrupted. Next, we have the “ void loop()” function. In this function, we are configuring the TRIG and ECHO pin as OUTPUT and INPUT respectively using a “ pinMode() ” function. Next, we have a “ void setup()” function, this function executes only once in our program. And we have made 2 variables called “ duration” and the “ distance” of long and int datatype respectively, which hold the duration of the pulse and the distance calculated. GPIO pin 6 is assigned to read the ECHO signal from the ultrasonic sensor and the GPIO 7 pin is assigned to give a triggering signal to the ultrasonic sensor. Once the code gets uploaded successfully, you can see the distance measured by the ultrasonic sensor on the serial monitor.įirst, we used 2 preprocessor components for assigning the pins of Arduino to connect the Ultrasonic sensor. Step 5: Once, the board and the Port are selected, click on the upload icon. You can make sure by checking in the device manager. Step 4: Select the correct port and the board you are using.įor selecting a Board: Go to Tools > Boards > Arduino AVR Boards > Arduino UNOįor selecting Port: Go to Tools > Ports > port to which the Arduino is connected. Step 3: Using a USB cable, connect your Arduino board to the computer. Step 2: Open Arduino IDE and type the above code. Step 1: Make connections as per the circuit diagram given above. Steps to Interface the Ultrasonic Sensor with Arduino UNO This code prints the distance on the serial monitor. The above code is used to measure distance using Ultrasoinc sensor and Arduino. Make all the connections as per the diagram above.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |