How does work Tilt sensor – Tilt sensor with Arduino nano [Code and circuit diagram]

Hello guys, welcome back to my SriTu Hobby blog. Today we will learn about Tilt sensors. A tilt sensor can be identified as a device that detects the tilting of a flat plane along different axes. These sensors can easily detect orientation and inclination. Also, these sensors are called Roll ball sensors and Mercury sensors.

Ok, let’s see now how does work these sensors. The cylindrical part of these sensors contains a mercury or metal ball that is designed to move in both directions. Also, there are two conductive elements at one end of this cylindrical section. When the metal ball moves in that direction, the two ends become shorter. The current then flows through these two terminals. For this reason, it acts as a switch. We can also get a signal by connecting this to a circuit.

The main advantages of using these sensors.

  • Low cost.
  • Low power consumption.
  • Simple to use.
Okay, now let’s see where these sensors should be used.
  • Identify the location of game system controllers.
  • For mobile phones and tablets.
  • To prevent the capsizing of boats, planes, and vehicles.
  • To measure the height of trees and buildings.
  • To warn when carrying material that is not suitable for tilt.
You can see the Tilt sensor below.
Let’s test how a tilt switch works using this. For this, we need the following accessories. These can be easily purchased from the link above.
OK, let’s do this project step by step.

Step 1

First, identify these components.
 
Arduino nano board.
You can use any other Arduino board for this project.
Tilt sensor.
Described above.
LED bulb.
This component is used to view the sensor signal.
180 Resistor
This component is used to control the current.
Breadboard
Jumper wires

Step 2

OK, now connect these components using the circuit diagram below.

Step 3

Now let’s look at the code below.

The complete program of this project – Download

/*Angle[Tilt] sensor with Arduino.
created by the SriTu Tech team.
Read the code below and use it for any of your creations.
*/
#define sensor 2
#define LED 3

void setup() {
Serial.begin(9600);
pinMode(sensor , INPUT);
pinMode(LED , OUTPUT);
}

void loop() {
bool value = digitalRead(sensor);
Serial.println(value);
if (value == 0) {
digitalWrite(LED, HIGH);
} else {
digitalWrite(LED, LOW);
}
}
 
————————————————————————————————–
First, the sensor connector pin and the LED bulb connector pin are defined.
#define sensor 2
#define LED 3
 
This code sets the sensor PIN as an input pin and LED PIN as an output pin.
void setup() {
  Serial.begin(9600);
  pinMode(sensor , INPUT);
  pinMode(LED , OUTPUT);
}
The following code reads the sensor value and inserts it into the “value” variable. Then, it is tested using the if condition, the LED bulb turns on if the value variable is equal to 0, and the LED bulb turns off if the value variable is equal to 1.
void loop() {
  bool value = digitalRead(sensor);
  Serial.println(value);
  if (value == 0) {
    digitalWrite(LED, HIGH);
  } else {
    digitalWrite(LED, LOW);
  }
 

Step 4

Finally, select the correct board and port.

Step 5

After, upload this code. You can watch the full video guide below.
(adsbygoogle = window.adsbygoogle || []).push({});

How does work Tilt sensor – Tilt sensor with Arduino nano [Code and circuit diagram]

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart
Select your currency
USD United States (US) dollar
EUR Euro
Scroll to Top