Table of Contents
In this tutorial, you will learn how to interface motion sensor with MSP430G2 LaunchPad . There are many types of motion sensors available in market, But in this tutorial, we be using PIR motion sensor. We will see how to detect motion of any object around this PIR motion sensor and how to interface it with MSP430G2 LaunchPad to detect motion. This tutorial can also be used as a motion detector project. This is a fourth tutorial on series of tutorials on MSP430G2 LaunchPad. To understand this guide completely, you should know about general purpose input/ output pins of MSP430G2 LaunchPad . You should also know how to use energia IDE to program MSP430G2 LaunchPad . If you have no knowledge about how to use MSP430G2 LaunchPad and how to program it using Energia IDE, you should read following two articles first:
- Getting started with MSP430G2 LaunchPad
- How to use GPIO pins of MSP430G2 LaunchPad
- How to use RGB LED with MSP430G2 LaunchPad
Now lets start with a introduction of motion detector sensor or motion sensor. I have already mentioned about the sensor which we are using in this tutorial. In this tutorial, we will use PIR sensor to sense the motion (movement) of human being and turns ON an LED to indicate about the detection of motion. Movement of human will be detected by the PIR sensor. PIR Sensor provides a triggering pulse to MS430G2 launchPad . MS430G2 launch Pad generates output at Pin No. 14 to turn ON the LED.
Introduction to motion sensor 
Motion sensor interfacing with MSP430G2 LaunchPad
In this circuit we are using pin number 13 as digital input pin which is connected with output pin of PIR sensor. Because PIR sensor gives logic high whenever it detects motion around and there is no motion around it will give logic low output. Terminal of PIR sensor is connected with ground and terminal three is connected with 5 volt TPI pin. I told you earlier about TPI pin. PIR sensor works on 5 volt so if you connect less than 5 volt to power supply pin of PIR sensor, it will not work properly. LED is used for indication. LED is connected with pin number 14 which will be initialized as a digital output pin in program.
Code of MSP430G2 LaunchPad interfacing with motion sensor
Code for PIR sensor is same as code for Push button interfacing with MS430G2 LaunchPad
int ledpin = 14; int motion_sensor = 13; int sensor_state; void setup() { pinMode(ledpin, OUTPUT); pinMode(motion_sensor, INPUT); } void loop() { sensor_state = digitalRead(motion_sensor); if (sensor_state == HIGH) { digitalWrite(ledpin, HIGH); delay(1000); } else { digitalWrite(ledpin, LOW); } delay(1000);