Have you ever struggled to fix nails on a wall perfectly parallel to the floor or ceiling? In this project, we have modeled an electronic-level device useful in placing anything perfectly parallel. This device is prototyped on the popular microcontroller board – the Arduino. It uses very few components to build, only an accelerometer sensor and a LED light. Let us quickly build this device on our favorite Arduino UNO and get everything perfectly aligned.
Components required
- Arduino UNO x1
- ADXL345 Accelerometer Sensor x1
- LED x1
- Resistor 330Ω x1
- Breadboard or a prototyping board
- Connecting wires or jumper wires
- L-shape measurement scale
Circuit connections
This device is built by interfacing Arduino with an ADXL345 accelerometer sensor and a LED. The ADXL345 is a digital sensor that talks with Arduino using an I2C interface. For interfacing ADXL345 with Arduino, connect the SDA and SCL pins of the sensor with the SDA and SCL pins of one of the I2C ports on Arduino. The following image shows available I2C ports on Arduino UNO.
The VCC and GND pins of ADXL345 are connected to 5V out and one of the Ground pins of Arduino UNO. A LED is also interfaced with the Arduino at pin 2. The LED’s anode is connected to 5V out of the Arduino UNO, while its cathode is connected to the Arduino’s pin 2. There is a current limiting resistor of 330Ω in series with the LED.
It is recommended to assemble the circuit on a prototyping board and attach an L-measurement scale to the board. The L-measurement scale must be perfectly aligned with the edges of the prototyping board or the device’s overall casing.
Circuit diagram
Arduino Sketch
How it works
ADXL345 is a 3-axis MEMS accelerometer sensor. It is a digital inertial sensor that uses a capacitive accelerometer design. It has a user-selectable range up to +/-16g, a maximum output resolution of 13 bits, a 3.9 mg/LSB sensitivity, and a maximum output data rate of 3200 Hz. ADXL345 measures static acceleration due to gravity as well as dynamic acceleration resulting from motion or shock. It can sense linear acceleration in 3 axes and detect the tilt and free fall of an object. The acceleration value obtained in gravity units can range from +2 g to -2g, or +4g to -4g, or +8g to -8g or +16g to -16g, depending upon the selected measurement range. The value of acceleration includes both static accelerations due to gravity and dynamic acceleration due to motion or shock. The following image shows acceleration values in gravity units due to gravity –
The sensor’s tilt can be detected by the acceleration’s sign and value in the x-, y- and z-axes. When only static acceleration is working on the ADXL345 sensor, the acceleration value along a given axis will be approximately +1g or -1g.
By examining the sign and value of acceleration in all axes, the exact orientation of the ADXL345 sensor in a 3-axis frame can be determined. This project uses the same principle of examining the orientation of the ADXL345 sensor. Whenever the sensor is perfectly aligned to one of the planes, the value of acceleration in one of the axes will be 1, while in the other two axes, it will be 0.
The Arduino is programmed to detect when the ADXL345 is perfectly inclined in one of the three planes. Remember that our circuit is also perfectly inclined with an L-measurement scale. So, when perfectly inclined in one of the three planes, Arduino lights up the indicator LED. This will indicate that the device and the L-measurement scale are perfectly parallel to either a horizontal or vertical plane. Using the L-measurement scale, points parallel to the horizontal or vertical plane can be marked. This can be used for fixing nails perfectly parallel to the floor or ceiling or to place objects perfectly parallel overground. It can also be used to detect if a wall or floor is inclined or flat.
In the Arduino code, we have considered some tolerance of 5% to 10% in acceleration values, as we only need to determine situations when one of the acceleration values approaches 1 or -1. In contrast, the other two acceleration values approach a value of zero. Whenever these conditions are matched, the LED lights up for 5 seconds, then switched off. This constant lookup for the matching conditions helps in avoiding human error in marking parallel points.
The code
The Arduino sketch configures the ADXL345 sensor to a +/- 2g measurement range and uses a 10-bit resolution. The script reads acceleration data of all axes and converts it to gravity units. The values of acceleration in the x-, y-, and z-axes are 10-bit and right-justified. Accordingly, the values are derived from 16-bit registers. At 10-bit resolution, the value of acceleration in the gravity unit is obtained by multiplying by 4 mg, i.e., multiplying by 0.004. After obtaining the acceleration values for all axes, the matching conditions are looked up, i.e., if one of the acceleration values approaches 1 or -1. In contrast, the other two acceleration values approach the value of zero. If any matching condition is found true, the device and the L-measurement scale are perfectly inclined to the horizontal or vertical plane in space, and parallel points can be marked using the L-scale.
The matching of conditions is indicated by lighting a LED. The LED is connected with Arduino such that it sinks current from the Arduino pin. The LED is lighted for 5 seconds by setting the Arduino pin to LOW. Then, the LED is again turned off by setting the respective Arduino pin HIGH. The accelerometer sensor is configured in the setup() function. The acceleration values in the X, Y, and Z-axis are determined in the loop() function. The matching conditions are also looked up in the loop() function, so Arduino keeps repeating it.
Result
You may also like:
Filed Under: Arduino Projects, Electronic Projects, Sensors, Tutorials, Video
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.