Acquire Data from an Accelerometer

This example shows how to acquire and display data from an accelerometer attached to a vehicle driven under uneven road conditions.

Discover Devices that Support Accelerometers

To discover a device that supports Accelerometers, click the name of the device in the list in the Command window, or access the device in the array returned by daq.getDevices command. This example uses National Instruments® CompactDAQ Chassis NI cDAQ-9178 and module NI 9234 with ID cDAQ1Mod3.

devices = daq.getDevices
devices = 

Data acquisition devices:

index Vendor Device ID           Description           
----- ------ --------- --------------------------------
1     ni     cDAQ1Mod1 National Instruments NI 9205
2     ni     cDAQ1Mod2 National Instruments NI 9263
3     ni     cDAQ1Mod3 National Instruments NI 9234
4     ni     cDAQ1Mod4 National Instruments NI 9201
5     ni     cDAQ1Mod5 National Instruments NI 9402
6     ni     cDAQ1Mod6 National Instruments NI 9213
7     ni     cDAQ1Mod7 National Instruments NI 9219
8     ni     cDAQ1Mod8 National Instruments NI 9265
9     ni     Dev1      National Instruments PCIe-6363
10    ni     Dev2      National Instruments NI ELVIS II

ans = 

ni: National Instruments NI 9234 (Device ID: 'cDAQ1Mod3')
   Analog input subsystem supports:
      -5.0 to +5.0 Volts range
      Rates from 1000.0 to 51200.0 scans/sec
      4 channels ('ai0','ai1','ai2','ai3')
      'Voltage','Accelerometer','Microphone','IEPE' measurement types
This module is in slot 3 of the 'cDAQ-9178' chassis with the name 'cDAQ1'.

Add an Accelerometer Channel

Create a session, and add an analog input channel with the Accelerometer measurement type.

s = daq.createSession('ni');
addAnalogInputChannel(s,'cDAQ1Mod3', 0, 'Accelerometer');

Set Session Rate and Duration

Change the scan rate to 4000 scans per second and the duration to 30 seconds.

s.Rate = 4000;
s.DurationInSeconds = 30;
s = 

Data acquisition session using National Instruments hardware:
   Will run for 30 seconds (120000 scans) at 4000 scans/second.
   Number of channels: 1
      index Type  Device   Channel   MeasurementType          Range        Name
      ----- ---- --------- ------- -------------------- ------------------ ----
      1     ai   cDAQ1Mod3 ai0     Accelerometer (Diff) -5.0 to +5.0 Volts

Set Sensitivity

You must set the Sensitivity value to the value specified in the accelerometer's data sheet. This example uses a ceramic shear accelerometer model 352C22 from PCB Piezotronics is used with 9.22 mV per Gravity.

s.Channels(1).Sensitivity = 0.00922;
ans = 

Data acquisition analog input accelerometer channel 'ai0' on device 'cDAQ1Mod3':

      Sensitivity: 0.00922
ExcitationCurrent: 0.001
 ExcitationSource: None
         Coupling: DC
   TerminalConfig: Differential
            Range: -5.0 to +5.0 Volts
             Name: ''
               ID: 'ai0'
           Device: [1x1]
  MeasurementType: 'Accelerometer'

Start Acquisition and Plot the Data

Use startForeground to acquire and plot the data.

[data,time] = startForeground(s);
xlabel('Time (Secs)');
ylabel('Acceleration (Gravities)');