David Caditz
Published © GPL3+

Bean Accelerometer For Solar Race Car

A simple and straightforward way to measure bump, braking and turning acceleration on a student-built solar powered race car.

BeginnerProtip1 hour699
Bean Accelerometer For Solar Race Car

Things used in this project

Hardware components

LightBlue Bean+
Punch Through LightBlue Bean+
×1

Software apps and online services

Punch Through Bean Loader for IOS
Bean Console

Story

Read more

Custom parts and enclosures

Bean+ case

This is the .stl file for our Bean + case.

Code

Bean+ GetAcceleration Code File

Arduino
Upload to Bean using Bean Loader. This is basically the example GetAcceleration sketch that comes with Bean Loader with a few minor changes. We changed the accelerometer range to +/- 4G on line 16. The default is +/- 2G which was not enough range for our bump tests. We also set the sleep duration to 100ms on line 27 ito get readings on a faster timescale.
/* 
  This sketch reads the acceleration from the Bean's on-board accelerometer. 
  
  The acceleration readings are sent over serial and can be accessed in Arduino's Serial Monitor.
  
  To use the Serial Monitor, set Arduino's serial port to "/tmp/tty.LightBlue-Bean"
  and the Bean as "Virtual Serial" in the OS X Bean Loader.
    
  This example code is in the public domain.
*/

void setup() {
  // Bean Serial is at a fixed baud rate. Changing the value in Serial.begin() has no effect.
  Serial.begin();   
  // Optional: Use Bean.setAccelerationRange() to set the sensitivity to something other than the default of ±2g.
  Use Bean.setAccelerationRange(4);
}

void loop() {
  // Get the current acceleration with range of ±2g, and a conversion of 3.91×10-3 g/unit or 0.03834(m/s^2)/units. 
  AccelerationReading acceleration = Bean.getAcceleration();
  
  // Format the serial output like this:    "X: 249  Y: -27   Z: -253"
  String stringToPrint = String();
  stringToPrint = stringToPrint + "X: " + acceleration.xAxis + "\tY: " + acceleration.yAxis + "\tZ: " + acceleration.zAxis;
  Serial.println(stringToPrint);
  Bean.sleep(100);
}

Credits

David Caditz

David Caditz

1 project • 0 followers

Comments