Hi all, new to the forums and Arduino world in general. I am a physics teacher and have an idea for a sensor that would prove to be very useful if it can be done. My students have built K'Nex roller coasters and I would like them to be able to make direct acceleration measurements of the cart (sensor attached to cart) as it travels around the path so can't be connected to computer. In my head it seems feasible but haven't been able to get far. This is what I have for code:
const int groundpin = 18; // analog input pin 4 -- ground
const int powerpin = 14; // analog input pin 0 -- voltage
const int xpin = A1; // x-axis
const int ypin = A2; // y-axis
const int zpin = A3; // z-axis
void setup()
{Serial.begin(9600);
pinMode(groundpin, OUTPUT);
pinMode(powerpin, OUTPUT);
digitalWrite(groundpin, LOW);
digitalWrite(powerpin, HIGH);
}
void loop()
{
int x = analogRead(xpin); //read from xpin
int y = analogRead(ypin); //read from ypin
int z = analogRead(zpin); //read from zpin
float zero_G = 512.0; //ADC is 0~1023 the zero g output equal to Vs/2
//ADXL335 power supply by Vs 3.3V
float scale = 102.3; //ADXL335330 Sensitivity is 330mv/g
//330 * 1024/3.3/1000
Serial.print("\t");
Serial.print(((float)x-340)/65*9.8); //print y value on serial monitor
Serial.print("\t");
Serial.print(((float)y-346)/68.5*9.8); //print y value on serial monitor
Serial.print("\t");
Serial.print(((float)z-414)/68*9.8); //print z value on serial monitor
Serial.print("\t");
Serial.print(millis());
Serial.println ();
delay(1000); //wait for 1 second while testing to slow data through the serial monitor but will be 100
}
Some more details and problems:
-
Accelerometer (ADXL 335) data is hard to work with. The above code that I found/combined/edited from a number of helpful places (can't remember now) can convert the values from the raw data to be essentially zero when sitting flat. As per accelerometers, once rotated, the data departs from zero even if still. Is it possible to ever get just dynamic data? Essentially reads zero if still regardless of orientation. I read that I might need a gyro but not sure.
-
To be portable, I intend to have an SD card breakout to write a file to that could then be transferred to a computer easily. I figure a .txt file with a few tabbed columns would suffice for easy import into excel but no experience working with this at all from an arduino coding end. Help!? :o
-
Battery wise, haven't gotten that far but I would get a LiPo with an appropriate charger board.
-
Currently developing with a UNO R3 but smaller would be nice if there are any suggestions. The custom K'nex roller coaster carts that I have 3d printed have only about a 5cm square platform area.
If you need any other information or details, let me know. ANY help you can provide is greatly appreciated.