MSP430: Temperature stabilizer

It has been a while since I played with the MSP430G2 evaluation board. Recently one of my friends wanted me to build a temperature stabilizer for one of his projects. The requirement was to stabilize a water container at 50 Centigrades. I decided to use the MSP430 as it has the basic components needed for it. In this post I will be talking about the code I used in the MSP430.

I used MSP430G2553 micro controller to do all the processing,
I used LM35 temperature sensor to measure the temperature.

The application was straight forward. I had to connect the LM35 IC through the ADC of the MSP430 and process the signal.


Following is the connection diagram.



Following is a state diagram of the problem.



According to the datasheet of the LM35 it works within 4V and 30V supply voltages. Since the MSP430 works at 3.3V I used a 9V battery to power up the LM35 IC. But the ground should be shared with the launchpad for this to work properly. It gives 10mV/C as the output in a linear scale.


The coding was done using the TIs code composer studio.

#include <MSP430.h>

* main.c

unsigned int value = 0;
unsigned int upperT = 180;
unsigned int lowerT = 160;

//The function to configure the ADC
void configureAdc(){
ADC10CTL1 = INCH_5 + ADC10DIV_3;
ADC10AE0 |= BIT5;

// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR;

__interrupt void ADC10_ISR (void)
__bic_SR_register_on_exit(CPUOFF); // Return to active mode

int main(void) {
short flag = 1; //relay on
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

BCSCTL1 = CALBC1_1MHZ; //Clock calibration
BCSCTL2 &= ~(DIVS_3);

P1DIR |= BIT0 + BIT6; //GPIO selection
P1SEL |= BIT5;

P1OUT &= ~(BIT0 + BIT6); //LEDx off


P1OUT |= BIT6; //LED1 ON

__delay_cycles(2000000); //delay 2sec
ADC10CTL0 |= ENC + ADC10SC; //Enable conversion
__bis_SR_register(CPUOFF + GIE); //Low power mode with enabled interrupts
value = ADC10MEM; //ADC conversion

if(flag == 1){ //When relay is on
if (value>=upperT){ //Wait until T = 53C
P1OUT &= ~(BIT0 + BIT6);
P1OUT |= BIT0;
flag = 0; //relay off //Turn off the relay
else if(flag==0){ //When relay is off
if (value<=lowerT){ //Wait until T = 47C
P1OUT &= ~(BIT0 + BIT6);
P1OUT |= BIT6;
flag = 1; //relay on //Turn on the relay



return 0;