arduino nano pin diagram

Step-by-Step Guide: Connecting an Ultrasonic Sensor to Arduino

INTRODUCTION

In this post we have explained how one can interface the Ultrasonic sensor with Arduino Nano pin diagram.

In this guide we will learn how to connect an Arduino Nano pin diagram with ultrasonic sensor to measure the distance and display the final output on an I2C LCD display. As a beginner it’s best to start with basic Arduino projects and learn how components interact in a circuit.

If you’re into tech or enjoy tinkering with electronics chances are you’ve heard about the Arduino Nano. The Arduino Nano has become so popular with makers due to its small size and powerful features. In this blog, we will further cover the cost, pin configuration and why the Arduino Nano stands out.

1. Compact Yet Powerful

Popular for its tiny size, the Arduino Nano is perfect for cramped space projects on the smallest scale. Nevertheless, it does not lack any little power and dish we same as execution time akin to the larger Arduino boards such as the Uno.

2. Affordable Arduino Cost

Cost is always something you cannot ignore when you’re onto working on budget friendly DIY projects. The good news is that the Arduino Nano brings all the basic features of an Arduino at a small fraction of the cost. By virtue of being an affordable, reliable microcontrollers, it’s a go to pick for both hobbyist and professional.

3. Flexible Pin Configuration

With the Arduino Nano’s 30 pin configuration, you can easily use multiple sensors, LED’s and other components when interfacing them. The Arduino Nano pin diagram explains how easy it is to connect various peripherals making this board best suited for both beginners and experts.

4. Wide Range of Applications

The Arduino Nano is versatile enough and can be used for everything from robotics to home automation. Its compatibility with different shields and modules make it possible to build different projects from basic LED control to more complex IoT system.

5. Simple Pinout for Beginners

For the Arduino Nano pin configuration, it’s pretty simple if you are just starting out with electronics. Unlike other development boards, the pinout of Bluino is simple and logical which provides beginners a smooth start when trying to experiment with various components.

6. The Sensors are easily integrated with other Arduino products.

The Arduino Nano easily keeps up with other Arduino products, so you can mix and match with other project components using additional sensors, modules, or shields. This makes it one of the best for building scalable projects because of the flexibility.

Components Required

  • Arduino Nano
  • HC-SR04 Ultrasonic Sensor
  • I2C LCD Display (like 16×2)
  • Jumper wires

Why Use Arduino Nano?

The Arduino Nano is a compact, perfect board for all sorts of tasks, based on ATmega328P microcontroller. The benefits are particularly valuable in small works or in a narrow setting. For such a project is essential to get up to date with the Arduino Nano pin diagram. It contains 30 pins of which 5 are power, 6 analog in/out, 8 digital, and few special function pins. A4 (SDA) and A5 (SCL) pins on the Nano are the I2C lines that you need to connect an I2C LCD.

Pinout Overview:

  • Digital I/O Pins: D0–D13
  • Analog Input Pins: A0–A7
  • Power Pins: 5V, GND, and Vin
  • I2C Pins: A4 (SDA) and A5 (SCL)
  • Pinout of HC-SR04 Ultrasonic Sensor
  • VCC: Power supply pin
  • GND: Ground pin
  • Trig: Thetrigger pin to send ultrasonic pulses
  • Echo: To receive reflected pulses connects it to Echo pin.

Ultrasonic Sensor

An instance of such sensor is an ultrasonic sensor where ultrasonic waves are used to detect distance from objects. It sends high frequency sound pulses out through the transmitter which bounce off the nearest object. Then the sensor measures how long it took the reflected sound wave to bounce back to the receiver and it converts this into a distance reading using the speed of sound.

Knowing which pins to use to receive and transmit data is necessary and the Arduino Nano pin diagram helps us to know which pins to use for Echo, Trig…

How to connect the ultrasonic sensor to the arduino nano.

Trig Pin to D4 on the Nano.

Echo Pin to D5 on the Nano.

VCC to the 5V pin.

GND to the GND pin.

When adding an I2C LCD display you will use the A4 (SDA) and A5 (SCL) pins on the Arduino Nano. Make sure you have installed LiquidCrystal_I2C library.

Arduino Code Explanation

The code below provides a step-by-step breakdown of how to control the ultrasonic sensor and display the readings on the Serial Monitor:

const int trigPin = 4;  // Trigger pin connected to D4 const int echoPin = 5;  // Echo pin connected to D5 long duration; int distance; void setup() {   Serial.begin(9600);          // Start serial communication   pinMode(trigPin, OUTPUT);    // Trig pin as output   pinMode(echoPin, INPUT);     // Echo pin as input } void loop() {   // Clear the Trig pin   digitalWrite(trigPin, LOW);   delayMicroseconds(2);   // Trigger the sensor   digitalWrite(trigPin, HIGH);   delayMicroseconds(10);   digitalWrite(trigPin, LOW);   // Measure the echo response time   duration = pulseIn(echoPin, HIGH);   // Calculate the distance   distance = duration * 0.034 / 2;   // Display the distance   Serial.print(“Distance: “);   Serial.print(distance);   Serial.println(” cm”);   delay(1000);  // Delay between measurements }

