Sensing: Vibration & Tilt

 Hello everyone! Today I am going to discuss about 2 types of useful sensors: Vibration Sensor (picture on the left) and Tilt Sensor (picture on the right). Both these products are available in Cytron website. This tutorial will be separated to 2 parts.

Part 1: Tilt Sensor: Saving Students’ Lives

About Tilt Sensor Module SN-TILT-MOD

The tilt sensor module is equipped with a tilt sensor and a potentiometer. You may attach it to any object and it will determine whether the object is tilted or not. It is simple as it returns a digital output. It uses SW-460D or SW-520D tilt sensor. This tilt sensor is a ball rolling type, NOT the Mercury type.

It comes with a M3 mounting hole for ease of attaching it to any object. A power LED and a status LED are attached to the module for visual indicator.

This module will output logic LOW when the sensor is tilted below the threshold angle; logic HIGH when it is tilted above the threshold angle. The threshold angle ranges from 45 degree to 130 degree. Aside from threshold angle, angular velocity also affect the tilt module. It can also be used as a vibration sensor, too!

This module can be interfaced with any microcontroller with digital input such as PIC, SK40C, SK28A, SKds40A, Arduino series for tilt detection capability. Also, not to forget, interfacing the module with a Relay module forms a tilt switch 🙂

Features:

  • Operating voltage: 3.3 to 5VDC
  • Ball Rolling type of tilt sensor.
  • PIN: VCC = 5V, GND = 0V, DO = digital output from module
  • AO is not use in this module.

* If the DO is not working, you might need to turn the on board potentiometer to center.

Application

Introduction

As a student myself, I do not find lecture sessions to be the most entertaining thing to attend to. In fact, there are only 2 cases when lectures can be interesting: either the lecturer is super cute and handsome 😉 or you have deep interest in that subject. Sadly, most university students suffer from sleep deprivation because they tend to stay up late the night before either to finish up assignments and projects, play games or hang out.The worse thing is if they have a 8:00AM lecture the next day. 

and slowly….. he or she becomes a sleeping beauty. It’s all cozy and nice until your lecturer bust you out. That would be embarrassing, eh?

Introducing the Lecture Alarm! An alarm that will automatically turn on whenever your head feels heavy and starts tilting.

DSC00434

Set up

Components:

tutorial3_bb

Set up diagram

The diagram above shows the connection of the CT-UNO, Tilt sensor module and the buzzer.

7060-600x800

Pin connection of Tilt Sensor Module

  • The Vcc pin on the tilt sensor module is connected to the Vcc on the breadboard.
  • The GND pin on the tilt sensor module is connected to the GND on the breadboard
  • Do pin gives out digital signal and is connected to pin 3.
  • Ao is not connected.

BC547-45V100mA-NPN-Transistor-pinout

Pin connection of NPN transistor N2222

The diagram above shows the pins of the NPN transistor. Why do I use a transistor? To prevent high current sinking to occur. When dealing with buzzer, it is advisable not to connect it directly into your UNO or any microcontroller.

CT-UNO uses ATmega328p. Its maximum current per I/O pin is 40mA (Please note also: the maximum total supply is 200mA)

If you don’t know the specifications of the buzzer, you can manually measure it.

Step 1: Your buzzer should have ‘+’ terminal and ‘-‘ terminal marked. Connect the ‘+’ of the buzzer to the positive terminal of a 5V power supply

Step 2: Use a digital multimeter (DMM) to connect the ‘-‘ of the buzzer.

Step 3: The negative terminal of the DMM is connected to the negative terminal of the 5V power supply.

WP_20150317_11_05_16_RawMeasuring the current flowing through buzzer in 5V power supply (I = 2.93mA)

We can see that the current drawn by the buzzer is 2.93mA. Although it does not exceed the current limit of one arduino I/O pin can supply, it is still safer to put a transistor.

If the buzzer draw more current than the uC I/O can supply, you can try adding a resistor according to the current, but it probably wont work or work out of the specifications. A NPN transistor will help you.

Program

[code lang=”c” highlight=””]
#define Tilt 2 //Digital output from tilt sensor module is connected to D2
#define BUZZER 3 //LED at D3 pin

void setup() {
//setup the input or output pin
pinMode(BUZZER, OUTPUT);
pinMode(Tilt, INPUT);
digitalWrite(BUZZER, LOW); //off LED
}

void loop() {
if(digitalRead(Tilt)) //if the DO from Tilt sensor is low, no tilt detected.
//You might need to adjust the potentiometer to get reading
digitalWrite(BUZZER,HIGH);
else
digitalWrite(BUZZER,LOW);
}[/code]

