Tilt Sensor With Arduino Nano [Code and Circuit Diagram]

by STEAM-DIY in Circuits > Arduino

78 Views, 2 Favorites, 0 Comments

Tilt Sensor With Arduino Nano [Code and Circuit Diagram]

fjlzqcwh.png

Finally, select the correct board and port.

Hello guys,

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

  1. Low cost.
  2. Low power consumption.
  3. Simple to use.

Okay, now let’s see where these sensors should be used.

  1. Identify the location of game system controllers.
  2. For mobile phones and tablets.
  3. To prevent the capsizing of boats, planes, and vehicles.
  4. To measure the height of trees and buildings.
  5. To warn when carrying material that is not suitable for tilt.

Let’s test how a tilt switch works using this. For this, we need the following accessories. These can be easily purchased from the links below.

Supplies

  1. Arduino nano board x 1
  2. Tilt sensor x 1
  3. LED bulb x 1
  4. 180 resistor x 1
  5. Breadboard x 1
  6. Jumper wires

Step 1

Firstly, identify these components.

Finally, select the correct board and port.

Finally, select the correct board and port.

Step 2

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

Finally, select the correct board and port.


Now let’s look at the code below.

  1. The complete program of this project –
/*Angle[Tilt] sensor with Arduino.
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 pin are defined.

#define sensor 2
#define LED 3

This code sets the sensor PIN as an input pin and the 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);
}


Finally, select the correct board and port. After, click the upload button.

Finally, select the correct board and port.

Finally, select the correct board and port.

OK, enjoy this tutorial. The full video guide is below. So, we hope to see you in the next tutorial or project. Have a good day.