Tilt sensor rp-rub-45's technical sheet suggests the following connection diagram:
The two 5VDC inputs of the sensor were connected to the Arduino +5 volts and the output to pin 12. (Ground was also connected).
An LED was connected to PIN 3.
Then the following sketch was uploaded to try it out:
/* tilt sensor / switch
RP RUB - testing
*/
// variables for front switches
int led = 3;
int tilt = 12;
void setup()
{ Serial.begin(9600); // writing something on the monitor
pinMode(led, OUTPUT);
pinMode(tilt, INPUT);
}
void loop() {
if (digitalRead(tilt)==HIGH) {
Serial.println("tilt");
digitalWrite(led, HIGH);};
delay (1000);
digitalWrite (led, LOW);
delay (500);
}
For Arduino the sensor is always in tilt mode (the led is going on and off continuously and the monitor is printing "tilt" after "tilt" after "tilt").
Can anybody catch what I am doing wrong?
Tks.