Touch Switch for MSP430 Launchpad
by vigneshraja in Circuits > Microcontrollers
5371 Views, 8 Favorites, 0 Comments
Touch Switch for MSP430 Launchpad

Hello everyone
Here i share my project touch switch for msp430 launchpad. In this project i use the piezo electric sensor as a touch switch for msp430. This method touch switch can be used for any micro controller. and also in this project i create led array output. when the piezo electric sensor is touched then the led array turn ON. when again the sensor touched then the led array turn OFF. here i programmed msp430 to toggle output for each touch of touch sensor we used. Let us see the circuit diagram , operation and program for implement this concept yours.
Circuit Diagram and Working


As we are using piezo electric sensor as touch sensor. when we touch the piezo electric sensor it will produce very small amount of voltage.So we can't directly use this with microcontroller . but that piezo sensor voltage capable to provide base voltage of transistor 2n3906 for turn ON the transistor. Transistor turn on means let the transistor's collector voltage flow to emitter through base of transistor. if transistor off means then there is contact between collector and emitter. The base of the transistor act as bridge of conductance.
Here i programmed the P1.3 pin of msp430 as input and make it PULLUP. PULLUP in the sense make the pin HIGH. Then it is connected with collector of 2n3906 transistor. when piezo sensor touched then it provide voltage to base of the transistor. then transistor turn on . so voltage flow from collector to emitter and get grounded.So the P1.3 pin become LOW. so the program sense the low signal then do the action.
In program i declared the P1.0 as output to trigger the led ON and here i used TIP122 transistor switch the led array . because led array works on 9v supply so msp430 can't produce that voltage directly. for that we use transistor as switching device. when the P1.0 output become high then voltage flow through 100 ohm resistor to base of tip122 transistor. and the 9v + connected with led array + pin . and -ve pin of led array connected with collector of the transistor and ground to emitter. as before said when there is voltage in base then the Transistor turn ON . so current flow between led to transistor so the LED glows.here i programmed msp430 to toggle output for each touch of touch sensor we used. So led turn ON or OFF for each touch.
Programming Code
Programming code for code composer studio software users:
#include <msp430g2231.h>
#define Key (P1IN & 0X08)
unsigned int i;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= 0x01; // Set P1.0 to output direction
P1OUT &= ~(0x01);
while(1)
{
if(!Key)
{
while(!Key);
P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR
}
}
}
Coding for energia software user:
int led = P1_0;
int button = P1_3;
void setup()
{
pinMode(led,OUTPUT);
pinMode(button,INPUT);
digitalWrite(led,LOW);
}
void loop()
{
int data = digitalRead(button);
if (data == LOW){
if(digitalRead(led) == HIGH){
digitalWrite(led,LOW);
}
else if(digitalRead(led) == LOW){
digitalWrite(led,HIGH);
}
}
}
THANK YOU FOR WATCHING. I HOPE YOU ALL ENJOY THIS.