Life2Coding
Improvised Representation of Tilt Sensor

Hello! Over here I have demonstrated the use of Improvised Representation of Tilt Sensor to measure any vibration, tilting, or movement.

Tilt Sensor act like a switch, for which, whenever it is tilted from one location to the other and it would react correspondingly. It has two poles inside or positive negative scheme. If it is tilted the circuitry will be closed or open instantly that produces analog signals that we can use to do our task.

Below I’ve added buzzer alarm and Tilt monitor as LED so that every time it is tilted we are aware of it. Also a switch which will represents out Tilt sensor because Tilt sensor act like a switch on or off  1 or 0.

This shows also how analog signals converted to digital signals.

 

Materials:

4 – 220R RESISTORS

3 – LEDs red, blue and yellow

1 – Tilt Sensor

1 – BUZZER ALARM

1 – Arduino Uno R3

 

SCHEMATIC DIAGRAM:

Tilt-Sensor-Earthquake-Measures-full Improvised Representation of Tilt Sensor

Θ CODE:

main.ino

/***
 * 
    Improvised Representation of Tilt Sensor.
    Tilt Sensor used to measure the number how matter tilted or moved.
    
    Support us: Life2Coding.com
 * 
 ***/

const int tiltSensorPin = A5;
const int ledPin = 13;
int tiltSensorPreviousValue = 0;
int tiltSensorCurrentValue = 0;
long lastTimeMoved = 0;
int shakeTime=50;
const int firstLEDPin = 11; //pin for one LED
const int secondLEDPin = 12; //pin for the other

void setup()
{
pinMode(7, OUTPUT);
pinMode (tiltSensorPin, INPUT);
digitalWrite (tiltSensorPin, HIGH);
pinMode (ledPin, OUTPUT);
pinMode (tiltSensorPin, INPUT); //the code will read this pin
digitalWrite (tiltSensorPin, HIGH); // and use a pull-up resistor
pinMode (firstLEDPin, OUTPUT); //the code will control this pin
pinMode (secondLEDPin, OUTPUT); //and this one
}

void loop()
{
tiltSensorCurrentValue=digitalRead(tiltSensorPin);
if (tiltSensorPreviousValue != tiltSensorCurrentValue){
lastTimeMoved = millis();
tiltSensorPreviousValue = tiltSensorCurrentValue;
}

if (millis() - lastTimeMoved < shakeTime){
digitalWrite(ledPin, HIGH);
}
else{
digitalWrite(ledPin, LOW);
}

if (digitalRead(tiltSensorPin)){ //check if the pin is high
digitalWrite(firstLEDPin, HIGH); //if it is high turn on firstLED
digitalWrite(secondLEDPin, LOW); //and turn off secondLED
}
else{ //if it isn't
digitalWrite(firstLEDPin, LOW); //do the opposite
digitalWrite(secondLEDPin, HIGH);
digitalWrite(7, HIGH); // turn LED on
delay(2);
digitalWrite(7, LOW); // turn LED off
delay(2);
}
}

The following video shows the demo of this post:

There are many kinds of Tilt Sensor. You have to choose what is best fitted for your project also they have different voltage rating; consult the manufacturers data shit first before doing any things ANOLOGY!

james-pic Improvised Representation of Tilt Sensor

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.