Interfacing of tilt sensor (SW200D) with an Arduino in tinkercad.
A Tilt Sensor can detect the inclination of an
object and gives its output High or Low. There is a mercury ball inside the
tilt sensor which moves when the sensor tilted and completes the circuit. So we
can use this feature to turn on and off the circuit.
In this project, we are interfacing
Tilt sensor with Arduino board in tinkercad. And controlling a
LED output when the tilt sensor tilts. It can be used like an alarm if the
sensor tilts then we can turn on the buzzer and LED flasher.
Circuit Diagram:
Components Required:
§ Arduino
UNO
§ Tilt
sensor (SW200D)
§ Resistor-1
§ LED-01
§ Connecting
wires
Connection:
The
hardware a part of this project is quite simple and easy to place together.
First of all, make the connections for the tilt sensor with the Arduino. The
connections for the tilt sensor with the Arduino given in the above circuit
diagram.
The
tilt sensor we used here is SW200D.tilt sensor has two pins one is connected to
the GND pin of an Arduino and another pin is connected to the digital pin of an
Arduino.
Connect
the one terminal of tilt sensor to the digital pin 2 using resistor.
Connect
the other terminal of tilt sensor to the GND pin of an Arduino.
Connect
the LEDs anode terminal to digital pin 9 of an Arduino.
Connect
the LEDs cathode terminal to GND pin of an Arduino.
Working of Arduino Tilt Sensor
A Tilt sensor is quite similar to a normal on off switch
only difference is it conducts current when it inclined at certain angle or in
other words, I can say it turned on only when it tilts. Due to this property,
we can use tilt sensor to detect the orientation od an object.
Now there are different types of tilt sensor out there
here we using a simple one axes inclination, a tilt switch or sensor. There are
two kinds of technology is to make the tilt sensor Mercury based and Roller
Ball based. The old ones are made of mercury. For more accuracy and results we
are having an accelerometer based 3- axis tilt sensor, using this sensor we can
detect full motion in three axes.
In SW200D tilt sensor, two metal balls are used to
close or open the switch. When we placed the sensor in upright position then metal
ball closes the contact with both the terminal and closes the switch.
When the inclination of the sensor is changed or
sensor is tilted by certain angle then metal ball are not in contact with
terminal then the switch is open.
Working of project:
As per the circuit diagram, the output
voltage of the tilt sensor is connected to the digital input pin 2 of an
Arduino. Tilt sensor gives the digital output when it tilted. output of the
tilt sensor is stored in variable name tilt sensor. Now if the tilt sensor
output is high that is 1 then set the digital pin 9 low this will make LED turn
off, if the tilt sensor output is low that is 0 then it gives the led flasher
effect.
Code
Explanation (Block Based):
First
of all, we create a variable named tilt_sensor to store the sensor value . For
declare the variable click on the variable block and create a variable, see the
below picture..
After
declaring the variable drag out the set block and set to the following blocks
Now set the variable that is
tilt_sensor to the read digital pin 2.
Take out the serial monitor block to
print the sensor value on the screen
Let’s use the main conditional
statement of the program that is ‘if’ block
Drag
the if block from the control also drag one block that is set pin block from
output and place it inside the if block. Select the digital pin 9 drag the
comparator operators from operators from math’s block. Here two conditional
statements used,
Condition1:
If the tilt sensor value is equal to the 1
then set digital pin 9 low, this will make LED turn off.
That
means sensor is not tilted.
Condition2:
If the tilt sensor value is equal to the 0
then set digital pin 9 high for 0.2 sec and low for 0.2 sec this will create
the LED flasher effect. Indicate that sensor is tilted.
Watch Working video :
Complete Arduino sketch:
int tilt_sensor = 0;
void setup()
{
pinMode(2, INPUT);
Serial.begin(9600);
pinMode(9, OUTPUT);
}
void loop()
{
tilt_sensor = digitalRead(2);
Serial.println(tilt_sensor);
if (tilt_sensor == 1) {
digitalWrite(9, LOW);
}
if (tilt_sensor == 0) {
digitalWrite(9, HIGH);
delay(200); // Wait for 200
millisecond(s)
digitalWrite(9, LOW);
delay(200); // Wait for 200
millisecond(s)
}
Comments
Post a Comment
If you any query please comment