Arduino Projects    |   Raspberry Pi  |     Electronic Circuits   |   AVR    |    PIC    |    8051    |    Electronic Projects

Angle and Distance Measurement Device using Arduino


Table of Contents:

  1. Angle and Distance Measurement Device using Arduino
  2. Working
  3. Measurement of Tilt/Slope/Angle
Deepesh Verma
Deepesh Verma


Required Components:

Arduino (Atmega8),

ADXL335 Accelerometer,

HCSR04 Ultrasonic Module and 16x2 LCD


This project demonstrates the interfacing of Accelerometer (ADXL335) with Arduino and calibrating it to measure Angle from a reference plane. Also measuring the distance from object in its line of sight.

The sensor data is fed to Arduino (Analog Input), it is processed and then the values are displayed on and 16x2 LCD.





ADXL335 is 3-axis accelerometer with analog output from Analog Devices. ADXL335 acceleration measurement range is +/- 3 g.

The Voltage requirement of IC-ADXL335 is typically 3.3V, but the module has on board regulator, which facilitates connection of 5V supply to it. It is extremely Low-Power device.

The module has 5 Pins, VCC(5V); GND; and X,Y,Z. The pins X,Y,Z give the acceleration in terms of Voltage, with a typical sensitivity of 300mV. The Analog signal on these pins is Digitized using ADC of Arduino, and required calibration is done through Software.


HCSR04 Ultrasonic Sensor Module:


The sensor module has 4-pins out of which Pin-1 and Pin-4 are +Vcc and Gnd respectively.

            Pin-2 is Trigger and Pin-3 is Echo pin.

            The working of sensors can be described from the below figure :


When a High pulse of 10us is applied at TRIG pin, the ultrasonic transmitter sends 8 consecutive pulses of 40kHz frequency.

As the Eighth pulse is sent the ECHO pin of the sensor becomes HIGH.

Now when the ultrasonic waves reflect from any surface and are received by the Receiver,  the ECHO pin becomes LOW.

The time it takes to leave and return to sensor is used to find the distance from the reflecting surface.

Distance in centimetres = (Time/58) cms


16x2 LCD:


16x2 alphanumeric LCD can display 16 characters in each of its row, and it has two rows. To interface an LCD we need to know about its internal registers and pin functions.

An LCD has two important registers namely command register and Data register. Both are 8-bit registers. The command register is written with various commands by the user. These commands are responsible for the functioning of LCD.

The data register is loaded with the ASCII value of the Data (Character/Number, etc.) to be displayed.

Both the registers are accessed through 8-bit Data Line (D0-D7). There is one selection line provided, namely R/S Pin, in LCD Module which selects between these two registers.

R/S=0à Command Register

R/S=1à Data Register

Apart from R/S, there are other two Pins, viz. R/W and EN.

EN pin is to enable (1) or to disable (0) the LCD.

R/W is used to select the operation ‘Read from LCD’ or ‘Write to LCD’. Logic 0 at R/W stands for Write operation and 1 for Read operation.

Apart from these pins, the last two Pins (15 & 16) on the LCD are for Backlight. And pins 1,2,3 are for GND, +VCC and +VEE(contrast adjustment) respectively.

There are various commands that need to be send to LCD so as to Initialize it, to make it work accordingly. These command are listed below.


Circuit Diagram

Source Code

 This Code is only visible to Registered users. Please Login/Register 



Comments (3)

hello sir, please give me

hello sir, please give me code of that project.


can you please elaborate

can you please elaborate the HCSR04 sensor with its calculation specially that factor of 58 used.

pin 2 and pin 3 of HCSR04

pin 2 and pin 3 of HCSR04 would be connected to which pins of Arduino ?

You are here