The Tilt Sensor can detect when it is at an angle.
Output: This module contains two contacts and a small metal ball. When the sensor is in its upright position, the ball bridges the two contacts, completing the circuit. When the board is tilted, the ball moves, and the circuit opens. When upright, the module outputs 5V and when it is tilted, it outputs 0V. When connected to an input on the Arduino using the TinkerKit Shield, you can expect to read a value of 1023 when in its upright position and 0 when it is titled.
Module description: this module features a Tilt Sensor, a signal amplifier, the standard TinkerKit 3pin connector, a green LED that signals that the module is correctly powered and a yellow LED that lights up when a connection is made (the sensor is upright).
This module is a SENSOR. The connector is an OUTPUT which must be connected to one of the INPUT connectors on the TinkerKit Shield.
/*
Tilt Sensor
Turns on and off a T010111 LED Module connected to O0,
triggered by a T000190 Tilt Sensor attached to I0.
created 2005
by DojoDave <http://www.0j0.org>
modified 17 Jun 2009
by Tom Igoe
modified 7 dec 2010
by Davide Gomba
modified 29 Nov 2011
by Priya Kuber & Federico Vanzati
This example code is in the public domain.
*/
// include the TinkerKit library
#include <TinkerKit.h>
// creating the object ’tilt’ that belongs to the ‘TKTiltSensor’ class
// and giving the value to the desired input pin
TKTiltSensor tilt(I0);
// creating the object ‘led’ that belongs to the ‘TKLed’ class
// and giving the value to the desired output pin
TKLed led(O0);
void setup() {
// The ‘objects’ created above, eleminates the need for pinMode().
}
void loop(){
// check if the tilt Sensor is tilted.
if (tilt.get() == HIGH) { // if tilted, the tilt.state() is HIGH
led.on(); // turn LED on
}
else { // if not tilted, the tilt.state() is LOW
led.off(); // turn LED off
}
}
