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]
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
- 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.
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
- Arduino nano board x 1
- Tilt sensor x 1
- LED bulb x 1
- 180 resistor x 1
- Breadboard x 1
- Jumper wires
Step 1
Firstly, identify these components.
Step 2
OK, now connect these components using the circuit diagram below.
Now let’s look at the code below.
- The complete program of this project –
First, the sensor connector pin and the LED bulb pin are defined.
This code sets the sensor PIN as an input pin and the LED PIN as an output pin.
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.
Finally, select the correct board and port. After, click the upload button.
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.