1. Introduction
This project demonstrates how to interface an ADXL3xx series (like the ADXL335) 3-axis accelerometer with an Arduino Uno. Accelerometers measure static acceleration (gravity) to detect tilt and dynamic acceleration to detect motion, shock, or vibration. This specific setup uses a clever "no-wires" approach by repurposing analog pins to power the sensor directly.
2. Components
Arduino Uno (or any compatible board)
ADXL3xx Accelerometer Breakout Board (e.g., ADXL335)
Breadboard
Jumper Wires (though the code supports direct mounting)
3. Circuit and Connections
The wiring follows a specific sequence to allow the sensor to be powered directly from the Analog Header:
| Accelerometer Pin | Arduino Pin | Function |
| ST (Self Test) | A0 | Testing the sensor integrity |
| Z-Axis | A1 | Analog input for vertical movement |
| Y-Axis | A2 | Analog input for forward/backward movement |
| X-Axis | A3 | Analog input for left/right movement |
| GND | A4 | Ground (set to LOW in code) |
| VCC | A5 | Power (set to HIGH in code) |
4. Circuit Working
The circuit operates by converting physical acceleration into variable voltage. The ADXL3xx outputs an analog voltage for each axis proportional to the G-force it senses.
Power Trick: Instead of using the dedicated 5V/GND pins, we use A4 and A5. By setting A4 to
LOWand A5 toHIGHvia software, they act as a power supply for the low-current sensor.Signal Processing: The Arduino's ADC (Analog-to-Digital Converter) reads these voltages on pins A1, A2, and A3 and converts them into a digital range of 0 to 1023.
5. Code
const int powerpin = 19; // analog input pin 5 -- voltage
const int xpin = A3; // x-axis
const int ypin = A2; // y-axis
const int zpin = A1; // z-axis
void setup() {
Serial.begin(9600);
// Repurposing analog pins as Power and Ground
pinMode(groundpin, OUTPUT);
pinMode(powerpin, OUTPUT);
digitalWrite(groundpin, LOW);
digitalWrite(powerpin, HIGH);
}
void loop() {
Serial.print(analogRead(xpin));
Serial.print("\t");
Serial.print(analogRead(ypin));
Serial.print("\t");
Serial.print(analogRead(zpin));
Serial.println();
delay(100);
}
6. Code Working
Pin Definition: The code defines
groundpinas 18 andpowerpinas 19. On an Arduino Uno, digital pins 14–19 correspond to Analog pins A0–A5.Initialization: In
setup(), the serial monitor is started. The power pins are set toOUTPUTto provide the necessary electricity to the sensor.Data Acquisition: In
loop(),analogRead()captures the raw voltage levels from the X, Y, and Z pins.Output: These values are printed to the Serial Plotter or Serial Monitor, separated by tabs for easy reading.
7. Tips
Voltage Warning: Most ADXL335 sensors are 3.3V devices. While this code works by using an Arduino pin as a high signal, ensure your specific breakout board has a voltage regulator if you connect it to a standard 5V rail.
Calibration: Raw values (e.g., 400-600) don't mean much without calibration. You'll need to map these values to actual G-force or degrees of tilt for advanced projects.
8. Uses
Tilt Sensing: Used in auto-leveling cameras or controllers.
Gesture Control: Creating "air-mice" or wearable controllers.
Drop Detection: Protecting hard drives or sensitive equipment.
Gaming: Tilt-to-steer mechanics in DIY gaming peripherals.
9. Conclusion
Interfacing an ADXL3xx with an Arduino is a straightforward way to add motion sensitivity to your projects. By utilizing the analog pins for power, you reduce wiring complexity, making it an ideal setup for beginners or compact builds.