This code sets up the sensor and continuously measures and displays the distance.

Circuit Diagram for Arduino Nano and I2C LCD

To connect the I2C LCD to the Arduino Nano:

  • SDA to A4 on Nano
  • SCL to A5 on Nano
  • VCC to 5V
  • GND to GND

Extended Code for Displaying on I2C LCD

You can enhance the project by showing the distance measurement on an I2C LCD. You’ll need to include the LiquidCrystal_I2C library and configure the LCD using its specific I2C address.

#include #include LiquidCrystal_I2C lcd(0x27, 16, 2);  // Set the LCD address void setup() {   Serial.begin(9600);   lcd.begin();   lcd.backlight();   pinMode(trigPin, OUTPUT);   pinMode(echoPin, INPUT); } void loop() {   // Measure distance as before…   lcd.setCursor(0, 0);   lcd.print(“Distance: “);   lcd.print(distance);   lcd.print(” cm”);   delay(1000); }

Some Common Questions about Ultrasonic Sensors

Explanation:

This article will cover some common questions about ultrasonic sensors.

How far can ultrasonic sensor go?

However, maximum range is usually from 2 cm and tens of meters on a model depending on the model. For certain applications, some sensors are able to extend their range to unique ranges.

Do changes in environmental factors affect ultrasonic sensor?

Yes, temperature, relative humidity, air temperature, and even air pressure can wreak havoc on ultrasonic measurements.

Can you detect multiple objects simultaneously?

Unlike ultrasonic sensors, ultrasonic sensors only sense objects found within their range even if there are multiple objects or the objects are tightly spaced to each other, however they may have issue in discriminating between closely spaced objects as the eggs can have overlapping echoes.

So, let us have a look at the Arduino Nano pin diagram.

Arduino Nano has a small footprint and is ideal for the project that needs small footprint. It contains essential I2C pins (SDA, SCL) which enable a quick connection with interfacing devices viz, I2C LCD. Knowing the Arduino Nano pin diagram means that you can easily wire the sensors and actuators, and even displays.

Conclusion

If you’ve followed this guide, you’ve interfaced a ultrasonic sensor with your Arduino Nano. Based on this project, many applications can be derived including distance measurement systems, obstacle detection and automated control.

Code : 

//PROVIDED TO YOU BY ElectroGlobal const int trigPin = 4; // Trigger pin of the ultrasonic sensor (connected to Arduino digital pin 2) const int echoPin = 5; // Echo pin of the ultrasonic sensor (connected to Arduino digital pin 3) void setup() { Serial.begin(9600); // Initialize serial communication for debugging pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); } void loop() { // Trigger the ultrasonic sensor by sending a 10us pulse digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); // Measure the time it takes for the echo to return long duration = pulseIn(echoPin, HIGH); // Calculate the distance in centimeters // Speed of sound in air at room temperature is approximately 343 meters/second or 0.0343 cm/microsecond // Divide the duration by 2 to account for the time it takes for the sound pulse to travel to the object and back int distance = duration * 0.0343 / 2; // Print the distance to the Serial Monitor Serial.print(“Distance: “); Serial.print(distance); Serial.println(” cm”); delay(1000); // Delay for readability (adjust as needed) } Code for Arduino, Ultrasonic Sensor, and LCD Display #include #include LiquidCrystal_I2C lcd(0x27,16,2); const int trig=4; const int echo=5; void setup() { // put your setup code here, to run once: lcd.begin(); lcd.backlight(); lcd.print(“Distance : “); pinMode(trig,OUTPUT); pinMode(echo,INPUT); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: digitalWrite(trig,LOW); delay(2); digitalWrite(trig,HIGH); delay(10); digitalWrite(trig,LOW); long duration = pulseIn(echo,HIGH); long distance=duration*0.034/2; //speed of sound=340 m/s =0.034 cm/microsecond. lcd.setCursor(10,0); lcd.print(” “); lcd.setCursor(10,0); lcd.print(distance); Serial.print(“Distance : “); Serial.println(distance); Serial.print(” cm”) delay(10); }

Why Your TV Remote Cell Matters More Than You Think : 7 Surprising Reasons
7 Powerful Reasons to Choose Ni Metal Hydride Batteries Over Others

Leave a Reply

Your email address will not be published. Required fields are marked *

WhatsApp
My Cart
Wishlist
Recently Viewed
Categories
Wait! before you leave…
Get 10% additional off on your next order
ELECTRO10
Use the code above to enjoy 10% additional off on your next order at checkout