Tilt Sensor Experiments

After completing the Tilt Sensor project, test yourself by trying these experiments.

1 The tilt sensor connections are exactly the same as the push button connections. Push button schematic
To simplify the connections (just like with the push button) we can use the internal pull-down resistor instead of the external resistor. Built-in pull-down resistor












To use the internal pull-down resistor, change the tiltSensor
pinMode command to OUTPUT but use it for input.
int tiltSensor = 2;
int led = 13;

void setup() {
  pinMode(led, OUTPUT);
  pinMode(tiltSensor, OUTPUT);	// use internal pull-down resistor
}

void loop() {
  int tiltState = digitalRead(tiltSensor);
  digitalWrite(led, tiltState);
  delay(10);
}
Remove the external 22K ohm resistor and the wire that connects the resistor to GND on the breadboard and then run your modified program.
You should get the same result.
2 In addition to the internal pull-down resistor, each digital pin on the Arduino also has an interal pull-up resistor, i.e. the resistor is connected to +5V instead of to GND.

In order for this to work, the other end of the tilt sensor is connected to GND instead of to +5V.
Built-in pull-up resistor












To use the internal pull-up resistor, set the pinMode command to INPUT_PULLUP and use it for input.
Built-in pull-up resistor
Run your modified program.
You should get the opposit result, i.e., the LED turns off when the tilt sensor is not tilted (upright).
3 Create a device that will sound an audible alarm and flash a red warning light when an object has fallen over. Hint: Combine a tilt sensor, buzzer, and a red LED.