Skip to content

Commit

Permalink
Moved accelerometer examples to a common folder
Browse files Browse the repository at this point in the history
  • Loading branch information
tigoe committed Jan 18, 2019
1 parent e3881d0 commit 7f321a3
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void setup() {
while (true); // stop here and do nothing
}

accelerometer.setRange(LIS3DH_RANGE_2_G); // 2, 4, 8 or 16 G!
accelerometer.setRange(LIS3DH_RANGE_8_G); // 2, 4, 8 or 16 G!
Serial.print(accelerometer.getRange());
}

Expand All @@ -46,4 +46,3 @@ float convertReading(int reading) {
float acceleration = (float)reading / divisor;
return acceleration;
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ Adafruit_LIS3DH accelerometer = Adafruit_LIS3DH();
// Adjust this number for the sensitivity of the 'click' force
// this strongly depend on the range! for 16G, try 5-10
// for 8G, try 10-20. for 4G try 20-40. for 2G try 40-80
#define CLICKTHRESHHOLD 40
#define CLICKTHRESHHOLD 10

long steps = 0;

void setup() {
Serial.begin(9600);
pinMode(14, OUTPUT);
// 0x18 is the accelerometer's default I2C address:
if (! accelerometer.begin(0x18)) {
Serial.println("Couldn't start. Check wiring.");
Expand Down Expand Up @@ -52,6 +53,7 @@ void loop() {
* axes to see how it works:
*/
byte click = accelerometer.getClick();
digitalWrite(14, click);
if (click > 0) {
// print the whole byte in binary:
Serial.println(click, BIN);
Expand All @@ -69,5 +71,5 @@ void loop() {

// adjust the delay depending on how frequently you
// plan to detect clicks. For a step detector, 30 - 80 ms works:
delay(30);
delay(10);
}
11 changes: 11 additions & 0 deletions Accelerometers/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Accelerometers

This folder contains examples for various accelerometers.

## Analog Devices ADXL3xx

Analog Devices makes a family of accelerometers, the [ADXL3xx accelerometers](https://www.analog.com/en/parametricsearch/11175#/p4503=select%20all&p4504=select%20all&sel=row33|row34|row31|row48), with analog voltage outputs for each axis. They are very simple to use with a microcontroller, because all you need to do is power them and connect their outputs to analog inputs of your microcontroller. For Arduino, there is no library needed to use these accelerometers. Different models have different sensitivities. Sparkfun has breakout boards for the [ADXL337 and ADXL377](https://learn.sparkfun.com/tutorials/adxl337-and-adxl377-accelerometer-hookup-guide). Adafruit has boards for the [ADXL326](https://www.adafruit.com/product/1018), [ADXL335](https://www.adafruit.com/product/163), and [ADXL377](https://www.adafruit.com/product/1413).

## STMicroelectronics LIS3DH

STMicroelectronics' [LIS3DH accelerometer](https://www.st.com/en/mems-and-sensors/lis3dh.html) is an inexpensive accelerometer with a variable range of sensitivity. It connects to a microcontroller using I2C. It's a great one to use when budget is a consideration. It also has some nice features like tap detection on all three axes.

0 comments on commit 7f321a3

Please sign in to comment.