Wireless Communication with Accelerometer Data

This post will detail the current progress of the wireless communication system of our project.

The RN-XV is set to ad-hoc mode by default. This is perfect for us, as we don’t need to connect to the internet for our purposes. We will leave this setting as it is. Next we connect to the RN-XV local network and open a telnet connection. We will use putty for this connection, and the settings can be seen below.



Notice the default IP address of the ad-hoc network is with the port set to 2000.

The current code sketch for the project is posted below

int inByte = 0;   // for incoming serial data
String inputString = "";
//string flag and contact established flag
boolean stringComplete = false, contact = false;
//sensor flags
boolean startSensor1 = false;

const int xin = A2, yin = A1, zin = A0;

int sampleDelay = 500;

void setup() {
        Serial.begin(9600);     // opens serial port
        //use AREF pin for 3.3V
        //initialize sensor pins
        pinMode(xin, INPUT);
        pinMode(yin, INPUT);
        pinMode(zin, INPUT);
        //establish connection with client
        //reserve 200 bytes for the inputString:

void loop() {
  // print the string when a newline arrives:
  if (stringComplete) {
    //set sensor1 flag if start1 entered
    if (inputString == "start1") {startSensor1 = true;}
    //stop sensor if stop1 entered
    if (inputString == "stop1") {startSensor1 = false;}
    for debugging
    // clear the string:
    inputString = "";
    stringComplete = false;
  if (contact) {
    if (startSensor1){readSensor1();}

  SerialEvent occurs whenever a new data comes in the
 hardware serial RX.  This routine is run between each
 time loop() runs, so using delay inside loop can delay
 response.  Multiple bytes of data may be available.
void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    if (inChar == '\n') {
      stringComplete = true;
    // add it to the inputString if it is alphanumeric
    if ((inChar > 65 && inChar  48 && inChar < 57)) 
      inputString += inChar;

void establishContact() {
  while (!Serial.available()) {
    Serial.println("Enter Input");   // send an initial string
  Serial.println("Connection Established");
  contact = true;

void readSensor1() {
  //identifier string
  Serial.print("Accel: ");
  //read xin
  Serial.print( analogRead(xin) );
  //read yin
  Serial.print( analogRead(yin) );
  //read zin
  Serial.println( analogRead(zin) );

The code will keep prompting the client until it gets a response:



And then will open communication once it receives input:



At this time you can start reading from the accelerometer sensor by issuing the command “start1” and stop it again by typing “stop1.” Right now we are sampling at 2Hz, but we can go higher.


The values are the raw outputs from the analog pins of an ADXL335 accelerometer. These readouts can be converted into something more readable like degrees, or they can control a visual representation of orientation.



Battery Testing

Li-ion Charging 

All batteries were tested for charging capabilities; only one was found to be faulty.

Li-ion DischargingUntitled

In order to discharge the battery, a motor was utilized as the load. The voltage values were notated every 60 seconds. The circuitry is depicted above.

Arduino Sketch

This sketch continuously reads the voltage of the battery as it discharges from the load (motor); the delay was set to 60 seconds.

Arduino Serial Monitor

Data Analysis

Battery 1 and Battery 8 discharge characteristics were plotted on the same graph in order to sufficiently analyze the two battery types.

Accelerometer ADXL 335 Testing

Part 1: Calibration

The Setup:

ADXL335 Calibration Setup

The Output (Viewed from the Arduino Serial Monitor):

ADXL335 calibration output

Resources/References: The setup and code used for calibration follow this tutorial: http://learn.adafruit.com/adafruit-analog-accelerometer-breakouts/programming.

Part 2: Orientation Sensing

The Setup:

ADXL335 Orientation Setup

The Output (Viewed from the Arduino Serial Monitor):

ADXL335 Orientation output

Resources/References: The setup and code used for orientation sensing follow this tutorial: http://bildr.org/2011/04/sensing-orientation-with-the-adxl335-arduino/.

Notes: The values for the orientation sensing output are in degrees.

Reading from Multiple Sensors

The Setup:

Mic and Temp Sensor Setup

The Output (Viewed from the Arduino Serial Monitor):

Mic and Temp Sensor output

Resources/References: The setup and code used here were adapted from the setups and codes of the microphone and temperature sensor, as well as with reference to the code available at http://arduino.cc/en/Tutorial/BlinkWithoutDelay#.Uwtd0oXEEcI .

Notes: The temperature sensor is connected to analog pin 0. The microphone is connected to analog pin 1. The millis() function was necessary in order to control the display rate of the sensor data to the serial monitor without using delay().

Microphone Testing

The Setup:

Microphone Sensor Setup

The Output (Viewed from the Arduino Serial Monitor):

Microphone Sensor Setup

Resources/References: The example code provided at http://playground.arduino.cc/Main/Average and http://www.arduino.cc/en/Tutorial/KnockSensor#.Uv-wLYXEEcI were used to develop the code for this test which is available here.

Notes: The test shown here for the microphone causes the on board LED (connected to pin13) to light up when the volume is greater than a chosen threshold. The setup consists of the electret microphone’s VCC pin connected to 5V, GND pin connected to ground, and AUD pin connected to the arduino’s A0 analog pin.

Accelerometer ADXL362 Testing

Part 1: Simple Read

The Setup:

Simple Read

The Output (Viewed from the Arduino Serial Monitor):

simple read sample

Resources/References: The setup and code used follow this tutorial: http://ez.analog.com/docs/DOC-2222. The code library can be found here: http://annem.github.io/ADXL362/.

Notes: The tutorial uses a 3.3V logic arduino. The arduino nano used here uses 5V logic. A simple logic level shifter was created to shift down the 5V to 3.3V by making voltage dividers using 2k ohm and 1k ohm resistors. The voltage dividers were used for the MOSI, SCK, and CS lines.

     Also important to note is the difference in the Reg 2C value here from the one in the tutorial. The value here is 13 while the value in the tutorial is 3. The cause of the difference has not been determined. A search of the ADXL362 datasheet reveals that register 2C is the FILTER_CTL register which controls the output data rate (ODR). A value of 13 sets the bandwidth of the antialiasing filters to 1/4 the ODR, and the ODR to 100 Hz.

     The values read from the sensor on the serial monitor are not as stable in this test as they are in the tutorial. This can be seen most easily is the XData. The snapshot of the data above shows the XData varying from -10 to 28.

Part 2: Motion-Activated Sleep

The Setup:

accel sleep int1

The Output (Viewed from the Arduino Serial Monitor):

accel sleep sample 1

accel sleep sample 2

Resources/References: The setup and code used follow this tutorial: http://ez.analog.com/docs/DOC-2261. The code library can be found here: http://annem.github.io/ADXL362/ and https://github.com/rocketscream/Low-Power.

Notes: The setup is the same as the Simple Read setup, except for the addition of a connection for Int1 of the accelerometer to d2 on the arduino. The data read on the serial monitor is once again more erratic than the data seen in the tutorial, but the functionality of the device entering a sleep mode after sitting still for a few seconds and waking upon movement works.