Вы находитесь на странице: 1из 4

Level Indicator using the Arduino board

Goal: To develop an instrument similar to a spirit level indicator using an Arduino Board
(interfaced with 16x2 LCD Display and 3-axis accelerometer
Parts Required
1. Arduino board
2. USB Cable
3. LCD 16X2
4. ADXL335, 3-axis Accelerometer
5. Wires

Procedure:
a. 3-Axis Accelerometer

An accelerometer is used to measure the acceleration experienced by an object. The ADXL335


board is adopted to measure the acceleration experienced by the object in motion with respect to
the X or Y or Z axis. We will only be measuring movements to the X axis in this lab.

Figure 1: ADXL335, 3-axis Accelerometer Figure 2: Arduino Board

b. Interface the 3-Axis Accelerometer

Connect the 3-Axis accelerometer to the Arduino shield as shown in Figure 3.

eselabs@seas.upenn.edu Page 1 of 4
Figure 3: Interfacing ADXL335, 3-Axis Accelerometer, with the Arduino Board

c. Interface the 16X2 LCD


In order to display the measured temperature values you will have to wire the 16x2 LCD display
(Figure 4) to 6 Digital Output pins of the Arduino board.
Wire the pins according to the following assignments:

1 1 1 1 1
LCD 1 2 3 4 5 6 7 8 9 15 16
0 1 2 3 4

Arduin
GN +5 GN 1 GN 1 +5 GN
o - - - - 5 4 3 2
D V D 2 D 1 V D
Board

Figure 4: 16X2 Liquid Crystal Display


LCD Display library functions are used interface the Digital I/O pins of the Arduino board with
the LCD Display. lcd.print(xxxxx) function is used to display the measured values. Refer to
the above code.

eselabs@seas.upenn.edu Page 2 of 4
d. Compile and download the working code to the Arduino Board
Compile the following code in Arduino IDE and download it to the Arduino Board.

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const int groundpin = 14; // analog input pin0 -- ground

const int powerpin = 18; // analog input pin4 -- voltage

const int xpin = 3; // x-axis of the accelerometer

void setup() {

lcd.begin(16, 2);

Serial.begin(9600);

pinMode(groundpin, OUTPUT);

pinMode(powerpin, OUTPUT);

digitalWrite(groundpin, LOW);

digitalWrite(powerpin, HIGH);

void loop() {

int avalue = 0;

int lcd_Cursor_Position = 0;

lcd.clear();

avalue = analogRead(xpin); // read value of the X-axis acceleration

lcd_Cursor_Position = 46 - avalue/13; // calculation to position the lcd cursor

Serial.print(avalue);

lcd.setCursor((15 - lcd_Cursor_Position), 1);

lcd.print('.');

eselabs@seas.upenn.edu Page 3 of 4
lcd.setCursor((15 - lcd_Cursor_Position), 0);

lcd.print('.');

delay(100);

e. Questions:
i. Explain how do you measure/calculate the following using the Arduino Board?
a) X-Axis Acceleration(Vin)
ii. What is the degree of accuracy of the spirit level?
iii. Can you display the spirit level using other characters apart from .?
iv. Can you make the spirit level indicator . move in the direction of the acceleration?
v. Can you make one spirit level indicator ., move in opposite direction to the other?

Figure 5: Aruduino based


level indicator
GOOD LUCK!
f. Questions:
i. Using a sound buzzer, play any musical note, if the level indicator is stationary in a
particular position for more than 10 seconds.

eselabs@seas.upenn.edu Page 4 of 4