Comment on page
ADXL345 with Arduino Uno
First, log in to your Simuli account and navigate to the Simuli Virtual Lab. Here we will create a new emulated instance of the
Arduino Uno. Click on the
Launchbutton under the Arduino to get started.
This will open the configuration menu. First, provide a name for the project. Then, we will add the
ADXL3453 Axes Accelerometer by selecting it from the list of available components. Finally, review that the name for the project and the selected sensors are correct and click on the
Once we have clicked on the Launch button, a new instance of the Arduino Uno will be created. It can take a few minutes, so be patient.
If you have not set up your Arduino IDE, follow the guide linked below.
Once you have the Arduino IDE ready to go, copy the code given below and paste it in the IDE.
/* Assign a unique ID to this sensor at the same time */
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);
Serial.print ("Sensor: "); Serial.println(sensor.name);
Serial.print ("Driver Ver: "); Serial.println(sensor.version);
Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);
Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" m/s^2");
Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" m/s^2");
Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" m/s^2");
Serial.println("Accelerometer Test"); Serial.println("");
/* Initialise the sensor */
/* There was a problem detecting the ADXL345 ... check your connections */
Serial.println("Ooops, no ADXL345 detected ... Check your wiring!");
/* Set the range to whatever is appropriate for your project */
/* Display some basic information on this sensor */
/* Get a new sensor event */
/* Display the results (acceleration is measured in m/s^2) */
Serial.print("X: "); Serial.print(event.acceleration.x); Serial.print(" ");
Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print(" ");
Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.print(" ");Serial.println("m/s^2 ");
Before we can compile this code, we need to install the relevant library. For this, open your Arduino IDE and go to
Toolsand then to
Manage Libraries.... This will open up the library manager, here we can search for the Adafruit ADXL345 library. Now select the library and install it. Now search for Adafruit Unified Sensor library, select the library and install it. Now we are ready to compile our code.
Install version 1.1.3 of the Adafruit Unified Sensor library instead of version 1.1.4, since it may be unstable.
savethe sketch in a folder and keep a note of that folder. We now need to get the
compiled binariesfor the sketch. Go to
Export Compiled Binary. The program will take some time to compile. Once the compilation is complete, go back to Simuli Virtual Lab and open the instance we created.
A new tab will open and we can interact with our Arduino. First, we need to
uploadour compiled binary. Click on the Arduino, this will open a file explorer, navigate to where you had stored the Arduino sketch. In the same folder, a file called
sketch.ino.standard.hexwill be present (where sketch is the name of the Arduino sketch). Select this file and click on
open. Now the hex file will be uploaded. Finally,
resetthe Arduino so that it loads the new file. To reset, just click the red power button above the top left corner of the Arduino. Now you can see the reading of the ADXL345 accelerometer in the terminal. If you change the values on the sensor, it will also be reflected in the terminal.
Now that you know how to get the readings from the ADXL345 sensor, you could try to make a fall detector. The simplest approach would be to check if there's a sharp change in acceleration in the X-axis. You can store the current reading in a temporary variable and then check the difference between it and the next reading. Keep building and have fun! 🎉