top of page

HOW TO INTERFACE AN ULTRASONIC SENSOR WITH ARDUINO USING TINKERCAD

Updated: Apr 1


Introduction :


An #Ultrasonic Sensor is an electronic device that measures the distance of an object or obstacle via Ultrasonic sound waves (that travel faster than the speed of audible sound), and it converts the reflected ultrasonic waved into electric signals. It is one of the most reliable and accurate proximity sensors.

The #sensor is based on the measurement of the time of flight of an ultrasonic pulse, which is reflected by the ground, it sends out Ultrasonic waves that has a range of frequency above human hearing. Ultrasonic Sensor is commonly used in obstacle avoiding robots and automation projects.


Let us go through the main necessary things which we should know :


Tinkercad is a powerful online platform that opens up a world of possibilities for electronics enthusiasts and robotics hobbyists. In this guide, we will explore how to utilize Tinkercad alongside the Arduino Uno and Ultrasonic Sensor to create exciting projects. Whether you are a beginner or an experienced maker, Tinkercad's intuitive interface and vast library of components make it a perfect playground for tinkering with electronics.


Understanding the Arduino Uno:


The Arduino Uno is a popular microcontroller board based on the ATmega328P. It features a wide array of digital and analog input/output pins, making it ideal for interfacing with various sensors and actuators. The board's simplicity and versatility have made it a staple in the maker community, enabling the creation of countless projects.

The Tinkercad Platform:


Tinkercad offers a user-friendly and browser-based environment that allows you to design, simulate, and prototype electronic circuits without the need for physical components. Getting started with Tinkercad is easy; simply sign up for a free account at Tinkercad.com and start exploring its features.


Tinkercad Login and Dashboard:


Upon creating an account, you will have access to your Tinkercad dashboard in tinkercad login . From here, you can start new projects, save your designs, and collaborate with others. The intuitive interface makes it effortless to drag and drop components onto the canvas, including Arduino Uno, Ultrasonic Sensors, LEDs, resistors, and more.


Integrating Ultrasonic Sensors:


The Ultrasonic Sensor, such as the HC-SR04, is a fundamental component for measuring distances in robotics and automation projects. It operates by emitting ultrasonic sound waves and measuring the time it takes for the sound to bounce back after hitting an obstacle. We'll guide you through connecting the Ultrasonic Sensor to the Arduino Uno and programming it to detect distances accurately.


Arduino IDE Integration:


Tinkercad offers seamless integration with the Arduino IDE, enabling you to write and upload custom code to your Arduino board. You can open the Arduino code editor directly from the Tinkercad interface, making it convenient to fine-tune your projects and explore advanced programming concepts.


 

LIST:


Software Components of tinkercad :

1. HCSR04:


Is the Ultrasonic Sensor used. An ultrasonic sensor contains two circular structures: one is the #transmitter and the other is a #receiver. The transmitter transmits the ultrasonic sound while the receiver receives the reflected signal.


HC-SR04
HC-SR04

Specifications:


2. Arduino Uno R3:


The #Arduino is a micro-controller board that is based on the ATmega328P, it consists of digital and analog input/output pins that are interfaced with the ultrasonic sensor (used to send and receive data). the Arduino Uno IDE consists of a Serial Monitor that displays the output.


Arduino UNO R3
Arduino UNO R3
 

CIRCUIT:


Circuit connections:


Ultrasonic sensor has 4 pins:

1. Vcc: connected to the 5V in Arduino

2. TRIG (trigger): connected to PIN 10 of the Arduino

#Trigger is used as Transmitter, this pin is used to transmit the sound from the Ultrasonic sensor. Trigger should be high. It is connected to the digital pin of the Arduino and used as output pin.

3. ECHO: connected to PIN 9 of Arduino.

Echo is used as a Receiver, it receives the sound. It is connected to the digital pin of the Arduino and used as input pin. In this diagram, we have connected Echo to pin 9.

4. GND (ground): connected to the GND of Arduino


Circuit diagram:



Explanation:


The variables and pin connections are declared and defined before both the loops


There are 2 loops in the code:

1. Void setup -code here is run only once

2. Void loop- code run continuously to measure the distance


CODE:




1. Void setup:

  • The Trig pin connected to the digital pin of the Arduino is set as output and the Echo pin as input

  • Serial.begin(96000): to start communication

2. Void loop:

  • Initially, the transmitter has to be low. Thus we have to clear the trig pin by setting it as low.

  • Lower or delay this pin for 2 microseconds.

  • Now trig pin is set as high to activate the transmitter and transmit the Ultrasonic signal.

  • A delay of 10 microseconds is given before transmitting another signal.

  • Now we have to low the trig pin again (clear)

  • To receive a signal, the echo pin is made high, thereby activating the receiver.

  • The transmitted signal is received by the receiver and the time of flight i.e., time taken to receive the signal is calculated (in microseconds)

  • the pulseIn function is used to read the length of the pulse from the Echo pin.

  • Through this time, we calculate the distance of the object or any obstacle in the path by using the formula distance= Time of flight * 0.034 / 2

  • at 20°C, the speed of sound in air (in microseconds) = 0.034

  • We divide by 2 because the signal strikes the object and bounces back to the receiver, thus we do not want to find the total distance traveled, but only the distance between the transmitter and the object.

  • Now we print the distance measured

  • Simulate the project and output can be seen on the Serial Monitor

