How to make a DIY digital rular using ultrasonic sensor

How to make a DIY digital rular using an ultrasonic sensor

how to make a diy digital rular using arduino

Hello, welcome back. Through this tutorial, today we will talk about how to make a DIY digital rular using an ultrasonic sensor. Also, the Arduino Nano board and the Ultrasonic sensor are mainly used for this project. An LCD is used to display the values. This tutorial also includes step-by-step instructions on how to create this easily and cheaply for everyone. Also, this tutorial is especially important for school projects.

Process of this Digital Rular

When activated this project, the ultrasonic sensor calculates the distance to the barrier in front of it. This distance is then taken by the Arduino board and displayed in centimeters and inches on the LCD screen.

OK, let’s do this project step by step. The required components are as follows.

Step 1

Firstly, identify these components.

Arduino Nano boardarduino nano board with digital rular

Ultrasonic sensorUltrasonic sensor with digital rualr

LCD displaylcd display

I2C moduleI2C module

Male headermale headers with digital rular

Female headerfemale headers

Dot boarddot board

Circuit wirescircuit wires

Jumper wiresjumper wires

Foam board or Cardboardfoam board

Step 2

Secondly, cut the foam board or cardboard as follows.

cut the foam board or cardboard as follows

Step 3

Thirdly, solder the female and male headers onto the dot board as shown below.

solder the female and male headers onto the dot board

solder the female and male headers onto the dot board

Step 4

Next, solder this circuit using wires. To do this, use the circuit diagram below.

digital ruler circuit diagram

solder the female and male headers onto the dot board

Step 5

Now, adjust the 4.5 x 2.25-inch piece to fit this circuit and glue it.

adjust the 4.5 x 2.25-inch piece to fit this circuit and glue it

adjust the 4.5 x 2.25-inch piece to fit this circuit and glue it

Step 6

Then, glue the that piece and the 2.25 x 2.25-inch piece to the 4.5 x 2.25-inch piece.

glue the that piece and the 2.25 x 2.25 inch piece to the 4.5 x 2.25 inch piece.

glue the that piece and the 2.25 x 2.25 inch piece to the 4.5 x 2.25 inch piece.

Step 7

Next, adjust the foam board pieces to fit the LCD display and the ultrasonic sensor. After, glue them. For that, use the pictures below.

adjust the foam board pieces to fit the LCD display and the ultrasonic sensor

adjust the foam board pieces to fit the LCD display and the ultrasonic sensor

Step 8

Then, connect them to the Arduino board. To do this, use the circuit diagram above.

connect them to the Arduino board

Step 9

Now, glue a 2.25 x 2.25-inch piece and a 4.5 x 2.25-inch piece to the base foam board piece as shown below. After, glue the top piece of this digital rular.

glue a 2.25 x 2.25-inch piece and a 4.5 x 2.25-inch piece to the base foam board piece as shown below.

glue a 2.25 x 2.25-inch piece and a 4.5 x 2.25-inch piece to the base foam board piece as shown below.

glue the top piece of this digital ruler

Step 10

Now, connect this project to the computer using a USB cable. Ok, let’s creates the project for this project. It is as follows.

I2C library — Download

/*How to make a digital rular
* https://srituhobby.com
*/
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C dis(0x27, 16, 2);

#define Trig 2
#define Echo 3

void setup() {
pinMode(Trig, OUTPUT);
pinMode(Echo, INPUT);
dis.init();
dis.backlight();
dis.setCursor(2, 0);
dis.print(“MEASURE YOUR”);
dis.setCursor(4, 1);
dis.print(“DISTANCE”);
delay(2000);
dis.clear();

}
void loop() {
digitalWrite(Trig, LOW);
delayMicroseconds(4);
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);

long t = pulseIn(Echo, HIGH);
long inch = t / 74 / 2;
long cm = t / 29 / 2;

dis.setCursor(0, 0);
dis.print(“Distance: “);
dis.print(cm );
dis.print(“cm “);

dis.setCursor(0, 1);
dis.print(“Distance: “);
dis.print(inch );
dis.print(“inch “);

}


Code explanation

Firstly, the I2C library is included. After, an object called “lcd” was created for this library. It includes the I2C address and the LCD length and width.

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C dis(0x27, 16, 2);

Secondly, ultrasonic sensor pins are defined.

#define Trig 2
#define Echo 3

In the setup function, Ultrasonic sensor pins are set as input and output pins.

pinMode(Trig, OUTPUT);
pinMode(Echo, INPUT);

Also, the LCD display initializes and displays as “MEASURE YOUR DESTANCE” on it.

dis.backlight();
dis.setCursor(2, 0);
dis.print(“MEASURE YOUR”);
dis.setCursor(4, 1);
dis.print(“DISTANCE”);
delay(2000);
dis.clear();

In the loop function, the distances are taken from the ultrasonic sensor and printed on the LCD.

void loop() {
digitalWrite(Trig, LOW);
delayMicroseconds(4);
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);

long t = pulseIn(Echo, HIGH);
long inch = t / 74 / 2;
long cm = t / 29 / 2;

dis.setCursor(0, 0);
dis.print(“Distance: “);
dis.print(cm );
dis.print(“cm “);

dis.setCursor(0, 1);
dis.print(“Distance: “);
dis.print(inch );
dis.print(“inch “);

}

Step 11

OK, now select board and port, Afterward, upload this code to the Arduino board.

digital ruler select board

 

digital ruler select board

digital ruler select port

digital ruler select upload code

Step 12

Lastly, connect the power source to the digital rular project. For that, use a potential of 7.4v to 12v. 

connect the power source to the digital ruler project. For that, use a potential of 7.4v to 12v. 

diy digital ruler measurement

OK, enjoy this project. The full video guide is given below. So, we will meet in the next tutorial.

Leave a Reply

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