Create a while loop to check the echo pin. This will send a short pulse from the ultrasonic sensor and then turn off the pulse. Pull the trigger pin high for five microsends before pulling the trigger pin low. Pull the trigger pin low, to ensure that it is not active, then pause for two microseconds. Create a function, ultra(), which will contain the code necessary to take a reading. The echo pin receives the reflected pulse, so echo is an input. For example our trigger pin is used to send a pulse of current, as such it is an output pin. These objects configure the GPIO pins of the Pico to be used with the ultrasonic sensor. Create two new objects, trigger and echo. The former is used to control GPIO pins, the latter is a library of time based functions. Import the Pin class from the machine library and then import the utime library. With the circuit built, connect your Raspberry Pi Pico and open the Thonny application.ġ. Int echoPin = 7 //declare pin for echo pin of UltraSonic sensor įloat speed = 0.(Image credit: Tom's Hardware) Software Setup of Ultrasonic Sensor on Raspberry Pi Pico Int trigPin = 8 //declare pin for trigger pin of UltraSonic sensor Measure distance using HC-SR04 ultrasonic sensor with Arduino The other 2 pins, Trig and Echo of the sensor are connected to digital pins 8 and 7 of Arduino, respectively. Now Connect all the above given required components shown in the below circuit diagram to build an Arduino Distance meter.Īs you can see from the above circuit diagram, HC-SR04 ultrasonic distance sensor power pins, Vcc and GND are connected to Arduino’s 5V and GND pins. Here are the required components along with Amazon buying links at best prices. LCD 16X2 module with or without I2C adapter
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |