Wednesday, January 12, 2011

Tilt Switch on Arduino

Another simple component is a tilt switch. This simple tilt switch has a mercury ball inside which closes the circuit and sends a high to the input if it is tilted. As an indicator I chose a LED mini board. Both boards can be found in the starter kit from seeedstudio.

This is the souce code. Plain and simple.
int tiltSwitch = 9;
int led = 8;

void setup() {
  pinMode(led,OUTPUT);
  pinMode(tiltSwitch,INPUT);
}

void loop() {
  if(digitalRead(tiltSwitch))
    digitalWrite(led,HIGH);
  else
    digitalWrite(led,LOW);
}

Here is a small demonstration:

video

No comments:

Post a Comment