Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Importance and Utility of Accelerometers
Accelerometers are vital components in various electronic devices and systems. They are used to measure acceleration forces and provide crucial input for motion detection, orientation sensing, and vibration monitoring. Whether it's in smartphones, gaming consoles, drones, or even industrial machinery, accelerometers play a pivotal role in enhancing user experience, ensuring safety, and enabling advanced functionalities.
Project: Building a Tilt Sensor using an Accelerometer
This project aims to demonstrate the practical application of an accelerometer by creating a tilt sensor. The tilt sensor will detect the angle at which it is tilted and provide a corresponding output. The objectives of this project are to:
List of Components:
You can find the ADXL335 accelerometer module and other components at the following links:
Examples:
Example 1: Basic Accelerometer Reading
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL335.h>
Adafruit_ADXL335 accelerometer;
void setup() {
Serial.begin(9600);
accelerometer.begin();
}
void loop() {
sensors_event_t event;
accelerometer.getEvent(&event);
Serial.print("X: ");
Serial.print(event.acceleration.x);
Serial.print(" m/s^2\tY: ");
Serial.print(event.acceleration.y);
Serial.print(" m/s^2\tZ: ");
Serial.print(event.acceleration.z);
Serial.println(" m/s^2");
delay(500);
}
Explanation:
Example 2: Tilt Sensor Output
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL335.h>
Adafruit_ADXL335 accelerometer;
void setup() {
Serial.begin(9600);
accelerometer.begin();
}
void loop() {
sensors_event_t event;
accelerometer.getEvent(&event);
float x = event.acceleration.x;
float y = event.acceleration.y;
float z = event.acceleration.z;
float roll = atan2(y, z) * 180 / PI;
float pitch = atan2((-1 * x), sqrt(y * y + z * z)) * 180 / PI;
Serial.print("Roll: ");
Serial.print(roll);
Serial.print(" degrees\tPitch: ");
Serial.print(pitch);
Serial.println(" degrees");
delay(500);
}
Explanation: