NPEDUCATIONS, Electronic circuits development, electronics tutorials, microcontroller tutorials and projects, advanced microcontroller (ARM) based tutorials and projects, Embedded c development, Embedded c for ARM cortex M, Intel IoT based projects, IoT projects, CC3200 launch pad projects, MSP430 Launchpad tutorials and projects, Tiva C launch pad tutorials and projects, 8051 tutorials and projects, sensor interfacing with microcontroller tutorials, data communications and networking tutorials, peripheral interfacing with microcontroller, led message scrolling display, arduino based tutorials and projects, intel galileo based tutorials and project, ADC interfacing tutorials, LED Blinking, LCD interfacing, Embedded System tutorials and projects, B.tech projects, M.tech projects, online Embedded C training

Automatic Public Tap control system using PIR sensor and MSP430 - project

Introduction:
In this project a water tap is opened or closed automatically based on the presence of human nearer to the PIR sensor. Generally a PIR sensor is used to detect the presence of human near to it.  If a person come closer to the PIR sensor, then it activate the control circuit and open the water tap to allow water outside. If the person left the place, then control circuit automatically close the tap lid. In this context the mechanical opening and closing of the tap lid is done with the help of 12V DC motor.
In this project, PIR sensor is used to detect the human presence in front of it. This PIR sensor also produces a digital output (either logic high or low) corresponding to the human presence in front of it and this digital output is connected to the microcontroller. A firmware resides in the microcontroller will automatically drive the DC motor according to the PIR sensor output. MSP430G2553 is a 16-bit microcontroller is used in this application, because all the port pins can be configured as interrupt pins. Any of the port pin of MSP430 can be connected to the PIR output and it immediately detects it as an interrupt signal. Low power consumption also brings this device to operate with simple battery. The MSP430G2553 got a lot of in built features, but lower power consumption, low operating voltage; interrupt driven feature, and small size of the MCU makes me to use this controller.
In this project, L293D is interfaced with MSP430 to drive the motor and its direction.


Circuit Diagram:


Fig 1: Circuit diagram for the Automatic public tap control system using PIR sensor

Circuit Explanation:
In the above circuit, the PIR sensor output is connected to the P1.4 of the MSP430G2553. The reset circuit consists of a resistor of 47k and 1nf capacitor. A reset switch S1 is connected across the 1nf capacitor, which is used to reset the MSP430G2553 microcontroller. A zener diode 3.3V is connected between the Vcc and Gnd lines to obtain 3.3 Volts for the MSP430G2553. L293D IC is an H-bridge circuit used to control the motor direction clock wise and anti-clock wise. Connect the Vcc1, Vcc2 and Enable (1,2 EN) pins to the 5V Vcc supply. Enable pin (1,2 EN) is used to enable the internal motor drivers 1 and 2 as shown in the figure 2.

Fig2: Internal circuit diagram for L293D


The 1A and 2A input pins of L293D are connected to the P1.6 and P1.7 port pins of MSP430G2553 respectively. The 1Y and 2Y output pins of the L293D are connected to the two ends of the DC motor. If 1A pin of L293D is HIGH and 2A pin is LOW, then the motor will rotate in clock wise direction, because the current will source from 1A and sink into 2A. Similarly, if the 1A is Low and 2A is HIGH, then the motor will rotate in anti-clock wise direction.

