Showing results for 
Search instead for 
Did you mean: 

One axis from ADXL345

Go to solution


I am completely new to using LabVIEW and would like to know how to programme a servomotor to move in the opposite direction that my ADXL345 accelerometer y-direction measures.

I want the servomotor to only do this when the acceleration is over a certain speed.

Can anybody help me with this please?

0 Kudos
Message 1 of 3
Accepted by topic author Liam3.rees



This is a really open-ended question but I'll try to give you some leads. How you go about doing this will depend greatly on the hardware you access to and how much effort you want to put into it. 


First, I would highly recommend brushing up on LabVIEW first. LabVIEW makes a lot of applications very easy but only if you have some fundamentals under your belt. This getting started guide  does a reasonable job of walking you through the basics. If you have access to LabVIEW training, I would definitely recommend that route. I would take specific note of the example finder and context help - these will be good friends while getting started. 


For the accelerometer, the datasheet specifies that it can communicate using SPI/I2C. The easy way to communicate with this is to get an I2C/SPI interface device and use the device API as shown here. Depending on what hardware you already have, you might also find a workable solution at at the bottom of this page where it lists the different options for SPI communication using LabVIEW (you can find similar documents for I2C via Google). 


For the servo, you'll need some form of PWM. If you have a DAQmx device with a counter, you can follow this guide for using a basic DAQmx counter to generate PWM signals. There are similar examples for using FPGAs to generate PWM signals which you can find by googling "LabVIEW PWM". 


I would start by establishing basic communication with your accelerometer and controlling your servo (both on their own) and try to understand how each component works. From there, integrating them will largely be a copy/paste job with some additional logic. The logic you described is very simple to implement with a basic understanding of LabVIEW.


As you go through this process, definitely leverage these forums, but you will get the highest-quality answers from very specific questions like "why do I get error XXXX, when attempting to run a counter-based task with an NI-XXXX using DAQmx <version>" (and post your code along with your question). 

Andrew Cole | Field Applications Engineer | National Instruments
0 Kudos
Message 2 of 3

Thank you very much! Very Helpful

0 Kudos
Message 3 of 3