ADXL335 3-axis Accelerometer (GY-61) [S057]



https://www.youtube.com/watch?v=VhsJ0hoZzxo


*GitHubhttps://github.com/rdiot/rdiot-s057.git


* Specs

This is a very low cost break out module for the ADXL335 tripple axis accelerometer. This module includes optional header pins and provides easy access to the X, Y and Z axis analogue outputs from the accelerometer. 

It is capable of sensing forces up to 3g in all axis. A 3.3V on-board regulator is also provided allowing the module to be powered from a 3.3 to 5V power supply source.


Model number: HCMODU0070

Supply Range: 3V ~ 5V

3 Axis sensing

Full scale range: +/-3g

Sensitivity: 300mV/g (Typ)

Pinout, schematic and datasheet available after purchase.


* Contents

- Connect

Arduino Uno 

3.3V ----- VCC 

      ----- AREF

ADXL335 

VCC ----- 3.3V 

X-OUT ----- A0 

Y-OUT ----- A1 

Z-OUT ----- A2 

GND ----- GND


- Key Code

#include <Wire.h> 

#include <LiquidCrystal_I2C.h>

 

LiquidCrystal_I2C lcd(0x27,20,4);  // LCD2004

const int xpin = A0;                  // x-axis of the accelerometer

const int ypin = A1;                  // y-axis

const int zpin = A2;                  // z-axis (only on 3-axis models)

 

void setup()

{

  lcd.init();  // initialize the lcd 

  lcd.backlight();

  lcd.print("start LCD2004");

 

  analogReference(EXTERNAL);

  pinMode(xpin, INPUT);

  pinMode(ypin, INPUT);

  pinMode(zpin, INPUT);

 

  delay(1000);

 

  lcd.clear();

}

 

void loop()

{

 

  lcd.setCursor(0,0);

  lcd.print("S057:ADXL335 3axisA");

 

  int x = analogRead(xpin);

    delay(1);

  int y = analogRead(ypin);

    delay(1);

  int z = analogRead(zpin);

  //zero_G is the reading we expect from the sensor when it detects

  //no acceleration.  Subtract this value from the sensor reading to

  //get a shifted sensor reading.

  float zero_G = 512.0;

  

  //scale is the number of units we expect the sensor reading to

  //change when the acceleration along an axis changes by 1G.

  //Divide the shifted sensor reading by scale to get acceleration in Gs.

  float scale = 102.3;

 

  float xp = ((float)x - zero_G)/scale;

  float yp = ((float)y - zero_G)/scale;

  float zp = ((float)z - zero_G)/scale;

 

  lcd.setCursor(0,1);

  lcd.print("ax="+ (String)x +" x=" + (String)xp);

 

  lcd.setCursor(0,2);

  lcd.print("ay="+ (String)y +" y=" + (String)yp);

 

  lcd.setCursor(0,3);

  lcd.print("az="+ (String)z +" z=" + (String)zp);

 

  delay(500); 

}

Posted by RDIoT
|