How to use Tilt Sensor SW-520D with ESP8266

tilt

Hi there! In this tutorial, you will learn how to use the Tilt SW-520D sensor, how it works, and understand how it can be implemented in future projects and the best way to implement it. What type of sensor is this? What can I do with this sensor? Why should I use it instead of others? These questions will be answered soon, just for you. Stay tuned!

Parts Required

Tilt SW-520D Sensor

Figure 1

A Tilt sensor is a sensor responsible for knowing if there is planar movement. They can be found in different types and shapes, but the basic function remains the same. We will proceed with the shape and aspect of the figure above. A sensor builds on-board with sensitivity adjustments capabilities. Usually the shape and color are similar, but not always equal.

So, back to the explanation! Their function is to detect the plane shift from horizontal to vertical and send a signal when it happens. Depending on the models used, the sensitivity involved to detect any shift can be very small. There are some modules that could sense very small plane shifts. Here, it will be a simple contact-type Tilt Sensor module.

Figure 2

Following the figure above, the working of this sensor seems intuitive. The configuration allows us to configure the component as a switch. So, by fixing it on a certain surface it can be used for the purpose of detecting vibration or for detecting tilt in a specified direction.

Normally, is built out of a little brass metal cylinder that looks like a capacitor, however, when you pick it up you feel and hear a metal ball inside. Sometimes can also be found in glass tubes. When held with the leads pointing downwards the metal ball will roll down and create a short circuit and act as a throw switch.   

It can be considered an accelerometer, however, it does not offer digital or analog signals that require processing.

Figure 3

Since this is an on-board sensor, 2 LEDs are present for power info and status switched on/off and a small potentiometer for sensitivity adjustment.

The general specs and pinout are listed here:

  • VCC: Input Voltage – 3.3V to 5V
  • GND: Ground
  • D0: Digital Output (TTL)
  • Input Current: 15mA
  • Operating Temperature: 0°C to 80°C

Due to noise, caused by mechanical bouncing, this should not be connected directly to microcontrollers, thus the potentiometer along with the IC on the left will compare the current from the sensor with the threshold selected with a screwdriver.

Figure 4

Under normal situations, the sensor pin will be open. So the voltage at the positive terminal of comparator IC will be zero then the output is going to be low and info LED will be OFF.

When the sensor pins are closed entire VCC appears at the positive terminal of the comparator and the output is going to be HIGH and the info LED will be ON.

So, with the previous explanation, the way that this sensor works is now clear. The output can be given to the controller or other systems. For example, security systems, toys, motors, robotic arms, among others.

If you want more technical info about this module it is good to check the SW-520D data sheet.

Circuit

Figure 5

Follow Figure 5 to obtain the wiring necessary for this setup. Since this is an easy-to-work sensor just connect the board DO to NodeMCU D7. The NodeMCU will power the Sensor board with 3.3V.

Code

The code below will read the state of the digital pin directly from pin D0 of the sensor, and print a small message on the serial monitor to have a notion if it is working. Just copy the code below to Arduino IDE and upload it to your ESP, Have fun!!!

 
int sensor_pin = 13; //NodeMCU On Board LED D7

//int board_led = 16; //NodeMCU On Board LED D0


void setup(){
  Serial.begin(9600);

  pinMode(sensor_pin, INPUT); //Set pin D7 as an input
  //pinMode(board_led, OUTPUT); //Set pin D0 as an input
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop(){

  int val_digital = digitalRead(sensor_pin);
  

   if(val_digital) {


     Serial.println(val_digital);
     Serial.print("\t");
     Serial.println("Earthquake");

     digitalWrite (LED_BUILTIN, HIGH);

   }

digitalWrite (LED_BUILTIN, LOW);
  
}

References

  • [1] https://components101.com/sensors/sw-520d-tilt-sensor-module
  • [2] https://components101.com/sites/default/files/component_datasheet/Tilt%20Sensor%20Datasheet.pdf
  • [3] https://i1.wp.com/www.arduiner.com/wp-content/uploads/2017/06/14438-Modulo-Sensore-Tilt-Vibrazione-Inclinazione-SW-520D.jpg?fit=680%2C663&ssl=1
  • [4] https://circuits-diy.com/tilt-sensor-module-sw-520d/

Leave a Reply

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

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
100% Free SEO Tools - Tool Kits PRO