CODE IN NOTEPAD
.txt
Download TXT • 979B
 

WORKING:


the Ultrasonic Sensor has to silver cylindrical structures (called Ultrasonic transducers) which consist of a transmitter t(hat transmits the sound waves) and a receiver.

the sensor generates a sonic burst that is emitted from the transmitter and bounces to the receiver after hitting the object. A 8 cycle ultrasound burst at 40KHz is created. the echo pin reads the time the sound waves take, in microseconds.


How to calculate distance:


Distance diagram
Distance diagram


· Blue box: Ultrasonic sensor

· Yellow box: Transmitter

· Red box: Receiver

· Green box: object/ obstacle





An Ultrasonic Sensor measures the time of flight of an Ultrasonic wave and by measuring the time, it measures the distance of the object.

When an object is placed in front of an ultrasonic sensor, ultrasonic waves are emitted on the object which is reflected towards the receiver. When the waves are transmitted and received, the total time taken for the Ultrasonic waves the hit the object and reflect back is calculated. Distance is calculated through time.

General formula for distance= T x C

To calculate object distance: D = ½ T x C

D= distance of the object or obstacle

C= speed of sound in air = 0.034 microseconds

We divide the time of flight by 2 as we do not want to measure the total distance i.e., the distance taken for the pulse to hit the object and the distance is taken for it to reflect the receiver. We only want the calculate the proximity of the object.

This gives the distance of the object from the sensor; Thus, we have to divide the time by 2.

Distance (cm) = Speed of sound (cm/µs) × Time (µs) / 2


working explanation:


Let us Explore the Power of Tinkercad.com: From 3D Design to Electronics Simulation


Introduction:


Tinkercad.com, an innovative online platform owned by Autodesk, has revolutionized the way makers and enthusiasts approach design, prototyping, and electronics simulation. In this article, we delve into the diverse features and functionalities that Tinkercad.com offers, ranging from 3D design to electronic circuit simulation, and how it has become a go-to resource for creators of all skill levels.


Tinkercad Intuitive 3D Design Tool:


Tinkercad.com's 3D design tool is a user-friendly gateway to the world of 3D modeling. With its intuitive block-based interface, beginners can effortlessly create complex 3D designs by combining and manipulating basic shapes. The platform's drag-and-drop functionality makes it accessible to novices, while its precision tools cater to advanced users seeking intricate detailing.

Designing Real-World Objects:


Tinkercad.com empowers users to design real-world objects that can be brought to life through 3D printing. From practical household items to intricate mechanical components, the platform serves as a versatile playground for designers looking to materialize their visions.


Bringing Electronics to Life in the Virtual World:


Beyond 3D design, Tinkercad.com offers an Electronics Lab that revolutionizes the way enthusiasts interact with electronic components. With an extensive library of virtual microcontrollers, sensors, actuators, and other electronic elements, users can create and simulate complex electronic circuits without needing any physical hardware.


Embracing Arduino in Tinkercad:


For Arduino enthusiasts, Tinkercad.com becomes a natural choice for prototyping and experimenting. The platform seamlessly integrates Arduino boards like the Arduino Uno, enabling users to program them using either the Arduino IDE or Tinker cad's Code Blocks. This integration facilitates hands-on learning and rapid prototyping of Arduino-based projects in a virtual environment.


Code Blocks for Intuitive Programming:


Tinkercad.com's Code Blocks feature caters to both beginners and experienced programmers. By using visual programming blocks, users can write code logic to control their 3D designs or electronic circuits without the need to write traditional lines of code. This approach demystifies programming concepts and encourages experimentation.


A Community for Inspiration and Collaboration:


Tinkercad.com fosters a vibrant community of creators, providing an avenue for inspiration and collaboration. Users can share their designs, join design challenges, and collaborate on projects. This supportive environment nurtures creativity and opens doors to new ideas.


Tinkercad.com has become a cornerstone in the maker community, offering an array of tools that bridge the gap between imagination and realization. From 3D design to electronics simulation, the platform empowers users to explore their creativity without constraints. Whether you are a seasoned designer or a curious beginner, Tinkercad.com's diverse features and supportive community make it the ultimate destination for bringing your ideas to life in the virtual world. Embrace the power of Tinkercad.com, and unlock a universe of limitless possibilities in the realms of design and electronics.

 

CONCLUSION:

The working of the ultrasonic sensor is understood. The steps and methods to interface the ultrasonic sensor with an Arduino are described. When the code is run and the circuit is simulated on TinkerCad, the distance of the object or any obstacle in the path of the sensor is calculated. The output can be seen on the Serial Monitor, when we change the location of the object, the distance is calculated and displayed on the serial monitor.

 

SEE ALSO:

the detection range of the Ultrasonic Sensor is dependent on the position and target size. The main advantage of this sensor is that, as the target size, increases, the reflected signal becomes stronger and the distance calculated is more accurate. Thus, the Ultrasonic sensor is a very useful device that has various applications such as:

· Car backing systems

· #Automation & Robotics

· To detect the depth of snow

· To find the water level of the tank

· In the production line

· Used in civil and mechanical fields for small and accurate measurements.


similar articles:

 

Follow us:

Please do follow us i.e #learnelectronicsindia to get daily updates about new blogs, videos, courses, quizzes, and contests.


Check us :


Click on the below links for internship and other opportunities:


Related Posts

See All
bottom of page