Thursday, September 8, 2011

Vernier Sensors and Arduino (or Teensy) for Data Logging

I've been thinking for a while about inexpensive data logging with Vernier educational sensors and a microcontroller development board. I played around with the TI MSP430 LaunchPad for a while, since it is only $4.30, but it's not quite as beginner-friendly as the Arduino. I eventually settled on the Arduino-compatible Teensy for its low price ($16) and small size.

Vernier does a good job of documenting sensor pinouts and calibration values in each sensor's manual, so I knew that this was a fairly easy project.

Unfortunately the sensors use a BT631A connector, which is difficult to find outside of the UK. I ordered this BT to RJ11 adaptor from DealExtreme, but unfortunately it's only 6P4C and we need 6P6C (6 conductors). All six pins are used by the sensor, but we really only need pins 2, 5, and 6. I'll try ordering something from UXCell or Vernier, but for now I've just used some breadboarding wires stuck into the back of the connector.

The required connections from the sensor are
pin 2 to ground (GND)
pin 5 to +5V (VCC)
pin 6 to an analog in (A0)
(I haven't gotten around to trying out the auto-ID function, but that's not an extremely useful function for my purposes anyway.)

Since this my first real microcontroller project, I followed the tutorials on the Teensy site regarding connecting something to the analog input. I modified some example code by Tom Igoe and came up with:

 Analog input, serial output
 Reads an analog input pin and prints the results to the serial monitor.
 The circuit:
 Vernier probe pin 2: Ground (GND)
 Vernier probe pin 5: +5 V (VCC)
 Vernier probe pin 6: Sensor output (A0)

 created 2011-09-08 by David Hay (misterhay)
 Some code borrowed from example by Tom Igoe

 This code is Creative Commons Attribution (

// Constants, used to give names to the pins used
const int analogInPin = A0;  // Analog input pin that the probe is attached to
const int ledPin = 11; // The Teensy on-board LED is on pin 11

// Variables
int sensorValue = 0;        // value read from the probe

// The setup, which runs once when the sketch starts
void setup()
  Serial.begin(38400);     // initialize serial communications at 38400 bps,
                           // not that this matters since it runs at USB speed
  pinMode(ledPin, OUTPUT);  // set the digital pin as an output

// The actual loop that does the sampling and output to the serial monitor
// This will continue to run as long as the Teensy is plugged in
// Use the Arduino Serial Monitor or some fancy GUI to see the output
void loop()
  // read the analog in value:
  sensorValue = analogRead(analogInPin);           
  // print the results to the serial monitor:

  // wait 10 milliseconds for the analog-to-digital converter to settle

Watch the output in a serial monitor program on your computer, and paste it into a spreadsheet program for graphing. Eventually I'll build a GUI for adjusting sample rates and number of sensors and maybe some live graphing, add some calibration, and put it in a better enclosure.