Categories

Arduino and LSM6DS3 accelerometer and gyroscope example

The LSM6DS3 is a system-in-package featuring a 3D digital accelerometer and a 3D digital gyroscope performing at 1.25 mA (up to 1.6 kHz ODR) in high-performance mode and enabling always-on low-power features for an optimal motion experience for the consumer.

The LSM6DS3 supports main OS requirements, offering real, virtual and batch sensors with 8 kbyte for dynamic data batching.

ST’s family of MEMS sensor modules leverages the robust and mature manufacturing processes already used for the production of micromachined accelerometers and gyroscopes.

The various sensing elements are manufactured using specialized micromachining processes, while the IC interfaces are developed using CMOS technology that allows the design of a dedicated circuit which is trimmed to better match the characteristics of the sensing element.

The LSM6DS3 has a full-scale acceleration range of ±2/±4/±8/±16 g and an angular rate range of ±125/±250/±500/±1000/±2000 dps.

High robustness to mechanical shock makes the LSM6DS3 the preferred choice of system designers for the creation and manufacturing of reliable products.

The LSM6DS3 is available in a plastic land grid array (LGA) package.

Key Features

Power consumption: 0.9 mA in combo normal mode and 1.25 mA in combo high-performance mode up to 1.6 kHz.
“Always-on” experience with low power consumption for both accelerometer and gyroscope
Smart FIFO up to 8 kbyte based on features set
Compliant with Android K and L
Hard, soft ironing for external magnetic sensor corrections
±2/±4/±8/±16 g full scale
±125/±250/±500/±1000/±2000 dps full scale
Analog supply voltage: 1.71 V to 3.6 V
Independent IOs supply (1.62 V)
Compact footprint, 2.5 mm x 3 mm x 0.83 mm
SPI/I2 C serial interface with main processor data synchronization feature

 

Code

I used the sparkfun library –https://github.com/sparkfun/SparkFun_LSM6DS3_Arduino_Library

This is the minimal example, there are many others

 

#include "SparkFunLSM6DS3.h"
#include "Wire.h"
#include "SPI.h"
 
LSM6DS3 myIMU; //Default constructor is I2C, addr 0x6B
 
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
delay(1000); //relax...
Serial.println("Processor came out of reset.\n");
 
//Call .begin() to configure the IMU
myIMU.begin();
 
}
 
 
void loop()
{
//Get all parameters
Serial.print("\nAccelerometer:\n");
Serial.print(" X = ");
Serial.println(myIMU.readFloatAccelX(), 4);
Serial.print(" Y = ");
Serial.println(myIMU.readFloatAccelY(), 4);
Serial.print(" Z = ");
Serial.println(myIMU.readFloatAccelZ(), 4);
 
Serial.print("\nGyroscope:\n");
Serial.print(" X = ");
Serial.println(myIMU.readFloatGyroX(), 4);
Serial.print(" Y = ");
Serial.println(myIMU.readFloatGyroY(), 4);
Serial.print(" Z = ");
Serial.println(myIMU.readFloatGyroZ(), 4);
 
Serial.print("\nThermometer:\n");
Serial.print(" Degrees C = ");
Serial.println(myIMU.readTempC(), 4);
Serial.print(" Degrees F = ");
Serial.println(myIMU.readTempF(), 4);
 
delay(1000);
}

 

 

Output

Open the serial monitor

Accelerometer:
X = -6.5480
Y = 2.1936
Z = -4.5135

Gyroscope:
X = 0.2800
Y = 0.0000
Z = 125.4400

Thermometer:
Degrees C = 25.0000
Degrees F = 77.0000

 

Link

1.71 V to 5 V LSM6DS3 SPI/I2C 3 Axis Accelerometer 3 Axis Gyroscope 6 Axis Inertial Breakout Board Embedded temperature sensor

Share

AM2320 temperature and humidity sensor and Arduino example

Temperature and humidity combined sensor AM2320 digital temperature and humidity sensor is a digital signal output has been calibrated. Using special temperature and humidity acquisition technology, ensure that the product has a very high reliability and excellent long-term stability. Sensor consists of a capacitive moisture element and an integrated high-precision temperature measurement devices, and connected with a high-performance microprocessor .

AM2320 communication using a single bus, two communication modes standard I2C. Standard single-bus interface, the system integration becomes easy and quick. Ultra-small size, low power consumption, signal transmission distance up to 20 meters, making all kinds of applications and even the most demanding applications the best choice. I2C communication using standard communication sequence, the user can directly linked to the I2C communication bus without additional wiring, simple to use. Two communication modes are used as humidity, temperature, and other digital information directly CRC checksum temperature-compensated output, users do not need to calculate the secondary digital output, and no need for temperature compensation of the humidity, temperature and humidity can be accurately information. Two communication modes are free to switch, the user can freely choose, easy to use, wide range of applications.

 

Specifications

