Experiment: Arduino train detactor
How to detect trains passing by, in a non-intrusive manner? We used an arduino Due (preferred over the Uno due to 12 bit ADC) with a 3 axis accelerometer for detecting vibrations. The device was then attached to concrete structure nearby the train stop. The video shows sensitivity tests in a professional and completely controlled test environment.
The arduino code can be found below the video.
//ARDUINO CODE
double mAccelCurrent, mAccelLast;
double mAccel;
int frame = 0;
void setup() {
// declare the ledPin as an OUTPUT:
Serial.begin(57600);
analogReadResolution(12);
pinMode(24, OUTPUT);
pinMode(26, OUTPUT);
pinMode(22, OUTPUT);
mAccelCurrent = 0;
mAccelLast = 0;
mAccel = 0.0;
Serial.println("ARD");
}
void loop() {
// read the value from the sensor:
int x = analogRead(A0);
// delay(1);
int y = analogRead(A1);
// delay(1);
int z = analogRead(A2);
// delay(1);
frame++;
Serial.println("ARD " + String(frame) + " " + String(x) + " " + String(y) + " " + String(z));
mAccelCurrent = sqrt(x*x + y*y + z*z);
double delta = mAccelCurrent - mAccelLast;
mAccelLast = mAccelCurrent;
if (delta > mAccel) mAccel = delta;
else mAccel = mAccel * 0.995 ;
if (mAccel > 20) mAccel = 20;
digitalWrite(22, mAccel>= 7.5 ? HIGH : LOW);
digitalWrite(24, mAccel>= 10 ? HIGH : LOW);
digitalWrite(26, mAccel>= 15 ? HIGH : LOW);
delay(1);
}
