Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » Arduino Tilt Angle & Distance Meter with ADXL335 & HC-SR04
Arduino Projects

Arduino Tilt Angle & Distance Meter with ADXL335 & HC-SR04

Mamtaz AlamBy Mamtaz AlamUpdated:September 16, 20221 Comment4 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
Tilt Angle & Distance Meter
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

Arduino Tilt Angle & Distance Meter with ADXL335 & HC-SR04

In this post, we will learn about Tilt Angle & Distance Meter Using Accelerometer & Ultrasonic Sensor with Arduino. We have used ADXL335 3 axis accelerometer for measuring the angle in the 360-degree dimension. Similarly, we have used HC-SR04 Ultrasonic Sensor to measure distance up to 400 cm. The measured angle and distance are displayed on the 16*2 LCD Display. You can even use ADXL345 Digital Accelerometer with the I2C interface.

Here we will be interfacing ADXL335 Accelerometer and Ultrasonic Sensor HC-SR04 with Arduino to measure the angle and distance. But before getting started you can visit our earlier post to learn more about accelerometer and Ultrasonic Sensor.

  1. Interface ADXL345 Accelerometer with Arduino & Processing Animation
  2. Arduino Earthquake Detector Alarm with Seismic Graph using Accelerometer
  3. Acceleration Measurement with Accelerometer ADXL335 & Arduino
  4. Range Finder Using Ultrasonic Sensor & Arduino with OLED Display
  5. Distance Measurement Using Arduino & HC-SR04 Ultrasonic Sensor




Bill of Materials

S.N.Components NameQuantityPurchase Links
1Arduino UNO Board1Amazon | AliExpress
2Ultrasonic Sensor HC-SR041Amazon | AliExpress
3Accelerometer ADXL3351Amazon | AliExpress
416x2 LCD Display1Amazon | AliExpress
5Potentiometer 10K1Amazon | AliExpress
6Connecting Wires20Amazon | AliExpress
7Breadboard1Amazon | AliExpress

What is an Accelerometer?

Accelerometers are devices that measure acceleration, which is the rate of change of the velocity of an object. They measure in meters per second squared (m/s2) or in G-forces (g). A single G-force for us here on planet Earth is equivalent to 9.8 m/s2, but this does vary slightly with elevation (and will be a different value on different planets due to variations in gravitational pull). Accelerometers are useful for sensing vibrations in systems or for orientation applications.


ADXL335 3 Axis Accelerometer:

Introduction:

ADXL335 3 Axis Accelerometer

This Accelerometer module is based on the popular ADXL335 three-axis analog accelerometer IC, which reads off the X, Y, and Z acceleration as analog voltages. By measuring the amount of acceleration due to gravity, an accelerometer can figure out the angle it is tilted at with respect to the earth. By sensing the amount of dynamic acceleration, the accelerometer can find out how fast and in what direction the device is moving. Using these two properties, you can make all sorts of cool projects, from musical instruments (imagine playing and having the tilt connected to the distortion level or the pitch-bend) to a velocity monitor on your car (or your children’s car). The accelerometer is very easy to interface to an Arduino Micro-controller using 3 analog input pins and can be used with most other microcontrollers, such as the PIC or AVR.

Working of ADXL335 Accelerometer:

The most commonly used device is the piezoelectric accelerometer. As the name suggests, it uses the principle of piezoelectric effect. The device consists of a piezoelectric quartz crystal on which an accelerative force, whose value is to be measured, is applied.

Due to the special self-generating property, the crystal produces a voltage that is proportional to the accelerative force. The working and the basic arrangement is shown in the figure below.




HC-SR04 Ultrasonic Sensor:

What is Ultrasonic Sensor?

The HC-SR04 ultrasonic sensor uses sonar to determine the distance to an object like bats do. It offers excellent non-contact range detection with high accuracy and stable readings in an easy-to-use package.

Distance Measurement Using Arduino & HC-SR04

From 2cm to 400 cm or 1” to 13 feet. Its operation is not affected by sunlight or black material like sharp rangefinders are (although acoustically soft materials like cloth can be difficult to detect). It comes complete with the ultrasonic transmitter and a receiver module.

How does HC-SR04 Ultrasonic Sensor Works?

Ultrasonic sensors emit short, high-frequency sound pulses at regular intervals. These propagate in the air at the velocity of sound. If they strike an object, then they are reflected back as echo signals to the sensor, which itself computes the distance to the target based on the time span between emitting the signal and receiving the echo.

We will have to convert this time into cm to calculate the distance traveled. We will use the following equation to calculate the distance.

S = v * t
The ultrasonic wave is basically a sound wave that travels at a speed of 340 m/s (0.034 cm/s). The ultrasonic sensor is measuring the time it takes to hit the object and then come back but we need only time that it takes to hit the object. So, we will divide it by 2.

