Overview
This project tells about how to use a Tilt sensor to glow a LED this is very
useful to detect whether the sensor is tilted or not.
In this project Tilt sensor is used to detect whether the sensor is tilted or
not if the sensor is tilted the LED will glow.
Hardware required
- Arduino Uno R3
- LED
- Resistor
- Jumper Wires
- Tilt Sensor
Schematic Diagram
Fig 1. Circuit Diagram
Arduino Code :
int tilt = 2; // the number of the input pin
int led = 13; // the number of the output pin
void setup()
{
pinMode(tilt, INPUT);
pinMode(led, OUTPUT);
}
void loop()
{
int reading;
reading = digitalRead(tilt);
if(reading)
digitalWrite(led, LOW);
else
digitalWrite(led, HIGH);
}
Precautions
- Connections should be done properly.
- Arduino is case Sensitive so code accordingly.
- Give different and appropriate colors to the wires.
- Use resistors for sensors and LED’s.