Operation:
The PIR sensor will detects the existence of human surrounding to it and produces a digital output (logic high or logic low). If the PIR sensor finds a person then it will produce logic high, otherwise it will produce logic low output. When the MSP430G2553 microcontroller finds this PIR output as logic high, then an interrupt signal will generated internally and call the corresponding ISR. The ISR routine will generate a logic levels on the L293D, therefore the motor will rotate in clock wise direction. If the PIR sensor output is logic low, the ISR routine will generate a logic levels on the L293D, therefore the motor will rotate in anti-clock wise direction.
Till now I was used the word logic “high” and logic “low” for the MSP430 interrupt detection. But instead of that I used the edge transition in my program- (High to Low edge or Low to High edge). If the MSP430 P1.4 pin finds ‘Low to High’ transition then the motor will rotate in clock wise direction. If it is “High to Low’ transition then the motor will rotate in anti-clock wise direction.
Note: Here one question will arise in our mind that, HOW the MSP430G2553 Microcontroller ISR will differentiate ‘High to low’ or ‘Low to High’ edge transition on the P1.4 pin?
For this, I have connected an LED to P1.0 pin of MSP430G2553. If the interrupt is occurred on the P1.4 pin then the LED on the P1.0 will toggle its output. By using the status of the LED or status on the P1.0 pin will decide the clock wise or anti - clock wise direction of the motor. That means if the LED is ON then the program logic will drive the motor in clock wise direction. Similarly, if the LED is OFF then the program logic will drive the motor in anti-clock wise direction.
Instead of above logic you can use PxIFGx to set the edge transition. Recommended!
Program Code Explanation:
1. Initialization of the port pins of MSP430G2553:
P1.5 is connected to PIR sensor and the P1.6 and P1.7 are connected to the L293D motor driver. Pin P1.0 is connected to LED.
          P1DIR |= 0xC1;    
P1OUT = 0X00;
Interrupt setting for the P1.5
P1IE |= 0x20;                            // P1.5 interrupt enabled
P1IES |= 0x20;                          // P1.5 High/low edge
P1IFG &= ~0x20;                       // P1.5 IFG cleared
2. Defining a Interrupt service routine
            #pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
            // configure the L293D pins (P1.6 and P1.7) to the drive motor. If the LED is ON change the motor direction in clock wise else change in anti-clock wise.
            ……….
// P1.4 IFG cleared.
……….

}


Automatic Public Tap control system using PIR sensor and MSP430 - project
Program Code:
/******************************************************************************
 * Title: Automatic Public Tap control system using PIR sensors
 * Author: kiranvarma
 * My favourate blogs
 * http://www.npeducations.com
 * http://www.npprogrammers.com or http://www.npprogrammers.blogspot.com
 * http://www.npfoods.com or http://www.npfoods.blogspot.com
******************************************************************************/

#include  

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
  _delay_cycles(1000000);

  // Initialization of the port pins of MSP430G2553 - P1.5 is connected to PIR sensor and the P1.6 and P1.7 are connected to the L293D motor driver
  P1DIR |= 0xC1;                            // Set P1.0 for LED output, P1.6 and P1.7 L293D motor pins to output direction
  P1OUT = 0X00;
  P1IE |= 0x20;                             // P1.5 interrupt enabled
  P1IES |= 0x20;                            // P1.5 High/low edge
  P1IFG &= ~0x20;                           // P1.5 IFG cleared

  _BIS_SR(LPM4_bits + GIE);                 // Enter LPM4 w/interrupt
}

// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
  P1OUT ^= 0x01;                            // P1.0 = toggle

  // P1.6 and P1.7 are Enable pins of the L293D (EN1 = 1, EN2 = 0 -- motor rotate in Forward direction)
  if(P1OUT & 0x01 == 0x01)
  {
	  P1OUT |= 0x80;
	  _delay_cycles(1000000);

	  P1OUT &= ~0xC0;   // disable the enable pins to stop the motor
  }
	// P1.6 and P1.7 are Enable pins of the L293D (EN1 = 0, EN2 = 1 -- motor rotate in Forward direction)
  else
  {
	  P1OUT |= 0x40;
	  _delay_cycles(1000000);

	 P1OUT &= ~0xC0;   // disable the enable pins to stop the motor
  }

  _delay_cycles(10000);
  P1IFG &= ~0x20;                           // P1.4 IFG cleared
}


0 comments :

Post a Comment

Thanks for visiting NPEDUCATIONS. We will contact you soon

0 comments :

Post a Comment

Thanks for visiting NPEDUCATIONS. We will contact you soon

If you really like this tutorial, Don't forget to give the comment or please subscribe to the RSS feed by submitting your E-mail or like our Facebook page.
Related Posts Plugin for WordPress, Blogger...

 
Powered by Blogger