• Operating Voltage: 3.1 VDC to 5.5 VDC
• Operating Temperature Range: -40 ° C to + 80 ° C
• Humidity Range: 0 to 99.9% RH
• Accuracy ( 25 ° C environment)
Temperature: ± 0.5 ° C
Humidity: ± 3%
• RH (10 … 90% RH)
Resolution: Temperature: 0.1 ° C
Resolution: Humidity: 0.1% RH
• Attenuation values
Temperature: <0.1 ℃ / Year
Humidity: <1% RH / Year
• Response time: Temperature: 5s
• Response Time: Humidity: 5s 1 / e (63%)
• Output signal: single bus / IIC signal
• Housing material: PC plastic

 

Layout

I couldn’t find a fritzing part but as you can see being a simple I2C sensor with a 3.1 to 5.5v range its straightforward to connect this device to an Arduino Uno

 

arduino and am2302

arduino and am2302

 

Code

You will need to install the folllowing library from https://github.com/EngDial/AM2320

This is the default example

 

#include <Wire.h>
#include <AM2320.h>
 
AM2320 th;
 
void setup() {
Serial.begin(9600);
Wire.begin();
}
 
void loop() {
Serial.println("Chip = AM2320");
switch(th.Read()) {
case 2:
Serial.println(" CRC failed");
break;
case 1:
Serial.println(" Sensor offline");
break;
case 0:
Serial.print(" Humidity = ");
Serial.print(th.Humidity);
Serial.println("%");
Serial.print(" Temperature = ");
Serial.print(th.cTemp);
Serial.println("*C");
Serial.println();
break;
}
delay(2000);
}

 

 

 

Output

Open the serial monitor

Chip = AM2320
Humidity = 47.10%
Temperature = 24.80*C

Chip = AM2320
Humidity = 48.70%
Temperature = 25.10*C

Chip = AM2320
Humidity = 53.60%
Temperature = 25.40*C

Chip = AM2320
Humidity = 55.80%
Temperature = 25.80*C

Chip = AM2320
Humidity = 59.80%
Temperature = 26.20*C

 

Links

AM2320 Digital Temperature and Humidity Sensor Replace AM2302 SHT10

https://akizukidenshi.com/download/ds/aosong/AM2320.pdf

Share

Arduino and LIS2DH three-axis linear accelerometer example

The LIS2DH is an ultra low-power high performance three-axis linear accelerometer belonging to the “femto” family, with digital I2C/SPI serial interface standard output.

The LIS2DH has dynamically user selectable full scales of ±2g/±4g/±8g/±16g and it is capable of measuring accelerations with output data rates from 1 Hz to 5.3 kHz.

The self-test capability allows the user to check the functioning of the sensor in the final application.

The device may be configured to generate interrupt signals by two independent inertial wake-up/free-fall events as well as by the position of the device itself.

The LIS2DH is available in small thin plastic land grid array package (LGA) and is guaranteed to operate over an extended temperature range from -40 °C to +85 °C.

 

Key Features

Wide supply voltage, 1.71 V to 3.6 V
Independent IOs supply (1.8 V) and supply voltage compatible
Ultra low-power mode consumptiondown to 2 µA
±2g/±4g/±8g/±16g dynamically selectable full-scale
I2 C/SPI digital output interface
2 independent programmable interrupt generators for free-fall and motion detection
6D/4D orientation detection
“Sleep to wake” and “return to sleep” function
Freefall detection
Motion detection
Embedded temperature sensor
Embedded FIFO

Connection

 

LIS2DH Arduino
VCC 5V / 3V3
GND GND
SDA A4(SDA)
SCL A5(SCL)

 

Code

This uses https://github.com/DFRobot/DFRobot_LIS2DH12/archive/master.zip , I had to change the I2C address for my board

 

#include <Wire.h>
#include <DFRobot_LIS2DH12.h>
 
 
DFRobot_LIS2DH12 LIS; //Accelerometer
 
void setup(){
Wire.begin();
Serial.begin(115200);
while(!Serial);
delay(100);
 
// Set measurement range
// Ga: LIS2DH12_RANGE_2GA
// Ga: LIS2DH12_RANGE_4GA
// Ga: LIS2DH12_RANGE_8GA
// Ga: LIS2DH12_RANGE_16GA
while(LIS.init(LIS2DH12_RANGE_16GA) == -1){ //Equipment connection exception or I2C address error
Serial.println("No I2C devices found");
delay(1000);
}
}
 
void loop(){
acceleration();
}
 
/*!
* @brief Print the position result.
*/
void acceleration(void)
{
int16_t x, y, z;
 
delay(100);
LIS.readXYZ(x, y, z);
LIS.mgScale(x, y, z);
Serial.print("Acceleration x: "); //print acceleration
Serial.print(x);
Serial.print(" mg \ty: ");
Serial.print(y);
Serial.print(" mg \tz: ");
Serial.print(z);
Serial.println(" mg");
}

 

 

Output

Open the serial monitor

Acceleration x: 0 mg y: -250 mg z: -375 mg
Acceleration x: 0 mg y: -625 mg z: -375 mg
Acceleration x: -125 mg y: -375 mg z: -500 mg
Acceleration x: -125 mg y: -500 mg z: -375 mg
Acceleration x: -125 mg y: -500 mg z: -375 mg
Acceleration x: 125 mg y: -375 mg z: -375 mg
Acceleration x: 0 mg y: -625 mg z: -375 mg
Acceleration x: 0 mg y: -375 mg z: -625 mg
Acceleration x: 0 mg y: -625 mg z: -375 mg
Acceleration x: -125 mg y: -500 mg z: -500 mg

 

