Hello friends, I hope you all are doing well. Today, I am going to share the 5th tutorial of Section-III in our Raspberry Pi Programming Course. In our previous tutorial, we have seen the interfacing of a PIR Sensor with Raspberry Pi 4. In today's tutorial, we will interface an Ultrasonic sensor with Raspberry Pi and will use Python to perform its calculations. So, let's get started:
Here's the list of components, we are going to use in today's project:
An Ultrasonic Sensor consists of a transmitter and a receiver, the transmitter emits the ultrasonic wave, which after hitting some object bounces back and receives by the ultrasonic receiver. If the Ultrasonic sensor is operated at 5V, it normally measures a distance of up to 450 centimeters.
With an ultrasonic sensor, you can measure the distance between your body and a target item, by sending and receiving ultrasonic sound waves. Unlike audible sounds, ultrasonic waves move faster. To create ultrasonic sound waves, the transmitter uses piezoelectric crystals. The sound then travels to and from the target. When it returns, the receiver gets the sound.
Mostly, ultrasonic sensors can detect objects as close as a few centimeters and as far as about five meters. Measurements of approximately 20 meters can be achieved with specially designed units.
An established technology, ultrasonic sensors have a wide range of uses, from industrial to consumer. Many new devices requiring presence detection or distance measuring can benefit from their simplicity, low cost, and durable construction. Because the hardware and software settings can be changed, they can be used in a wide range of situations.
The Ultrasonic Sensor has four connections:
An ultrasonic sensor is made up of two parts: a transmitter and a receiver, arranged side by side as close as possible. Smaller measurement errors are achieved when the receiver is near the emitter, as the path of sound from the source to the destination is straight-lined. In addition, the transmitter and reception functionalities of some ultrasonic transceivers are combined into a single device, decreasing inaccuracy to the greatest extent possible while simultaneously reducing the PCB footprint of the device.
Moving further away from the transmitter causes sound waves to broaden and the detection area increases. Ultrasonic sensors, instead of specifying a fixed detecting region, provide coverage specifications in the form of beam width or beam angle to account for this shifting terrain. For comparison, either the full beam angle or the difference from a transducer's straight line, is being used.
The beam angle has a secondary effect on the device's range. As shown in the above figure, in the case of a narrow beam, the energy of an ultrasonic pulse can travel farther, before it dissipates to unusable levels. Wide beams are better for broad detection and covering large regions, while narrow beams are better for preventing false positives, since they limit the detection region.
When looking for individual parts, transmitters and receivers for ultrasonic sensors can be found separately, or as part of a single device called an ultrasonic transceiver. In most analog ultrasonic sensor alternatives, a trigger signal is sent by the transmitter, and the receiver gets the signal as soon as the echo is recognized. In order to meet specific requirements, the designer can alter the pulse length and any encoding. The microcontroller is ultimately responsible for decoding and calculating the time between the trigger and the echo.
Ultrasonic sensors typically emit a chirp of ultrasonic radiation, that is much higher in frequency than the range of human hearing. This chirp is used to calculate the duration taken for sound to reflect from an item. This method is based on the principles of echolocation, which are used by bats to detect their prey. With this in mind, it is easy to convert the time of the ultrasonic chip to distance because the sound travels at 343 m/s in the air at ambient temperature. So, in order to calculate the distance covered, we will use the following formula:
We have divided it by 2 because the waves will cover the distance twice, one while going toward the object and the second while coming back from the object.
For example, an ultrasonic sensor emits an ultrasonic wave pointed toward a box. The waves take 0.025 seconds to bounce back. Now, in order to calculate the distance between the sensor and the box, we need to use the above formula and it gives us 4.2875 meters, as shown in the below figure:
As we discussed in the Pinout section, Ultrasonic Sensor has 4 pins in total.
If you set Vcc to 5 volts, the Echo pin will also output 5 volts. Raspberry Pi GPIO pins are prone to voltages above 3.3V, so it is imperative to avoid them. Two alternatives exist at this point:
Now let's design it with real hardware:
Double-time distance measurements are calculated with the following Python program:
For ten seconds, the trigger is engaged and the sensor uses this signal to produce sound pulses. The start time is decided as soon as the echo signal rises to a high level. Once the echo signal's negative edge is identified, the stop time is calculated. To calculate how long it will take for a sound wave to travel between two points, subtract the starting time from the final time. The speed of sound in the air is 343 m/s, so multiple this time is multiplied by the speed of sound. You must multiply the values by 100 in order to display them in cm. A speed of 34,300 cm/s is obtained. Finally, to acquire a single distance, divide everything by 2. Now let's implement this pseudocode in Python script:
When using the GPIO SetMode, the numbering scheme used to work on Raspberry Pi's GPIO can be defined in two ways: GPIO.board and GPIO.BCM, respectively.
If you want to learn more about GPIO.Board and BCM, I'd like you to check out the following picture.
It is important to take into account the limits of ultrasonic sensors before making a final decision on which sensor to use.
In this tutorial, we learned how to connect ultrasonic sensors to Raspberry Pi 4. In addition, we studied the sensor's fundamentals and the distance calculation etc. Next, we'll learn how to interface a DHT11 sensor with Raspberry Pi 4 board. Till then, take care. Have fun!!!
Almost all designers agree that Adobe Illustrator is the best tool for creating vector graphics. You can use the software to create artwork, logos, infographics, artwork, icons, and pretty much anything else you like. Adobe Illustrator uses mathematical formulas to scale images as opposed to pixels, which means resizing might strain your computer, but you get seamless and infinite resizing.
Adobe Illustrator is not free. You get a free seven-day trial and then have to pay $20.99 per month after that.
Affinity Designer is regarded by many as the best Adobe Illustrator alternative. It is great for beginners and experienced designers alike, offering an intuitive interface and user-friendly features. You can also use it for almost all design work, and its two notable features are its 8,000X history steps and 1,000,000% zoom. Both of these features make it perfect for working with clients who want even the smallest details to be perfect.
In the past few years, stickers have grown exponentially in popularity, and it is almost impossible to go a day without seeing at least one sticker in real life or on social media. They are great promotional tools because they can be added to books, flasks, guitars, laptops, social media, and so many other places. With stickers being such useful marketing tools, designers need a way to create them easily.
Picsart Sticker maker makes it easy to make your own stickers, you only have to upload your photo and work on it using the tool. The platform also makes it easier to share all your stickers online or print physical copies for distribution.
Canva is an all-around online design tool that you can use to design almost anything. It uses a drag-and-drop interface that is familiar to many people, and that makes it easy even for beginners to whip up some quick and professional-looking designs.
The tool also comes with lots of backgrounds, templates, fonts, and images to get you started. Do note that you need to pay to get access to some of the assets on the platform.
Canva also stands out due to its social media integration; you can post designs directly from Canva to your accounts.
Pixlr is an image editing tool that is a little different; it does not come with all the tools other apps do. It provides all the basic and essential tools you need without requiring you to learn how to use new tools or integrate them into your workflow. Because of this, Pixlr is perfect if you are looking for a tool to help you complete quick edits.
Pixlr is part of an ecosystem of complementary design tools and supports many of the popular design file formats. It also uses a drag-and-drop interface which makes things a lot easier, even for beginners. As with Canva, it also comes with numerous design tools and templates to get you started quickly.
There are different graphic design tools, apps, and platforms available depending on what you are looking for. For beginners, there are online apps with simple features that get simple products done, while for professionals there is software that makes it easier to handle and complete massive and complex design projects.