case 0: // will be 7 while on battdigitalWrite(ledPinR, HIGH);break;default:digitalWrite(ledPinR, HIGH);// if nothing else matches, do the default// default is optional}delay(100);buttonBool = digitalRead(buttonPin);}digitalWrite(ledPinG, LOW);digitalWrite(ledPinY, LOW);digitalWrite(ledPinR, LOW);while(digitalRead(buttonPin)); // wait until button isreleased}//*********************************************mainloop************************************void loop(){buttonState = digitalRead(buttonPin);if(buttonState == 1){voltageDisplay();delay(100);}int pulseX, pulseY; // variables to read thepulse widthsint accelerationX, accelerationY; // variables to contain the// resulting accelerationsint sum = 0;int avg = 0; //pulseX = pulseIn(xPin,HIGH); // x axis not used inpresentationpulseY = pulseIn(yPin,HIGH);// convert the pulse width into acceleration// acceleration is in milli-g's// earth's gravity is 1000 milli-g's, or 1g// accelerationX = ((pulseX / 10) - 500) * 8 // x axis not used inpresentation for(int i = 0; i < 10; i++) // 10 samples to reducesignal noise{accelerationY = ((pulseY / 10) - 500) * 8;sum += accelerationY;delay(100);}avg = sum / 10;if(avg <= -90 || avg >= -10) //test avg to determinenotification{Serial.print("TILT\n");
Leave a Comment
Can you explain your train detector how it works. Also have you looked at the Seeed RFID module ?
Yes, the train detector works by using an accelerometer to detect vibration of a passing train. The device is enclosed in a water resistant case and magnetically attached to the side of a rail. It is rather small, roughly 2"x2"x4". I had considered RFID but decided it would be too expensive and unreliable on the thousands of trains it would need to be placed on. See my the .ppt I posted as well.