![accelerometer adxl345 wire library code accelerometer adxl345 wire library code](https://2.bp.blogspot.com/-8R96f7CcMb8/XUaTaw-WX1I/AAAAAAAADcI/gx7mdAVeXmEIuqHiU9kYxoDN4eXZ0XuUACPcBGAYYCw/s280/arduino.jpg)
![accelerometer adxl345 wire library code accelerometer adxl345 wire library code](https://howtomechatronics.com/wp-content/uploads/2019/03/Arduino-and-ADXL345-Accelerometer-Orientation-Tracking-3D-Visualization.jpg)
The arguments of the readAccel() function are the variables that will hold the sensor readings from each axis. Next, we get the sensor readings from the accelerometer with the readAccel() function. Therefore we declare three int variables – x, y, and z. The ADX元45 outputs separate acceleration measurements for each axis, so we need a unique variable for each axis.
![accelerometer adxl345 wire library code accelerometer adxl345 wire library code](http://www.microbitlearning.com/wp-content/uploads/2017/12/microbit-and-adxl345_bb.png)
In the loop() section, the first thing we do is declare variables to hold the sensor readings. We pass it the range variable, which stores the range setting we defined when we declared it. Next, we call the setRangeSetting() function to set the sensitivity range of the sensor. This function is called through the adxl object we created earlier. Then we initialize the ADX元45 with the powerOn() function.
Accelerometer adxl345 wire library code serial#
In the setup() section we initialize the serial monitor. Next we declare a variable called range, which will store the sensitivity range we want the ADX元45 to have. When there are no arguments passed to the function, as in this case, the sensor will use I2C to communicate with the Arduino. The ADX元45() function configures the communication mode that the sensor will use to talk to the Arduino. We set the adxl object equal to the function ADX元45(). Next we create an object called adxl, which is a member of the ADX元45 class. The first thing we do is include the Sparkfun ADX元45 library. The sketch will output the raw accelerometer readings to the serial monitor: #include Once you get the library installed, upload the code below to the Arduino. To program the ADX元45 accelerometer we will use the Sparkfun ADX元45 library.