Remote Accelerometer

Posted by on Feb 7, 2010 in Arduino | 21 Comments

ADXL335 + ATmega328 + RFM12B

What is a remote accelerometer? It’s a tiny device that has a three axis accelerometer and transmit the acceleration values to a remote host. And what is it good for? There are various uses for it. One is you attach the sensor to someone and let him jump around. On your remote machine you can use the data to produce sound or modify music. Think of it as a simplified Wiimote.

Last year Jan of electronicperformers.org came to me with the idea to make the jumping of people on a trampoline audible. We thought about it and it seemed to be easy. I tinkered with some XBees and ADXL acceleration sensors. They worked quite ok, but we had some trouble with the transmission, which sometimes just stopped for a couple of seconds. Maybe some kind of resetting, I really don’t know. Here is a video of the installation.

After that I thought, nice, but can’t we get it smaller and cheaper? So I sat down and designed a tiny custom PCB.

Features

ADXL335 + ATmega328 + RFM12B (Schematic)

I had already two JeeNodes laying around. These boards are using a RFM12B transceiver board to communicate with each other. So I decided to use the RFM12B as XBee replacement. They are really cheap, around 3 to 4 Euros.
The device should be Arduino compatible. Mostly because of the ease of development and available libraries.

  • ATmega328P, Arduino compatible microcontroller, running at 8 MHz
  • ADXL335, 3 axis accelerometer, +/- 3g
  • RFM12B radio transceiver, 868 MHz, range of up to 100 meters
  • MCP1702 linear, low-drop voltage regulator for 3.3 V, 250 mA
  • powered by a 3.7 V lipo cell, 100-300 mA
  • 6 pin ISP header for programming the bootloader
  • 6 pin serial header to attach an FTDI-cable
  • voltage sensor to tell when the battery goes low

Assembly

ADXL335 + ATmega328 + RFM12B

This is my second try on SMD. Resistors and capacitors are sized 0805. The controller is TQFP and the ADXL335 is LFCSP. LFCSP has not even pins you can hand solder. A very tiny package. As I had no stencil to place the solder paste (because I still have no laser cutter) I had to place the paste by hand. Pressing hard on the syringe and trying to work precisely at the same time is not that easy. After placing a tiny bubble of paste on every pad and gently placing all components, I heated up my hot-air rework station. Soldering with the hot-air station was easy. Not all components are well aligned, maybe because I used not enough solder paste. Often mis-aligned parts slide into place as soon as the paste gets liquid.
Next were the headers, battery connector and the RFM12B module. These were soldered traditionally with an iron.

Here is a picture of the back with the RFM12B module. The red wire is the antenna.

ADXL335 + ATmega328 + RFM12B (backside)

Software

After having the thing assembled it’s time to test it out. First is to program the Arduino bootloader. For that you need an ISP programmer. I used the USBtinyISP from adafruit. Simply select the target (Arduino Pro Mini @ 8 MHz w/ ATmega328), programmer and the port in the Arduino IDE and select “burn bootloader”. Worked on the first try.
Next is a blink sketch to check if the serial connection and the LED works. It turns out that I used too little solder paste on the controller. After resoldering that pin the LED worked.
Next sketch was to check if the ADXL works correctly, which it did. All three axis seem to work great.
After that I had to get the transceiver working. I took the RFM12 lib from Jee Labs. You have to download the Ports lib as well to get it running. First I uploaded the RF12demo sketch, which allows to setup the RFM12 module and store the configuration in EEPROM. The module was recognized and configured with no problem at all.

Time to develop the actual firmware. Here is the sketch for the sensor.

// RF12B ADXL sensor
// config D i4 g212 @ 868 MHz

#include "Ports.h"
#include "RF12.h"

int xPin = 0;
int yPin = 1;
int zPin = 2;
int ledPin = 5;
byte buf[6];

void setup() {
  rf12_config();
  pinMode(ledPin, OUTPUT);
}

int x, y, z;
unsigned long time;
byte ledOn;

void loop() {
  rf12_recvDone();
  if (rf12_canSend()) {
    x = analogRead(xPin);
    y = analogRead(yPin);
    z = analogRead(zPin);
    buf[0] = x >> 8;
    buf[1] = x;
    buf[2] = y >> 8;
    buf[3] = y;
    buf[4] = z >> 8;
    buf[5] = z;
    rf12_sendStart(0, buf, 6); 
  }  
  if (time < millis()) {
    time = millis() + 200;
    if (ledOn) {
      digitalWrite(ledPin, HIGH);
    }
    else {
      digitalWrite(ledPin, LOW);
    }
    ledOn = !ledOn;
  }
}

It's really easy. You have to call the rfm12_recvDone() to make sure the driver is still working. You have to call it, even if you are not trying to receive anything. If rfm12_canSend() returns true, we can transmit our data. We read the 3 axis acceleration and pack it into a byte array. This byte array is then transmitted. No more, no less. No acknowledge, nothing.

The receiver part looks almost the same, it receives the data and prints it on the serial port. From here on, you can do almost anything: Processing, Pure Data, Python, what ever fits best. You only have to be able to read a serial port.

Demo

For the demo I used Processing to draw a graph of every acceleration value. The red one is a bit hard to see in the video. Then I used Python with pyglet to play short wave sounds.