S = (t * 0.034)/2


Circuit: Arduino Tilt Angle & Distance Meter with ADXL335 & HC-SR04

Here is a circuit diagram for Tilt Angle & Distance Meter Using Accelerometer & Ultrasonic Sensor. Assemble the circuit as shown in the figure below.

Arduino Tilt Angle & Distance Meter with ADXL335 & HC-SR04

Arduino ADXL335 HC-SR04



Source Code/ Programs:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <LiquidCrystal.h>
#define ADC_ref 5 // ADC reference Voltage
#define zero_x 1.799
#define zero_y 1.799
#define zero_z 1.799
#define echoPin 8
#define trigPin 9
#define selectSwitch 1
#define sensitivity_x 0.4
#define sensitivity_y 0.4
#define sensitivity_z 0.4
unsigned int value_x;
unsigned int value_y;
unsigned int value_z;
float xv;
float yv;
float zv;
float angle;
LiquidCrystal lcd(12,11,5,4,3,2);
void setup()
{
analogReference(ADC_ref);
pinMode(selectSwitch,INPUT);
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
lcd.clear();
lcd.begin(16,2);
lcd.print("Tilt & Distance");
lcd.setCursor(0,2);
lcd.print(" Measurement ");
delay(3000);
lcd.clear();
}
void loop()
{
int distance,duration;
value_x = analogRead(A0);
value_y = analogRead(A1);
value_z = analogRead(A2);
xv=(value_x/1024.0*ADC_ref-zero_x)/sensitivity_x;
yv=(value_y/1024.0*ADC_ref-zero_y)/sensitivity_y;
zv=(value_z/1024.0*ADC_ref-zero_z)/sensitivity_z;
angle =atan2(-yv,-zv)*57.2957795+180;
if(digitalRead(selectSwitch)==HIGH)
{
lcd.setCursor(0,0);
lcd.print("Tilt: ");
lcd.print(angle);
lcd.print(" deg");
digitalWrite(trigPin, HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance >= 400 || distance <= 0)
{
lcd.setCursor(0,1);
lcd.print("Out of Range");
}
else
{
lcd.setCursor(0,1);
lcd.print("Distance: ");
lcd.print(distance);
lcd.print(" cm ");
}
delay(1000);
lcd.clear();
}
else
{
lcd.setCursor(0,0);
lcd.print("X=");
lcd.print(xv);
lcd.print(" Y=");
lcd.print(yv);
lcd.setCursor(0,1);
lcd.print(" Z= ");
lcd.print(zv);
delay(1000);
}
}


Video Tutorial & Explanation:

Tilt Angle & Distance Meter Using Arduino
Watch this video on YouTube.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleInterfacing 16X2 LCD Display with STM32 Bluepill Microcontroller
Next Article What is Rotary Encoder? Construction & Working of Rotary Encoder

Related Posts

DC Energy Meter using Arduino

Build a DC Energy Meter using Arduino – 32V/5A

Updated:August 26, 20252K
Interfacing ADXL375 Accelerometer with Arduino

Interfacing ADXL375 Accelerometer with Arduino (±200g)

Updated:June 28, 2025
PZEM-004T Arduino Energy Meter

DIY AC Energy Meter using PZEM-004T & Arduino

Updated:March 6, 20258K
Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Updated:February 2, 20259K
Password Based Door Lock Security System Using Arduino & Keypad

Password Based Door Lock Security System Using Arduino & Keypad

Updated:February 2, 20252436K
Earthquake Detector Alarm with with Accelerometer & Arduino

Earthquake Detector Alarm with Accelerometer & Arduino

Updated:February 2, 2025661K
View 1 Comment

1 Comment

  1. sharana basava on November 22, 2022 7:16 AM

    can I access it in pdf format?

    Reply

CommentsCancel reply

Latest Posts
ESP32 Fingerprint Attendance System with Live Web Dashboard

ESP32 Fingerprint Attendance System with Live Web Dashboard

June 21, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
Top Posts & Pages
  • ESP32 Fingerprint Attendance System with Live Web Dashboard
    ESP32 Fingerprint Attendance System with Live Web Dashboard
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • How to use Modbus RTU with ESP32 to read Sensor Data
    How to use Modbus RTU with ESP32 to read Sensor Data
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • Half Wave Rectifier Basics, Circuit, Working & Applications
    Half Wave Rectifier Basics, Circuit, Working & Applications
  • How to use INA226 DC Current Sensor with Arduino
    How to use INA226 DC Current Sensor with Arduino
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (205)
    • ESP32 MicroPython (7)
    • ESP32 Projects (82)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.