LCD Keypad Shield

You can also use an LCD to display some message. I am using a LCD Keypad Shield.

Set up
tutorial3_bb with keypad shieldSet up diagram with LCD Keypad Shield

NOTE: LCD Keypad Shield is using pin 4 to pin 9. Do not use these pins for other purpose.

Program

[code lang=”c” highlight=””]
/*
The circuit:
* 16×2 character LCD to ARDUINO UNO
* LCD RS pin to digital pin 8
* LCD Enable pin to digital pin 9
* LCD D4 pin to digital pin 4
* LCD D5 pin to digital pin 5
* LCD D6 pin to digital pin 6
* LCD D7 pin to digital pin 7
* LCD R/W pin to ground

Tilt Sensor module to Arduino UNO
*VCC to 5V
*GND to GND
*Do to D2
*AO of tilt sensor is not used
*/

// include the library code:
#include
#include

#define Tilt 2 //Digital output from tilt sensor module is connected to D2
#define BUZZER 3 //LED at D3 pin

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

void setup() {
//setup the input or output pin
pinMode(BUZZER, OUTPUT);
pinMode(Tilt, INPUT);
digitalWrite(BUZZER, LOW); //off LED
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print(” Lecture”);
lcd.setCursor(0,1);
lcd.print(” Alarm”);
delay(1000); //delay for 1 second
lcd.clear();
}

void loop() {

if(digitalRead(Tilt)) //if the DO from Tilt sensor is low, no tilt detected. You might need to adjust the potentiometer to get reading
{
digitalWrite(BUZZER,HIGH);
lcd.setCursor(0, 0); //move LCD cursor
lcd.print(“SLEEPING”); //Display message
}
else
{
digitalWrite(BUZZER,LOW);
lcd.setCursor(0, 0); //move LCD cursor
lcd.print(“AWAKE “); //Display message
}
}[/code]

[youtube]https://www.youtube.com/watch?v=kiDQTBkPmpY[/youtube]

Part 2: Mini DIY Security Alarm

About Vibration Sensor Switch

This is high sensitivity vibration sensor. It act like a normal open switch. When it senses vibration, the terminals touches together and create a short circuit.

It is sealed and reliable, yet low cost vibration sensor. You can apply it to toys, household appliance, sport equipments, burglary alarm or security system.

Features:

  • Small and compact
  • Act like normally open switch
  • Highly sensitive to vibration/movement (contact)
  • Low power

Dimension: 4.5mm (diameter) x 14mm

Introduction

Security alarm is a system designed to detect intrusion – unauthorized entry – into a building or area. Do you have an alarm device attached on your home ceiling? Do you know the concept of that device?

1.0x0              310qkrU0ZML._SY300_

These devices use vibration sensor to detect intrusion. When there is any vibration due to the movement of a person, the alarm will start ringing. Now, we know the concept of this magical device, let’s build a simple one out of it.

I have tried googling about this product to review about it but I noticed that not many have talked about it in tutorials. Most of them only did a demo video without proper guidance or tutorial to talk about it. I hope this tutorial will give you a further approach on this product.:D

I will only show how this sensor work and respond along with the code because I am not an expert in doing the design of the outer body. If you had done a design, please share it with me! 😀

Set up

Components:

tutorial3b_bb

  • Digital pin 1 is connected to the buzzer.
  • Digital pin 2 is connected to the vibration sensor
  • Digital pin 3 is connected to the switch.
  • NPN2222 transistor is used to avoid current sinking from the buzzer to the ct-uno. You may refer to Part 1 for explanation
  • The 220 ohm resistor attached one end of the sensor and the CT-uno is used as a voltage divider to reduce the current flow.
  • How to connect the vibration sensor SN-VBR-18010P?
    • As you can see, one of the leg of the sensor is very thin and delicate. So, we must be extra gentle when dealing with it.
    • To make it easy, I soldered both leg with a wire. If you are not familiar with soldering. Let me give you a quick tutorial:
      • Step 1: Cut 2 fair length of wires and strip the end.
      • Step 2: Melt some solder lead onto each of the wire endWP_20150318_12_26_59_Rich
      • Step 3: Melt some solder lead onto your solder bit. Then, place your soldered wire onto the leg of the sensor and solder them together. Do it for the other leg. Remember to be extra careful and gentle when dealing with the thinner leg. You should get this.                                                                                               WP_20150318_12_35_11_Rich
      • Step 4: Now, because the thinner leg still looks very insecure, I am going to secure it with heat shrink tube. I cut 2 small size heat shrink tube and one large size heat shrink tube to protect the wires and secure the sensors’ legs.                                                           WP_20150318_12_37_24_RichWP_20150318_12_39_20_RichWP_20150318_12_40_06_Rich
      • Tada! Now your sensor is safe and sound! 😀WP_20150318_12_41_49_Rich