Outlook

3 generations of remote accelerometers

The picture above shows three generations of this device. On the left is the first implementation, using an XBee and an ADXL335, both on breakout boards, wired on a prototyping board. In the middle is the first custom PCB. As you can see, there are two air wires. That happens, when you get distracted while designing a PCB. On the right is the current version.

For the next design I would include an ON/OFF switch so you don't have to pull off the battery all the time. And maybe add a small tactile button to make more Wii-like projects possible.

Downloads and Links

21 Comments

  1. UHe
    7. February 2010

    I like Bruce :)
    About the voltage sensor, what do you use? Somehow I can’t find it in the schema..

  2. Alex
    8. February 2010

    It’s the voltage divider with R3 and R4.

  3. Khaled
    8. February 2010

    The Bruce Lee part is very funny :D
    This is a very nice project Alex! Well done…

  4. ericwertz
    11. February 2010

    Very nice work — fantastic for only the second try I’d think!

    Did you do your hot-airing from the top or from the bottom (skillet-style)?

    If from the top, paste’s enough to keep the passives from blowing-away?

    ++tkx

  5. Alex
    11. February 2010

    I did it from the top. But I reduced the fan speed a bit. So no blowing away.
    Skillet style is another option that sounds good. Haven’t tried that.

  6. Jake
    19. February 2010

    Great Project. Just wondering if the length of the wire matters. If so, what length did you use?

  7. Alex
    19. February 2010

    The length of the wire matters. It is adapted to the wavelength lambda. The length of the antenna is lambda/4.
    300.000 km / 868 MHz = lambda = 0.3456 m
    => lambda/4 = 8.64 cm

  8. Arduino Remote Accelerometer | Embeddedpub - Embedded Projects
    26. February 2010

    [...] a RFM12B transceiver board to communicate with each other. Author:Alexander Weber Project Web Page:http://tinkerlog.com/2010/02/07/remote-accelerometer/ Rating: 3 [...]

  9. Griff
    15. April 2010

    wow, cool beans – thinking of making something like this with the bluetooth chip they use in the wii-mote.

    I checked out your flickr set as well – those fireflies remind me of a setup I saw at burning man last year. All very fun stuff.

  10. Epokh
    17. April 2010

    Great job, I took your design and added a 2 axis gyroscope IZX 5000.
    I can send you the new eagle files if you want to build a 5 DOF sensor.
    Very small I like it.

  11. Alex
    17. April 2010

    Wow, that would be great!

  12. Len Williams
    16. May 2010

    I do not have the facilities or ability to construct the board, but would be prepared to pay someone to do it for me.
    I would like to buy up to 5 units fully assembled.
    Anyone willing to do this.?
    Thanks,
    Len

  13. hghoyer
    2. June 2010

    ich habe gerade Deinen Artikel bei http://tinkerlog.com/2010/02/07/remote-accelerometer/
    gelesen und finde das superinteressant!! Studiere zur Zeit Sound Studies an der UdK Berlin, wohne aber schon in Hamburg und muss nur noch meine Arbeit schreiben… Arbeite nun auch mit Pure Data… Habe mit dem Nunchuck Wii Controller experimentiert… Aber der Spukt in der Seriellen Schnittstelle solche Daten aus: http://www.supercue.de/daten/wii_nunchuck/neutral.jpg

    die lassen sich nicht einfach in pure data anbinden. zumindest weiß ich nicht, wie ich das machen soll. Mit PDuino und dem Analogen Input wird nichts angezeigt…

    Wie habt ihr bei Eurem Projekt die Daten in Pure Data eingelesen? Hat der Beschleunigungssensor einfache analoge Werte ausgegeben?

  14. Alex
    3. June 2010

    Falls Du Lust hast, kommst Du einfach zum Tinker Drinkup mal vorbei. http://paloaltona.posterous.com/
    Evtl. triffst Du da auch Jan, der die PD Geschichten macht.
    Viele Grüße,
    Alex

  15. Joozt
    17. June 2010

    Nice project!

    What kind of batteries do you use? They look very small. How long does the accelerometer run on those batteries?

  16. Alex
    18. June 2010

    I haven’t checked the actual battery life but I suppose it’s at least 3 hours. Take a look at http://www.hobbycity.com for small lipoly batteries.

  17. Fabio Varesano
    27. August 2010

    What did you use to create the PCB? Did you send the design to a manufacturer or produced it by yourself?

    How did you managed to solder the tiny little chips?

  18. Alex
    28. August 2010

    The board was processed by BatchPCB. The tiny SMT parts were placed by hand and then soldered with a hot air rework station.
    Works quite ok after a bit of practicing.

  19. Olli
    30. August 2010

    Hey! Welche Station nutzt du denn und mit wieviel Grad betreibst du die? Habe demnächst auch vor ein SMD-Projekt zum Einstieg zu planen.

  20. michael
    20. February 2011

    great project, need to do something similar myself.
    i’m wondering if you tested for range at all?
    even with just the same setup you have would be most interesting.
    thanks!

  21. jean
    16. March 2012

    Hello, very good design. Do you have any measure of the latency ? we want to use it in a musical instrument, and we need the smallest latency. I f there is one, what could be done to improve the system ?
    thank you