Link

http://www.st.com/resource/en/datasheet/lis2dh.pdf

Share

Arduino and MPU6500 6-axis Motion Tracking device

The MPU-6500 is the company’s second-generation 6-axis Motion Tracking device for smartphones, tablets, wearable sensors, and other consumer markets.

The MPU-6500, delivered in a 3 mm x 3 mm x 0.9 mm QFN package, addresses the market requirements for high-performance applications such as pedestrian navigation, context-aware advertising, and other location-based services.

The device also supports the specifications for emerging wearable sensor applications, such as remote health monitoring, sports and fitness tracking, and other consumer applications.

Features

Digital-output of 6-axis MotionFusion data.
9-axis fused data from Motion Processing Library
Tri-Axis angular rate sensor (gyro) with a sensitivity up to 131 LSBs/dps and a full-scale range of ±250, ±500, ±1000, and ±2000dps
Tri-Axis accelerometer with a programmable full scale range of ±2g, ±4g, ±8g and ±16g
Reduced settling effects and sensor drift by elimination of board-level cross-axis alignment errors between accelerometers and gyroscopes
Digital Motion Processing™ (DMP™) engine offloads complex MotionFusion, sensor timing synchronization and gesture detection
MotionApps™ Platform support for Android, Linux, and Windows
Embedded algorithms for run-time bias and compass calibration
Digital-output temperature sensor
Digital input on FSYNC pin to support video Electronic Image Stabilization
Programmable interrupt supports gesture recognition, panning, zooming, scrolling, tap detection, and shake detection
VDD Supply voltage range of 1.71V–3.6V
Gyro operating current: 3.2mA (full power, gyro at all rates)
Gyro + Accel operating current: 3.4mA (full power, gyro at all rates, accel at 1kHz sample rate)
Accel low power mode operating currents: 18.65µA at 31.25Hz
Full Chip Idle Mode Supply Current: 6µA
400kHz Fast Mode I²C or up to 20MHz SPI serial host interfaces
10,000g shock tolerant

 

Layout

 

arduino and mpu-6500

arduino and mpu-6500

 

Code

I found a library here that seemed to work ok – http://www.uctronics.com/download/U3635_MPU6500.zip

 

// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#include "Wire.h"
 
// I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include "I2Cdev.h"
#include "MPU6050.h"
 
// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
MPU6050 accelgyro;
 
int16_t ax, ay, az;
int16_t gx, gy, gz;
 
#define LED_PIN 13
bool blinkState = false;
 
void setup() {
// join I2C bus (I2Cdev library doesn't do this automatically)
Wire.begin();
 
// initialize serial communication
// (38400 chosen because it works as well at 8MHz as it does at 16MHz, but
// it's really up to you depending on your project)
Serial.begin(38400);
 
// initialize device
Serial.println("Initializing I2C devices...");
accelgyro.initialize();
 
// verify connection
Serial.println("Testing device connections...");
Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
 
// configure Arduino LED for
pinMode(LED_PIN, OUTPUT);
}
 
void loop() {
// read raw accel/gyro measurements from device
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
 
// these methods (and a few others) are also available
//accelgyro.getAcceleration(&ax, &ay, &az);
//accelgyro.getRotation(&gx, &gy, &gz);
 
// display tab-separated accel/gyro x/y/z values
Serial.print("a/g:\t");
Serial.print(ax); Serial.print("\t");
Serial.print(ay); Serial.print("\t");
Serial.print(az); Serial.print("\t");
Serial.print(gx); Serial.print("\t");
Serial.print(gy); Serial.print("\t");
Serial.println(gz);
 
// blink LED to indicate activity
blinkState = !blinkState;
digitalWrite(LED_PIN, blinkState);
}

 

Output

Open the serial monitor

a/g: -280 -10732 -7336 32767 18392 -32768
a/g: 1620 -9008 -5564 32767 16477 -32768
a/g: 4368 -10656 -4060 32767 15867 -32768
a/g: 7724 -9952 -832 32767 14362 -32768
a/g: 6512 -6872 -340 32767 19106 -32768
a/g: 13252 -12072 3184 32767 20260 -32768
a/g: 15236 -12164 4784 32767 16474 -32768
a/g: 13152 -12644 2924 32767 10330 -32768
a/g: 16376 -11592 4708 31548 6686 -32768
a/g: 15676 -10160 4612 28194 3577 -32768
a/g: 15320 -10376 4480 25826 63 -32768
a/g: 17024 -9380 5472 25643 -483 -32768
a/g: 12064 -8728 4524 25102 -2927 -32768
a/g: 13240 -7600 5172 21817 -4007 -32768

 

Link

https://www.invensense.com/wp-content/uploads/2015/02/MPU-6500-Datasheet2.pdf

GY-6500 MPU-6500 6DOF six-axis accelerometer 6-axis attitude gyro sensor module SPI Interface MPU6500

Share