Arduino based Level Indicator - the Department of Electrical and

advertisement
UNIVERSITY OF PENNSYLVANIA
DEPARTMENT OF ELECTRICAL AND SYSTEMS ENGINEERING
ESE UNDERGRADUATE LABORATORY
ESE 205: Electrical Circuits and Systems I Laboratory
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 3axis accelerometer
Parts Required
1.
2.
3.
4.
5.
Arduino board
USB Cable
LCD 16X2
ADXL335, 3-axis Accelerometer
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
eselabs@seas.upenn.edu
Figure 2: Arduino Board
Page 1 of 4
b. Interface the 3-Axis Accelerometer
Connect the 3-Axis accelerometer to the Arduino shield as shown in Figure 3.
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:
LCD
1
2
3
4
5
6
7 8 9 10 11 12 13 14 15
Arduino
GND +5V GND 12 GND 11 Board
-
-
-
5
4
3
2
16
+5V GND
Figure 4: 16X2 Liquid Crystal Display
eselabs@seas.upenn.edu
Page 2 of 4
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.
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
eselabs@seas.upenn.edu
Page 3 of 4
Serial.print(avalue);
lcd.setCursor((15 - lcd_Cursor_Position), 1);
lcd.print('.');
lcd.setCursor((15 - lcd_Cursor_Position), 0);
lcd.print('.');
delay(100);
}
e. Questions:
i.
ii.
iii.
iv.
v.
Explain how do you measure/calculate the following using the Arduino Board?
a) X-Axis Acceleration(Vin)
What is the degree of accuracy of the spirit level?
Can you display the spirit level using other characters apart from ‘.’?
Can you make the spirit level indicator ‘.’ move in the direction of the acceleration?
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
Download