Program

[code lang=”c” highlight=””]
#define vib_sensor 2
#define alarm 1
#define switch_button 3
int state = 0; //variable for reading the vibration sensor state
void setup() {
// put your setup code here, to run once:
pinMode(vib_sensor,INPUT); //initialize the vibration sensor as an input
pinMode(alarm,OUTPUT); //initialize the led sensor as an output
pinMode(switch_button,INPUT);
}

void loop() {
// put your main code here, to run repeatedly:
//read the state of the vibration sensor value:
state = digitalRead(vib_sensor);

//check if there is vibration or not:
//if there is vibration, it will return a LOW state. If none, then it remain at HIGH state

if (state == HIGH){
//LED remain off
digitalWrite(alarm, LOW);
}
else{
while(digitalRead(switch_button)==HIGH){
//LED turns on and off repeatedly
digitalWrite(alarm,HIGH);
delay(100);
digitalWrite(alarm,LOW);
delay(100);
}
}
}
[/code]

LCD

You can also install an LCD to make it look more fun. I will be using an LCD Keypad Shield.

NOTE: LCD is using pin 4 to pin 9. Make sure that you do not use these pins for other purpose.

Set up

tutorial3b_bb with keyapd shiedlProgram

[code lang=”c” highlight=””]
//define library
#include
#include

//define pin name
#define vib_sensor 1
#define alarm 3
#define switch_button 2
int state = 0; //variable for reading the vibration sensor state

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

void setup() {
// put your setup code here, to run once:
pinMode(vib_sensor,INPUT); //initialize the vibration sensor as an input
pinMode(alarm,OUTPUT); //initialize the led sensor as an output
pinMode(switch_button,INPUT);
//set up the LCD’s number of columns and rows:
lcd.begin(16,2);
lcd.print(” CYTRON “);
lcd.setCursor(0,1);
lcd.print(” ALARM “);
delay(2000);
}

void loop() {
// put your main code here, to run repeatedly:
//read the state of the vibration sensor value:
state = digitalRead(vib_sensor);

//check if there is vibration or not:
//if there is vibration, it will return a LOW state. If none, then it remain at HIGH state
while(digitalRead(switch_button)==HIGH){
if(state == LOW){
//LED remain off
digitalWrite(alarm, LOW);
lcd.setCursor(0,0);
lcd.print(” SAFE & SOUND “);
lcd.setCursor(0,1);
lcd.print(” ^__^ “);
}
else{
//LED turns on and off repeatedly
lcd.setCursor(0,0);
lcd.print(” INTRUDER “);
lcd.setCursor(0,1);
lcd.print(” ALERT!!! “);
digitalWrite(alarm,HIGH);
lcd.noDisplay();
delay(100);
digitalWrite(alarm,LOW);
lcd.display();
delay(100);
}
}
if (digitalRead(switch_button)==LOW){
lcd.setCursor(0,0);
lcd.print(” ALARM IS “);
lcd.setCursor(0,1);
lcd.print(” DISARMED “);
}
}
[/code]

That is all from me. I hope you had fun playing with your sensors! If you have anything to ask please go to our forum to post your question. Feel free to comment down below! Feedbacks are always welcome. 😀
Source code:

1. Tilt Sensor Module  — Tilt_Module

2. Vibration Sensor — vibration

Buy

,

One thought on “Sensing: Vibration & Tilt

  1. Hi. My name is Dan Taylor from Sundance Wy. 19108 us hwy 14
    82729
    I doubt if you’ve ever had a request like this but here goes.
    I build a lot of Livestock (cattle) fence and I have a post hole digger on the front of a skid steer as well as a hydraulic Danuser hammer. I pound an 8″ post in a 6″ hole. It’s extremely important to drill the holes in the ground straight as when you hammer the post in the ground it follows the hole closely. I can tell fairly close if the auger is straight side to side but not at all forward to backward. It would be great to have some device on the auger drilling the holes as well as the post pounder to let me know in the cab of the skid steer if they are straight. The auger doesn’t get much shock but the pounder gets a Lot. If you can help me with this you can call or text to my cell phone.
    307 290 2659. Thanks

Leave a Reply

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