Arduion 驱动 ADXL335三轴加速度计模块
- 简介
 - 电气参数
 - 原理图
 - 接线
 - 代码
 - 实验结果
 
简介
ADXL335是一个小,薄,低功率,完整的三轴加速度计,具有信号调节电压输出。该产品测量加速度的最小全尺度范围为±3 g。它可以测量倾斜传感应用中重力的静态加速度,以及由运动、冲击或振动产生的动态加速度。
 
电气参数
| 供电电源 | 3~5 V | 
|---|---|
| 供电电流 | 400uA | 
| 通信接口 | 模拟量输出 | 
| 工作温度 | -40°~ 85° | 
原理图

 工作原理:
 该传感器是建立在硅晶片上的多晶硅表面微加工结构。多晶硅弹簧使结构悬浮在晶片表面,并提供加速阻力。结构的偏转是用一个差动电容器来测量的,它由独立的固定板和附着在移动质量上的板组成。固定板由180°的失相方波驱动。加速度使移动质量偏转,使差分电容器失衡,导致传感器输出的振幅与加速度成正比。然后使用相敏解调技术来确定加速度的幅度和方向。
接线
| Arduion | ADXL335 | OLED | 
|---|---|---|
| 5V | VCC | VCC | 
| GND | GND | GND | 
| A1 | x-OUT | - | 
| A2 | y-OUT | - | 
| A3 | Z-OUT | - | 
| A4 | - | SDA | 
| A5 | - | SCL | 
代码
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>  //1306的库文件
#define OLED_RESET 13                   //设置复位是13号引脚
Adafruit_SSD1306 display(OLED_RESET);
const int xInput = A1;
const int yInput = A2;
const int zInput = A3;
// initialize minimum and maximum Raw Ranges for each axis
int RawMin = 0;
int RawMax = 1023;
// Take multiple samples to reduce noise
const int sampleSize = 10;
void setup() 
{
  analogReference(EXTERNAL);
  Serial.begin(9600);
  display.begin(SSD1306_SWITCHCAPVCC,0x3C); //刷新
  display.clearDisplay(); //清屏
  display.setTextColor(WHITE);   //字体白色
  display.display();  //显示
}
void loop() 
{
  //Read raw values
  int xRaw = ReadAxis(xInput);
  int yRaw = ReadAxis(yInput);
  int zRaw = ReadAxis(zInput);
  // Convert raw values to 'milli-Gs"
  long xScaled = map(xRaw, RawMin, RawMax, -3000, 3000);
  long yScaled = map(yRaw, RawMin, RawMax, -3000, 3000);
  long zScaled = map(zRaw, RawMin, RawMax, -3000, 3000);
  // re-scale to fractional Gs
  float xAccel = xScaled / 1000.0;
  float yAccel = yScaled / 1000.0;
  float zAccel = zScaled / 1000.0;
  
  Serial.print("X, Y, Z:: ");
  Serial.print(xRaw);
  Serial.print(", ");
  Serial.print(yRaw);
  Serial.print(", ");
  Serial.print(zRaw);
  Serial.print(" :: ");
  Serial.print(xAccel,0);
  Serial.print("G, ");
  Serial.print(yAccel,0);
  Serial.print("G, ");
  Serial.print(zAccel,0);
  Serial.println("G"); 
  display.setTextSize(1);       //字体大小为1号
  display.setCursor(35,0); //字体排布在oled里面的行、列数
   display.print("ADXL335");
  display.setCursor(0,12); 
  display.print("X, Y, Z:"); 
  display.print(xRaw);   
  display.print(", ");
  display.print(yRaw);
  display.print(", ");
  display.print(zRaw);
  display.setCursor(0,24);
  display.print("Accel:");          
  display.print(xAccel,0); 
  display.print(" G");
  display.print(yAccel,0);
  display.print(" G");
  display.print(zAccel,0);
  display.print(" G");
 display.display();
 display.clearDisplay(); 
  delay(200);
}
// Take samples and return the average
int ReadAxis(int axisPin)
{
  long reading = 0;
  analogRead(axisPin);
  delay(1);
  for (int i = 0; i < sampleSize; i++)
  {
  reading += analogRead(axisPin);
  }
  return reading/sampleSize;
}
 
实验结果




















