Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino-Based Tilt and Distance Measurement System with ADXL335 and Ultrasonic Sensor

View and Edit Project In Cirkit DesignerImage of Arduino-Based Tilt and Distance Measurement System with ADXL335 and Ultrasonic Sensor

Circuit Documentation

Summary

This circuit is designed to measure the angle of a joint in human bones using an ADXXL335 accelerometer and an ultrasonic sensor. The data is processed by an Arduino UNO and displayed on a 16x2 LCD. The circuit also includes a trimmer potentiometer for adjusting the LCD contrast.

Component List

  1. ADXXL335 Accelerometer

    • Description: Measures acceleration in three axes (X, Y, Z).
    • Pins: VCC, X-OUT, Y-OUT, Z-OUT, GND
  2. Arduino UNO

    • Description: Microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  3. 16X2 LCD

    • Description: Alphanumeric display module with 16 columns and 2 rows.
    • Pins: VSS, VDD, V0, RS, RW, E, D1, D0, D2, D3, D4, D6, D5, D7, A, K
  4. Trimmer Potentiometer

    • Description: Adjustable resistor used for setting the LCD contrast.
    • Pins: leg1, wiper, leg2
    • Properties: Resistance: 10k Ohms
  5. Ultrasonic Sensor

    • Description: Measures distance using ultrasonic waves.
    • Pins: +VCC, Trigger, Echo, GND

Wiring Details

ADXXL335 Accelerometer

Arduino UNO

16X2 LCD

Trimmer Potentiometer

Ultrasonic Sensor

Code Documentation

#include <ADXL335.h>
#include <HCSR04.h>
#include <UnoWiFiDevEd.h>
#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 9
#define trigPin 8
#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, 1);
  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);
  }
}

This code reads data from the ADXXL335 accelerometer and the ultrasonic sensor, calculates the tilt angle and distance, and displays the results on the 16x2 LCD. The LCD displays either the tilt angle and distance or the X, Y, Z values from the accelerometer based on the state of the select switch.