Part Number: MSP430G2452
Tool/software: Code Composer Studio
Dear all;
I am making self watering project. In this project I am using soil moisture sensor and selenoid valf. Also I am trying to see moisture level at 16*2 LCD Display. But I can not see correct results. If sensor is out of soil it gives maximum 530, but it must give 1023. Also, when sensor is inside of the humid soil it gives appwoximately value between 200 and 300. I added my code below. What is the my wrong in code? Regards.
*Supply of sensor is 5V.
http://www.nskelectronics.in/index.php?route=product/product&product_id=475
#include <msp430.h>
#include "lcdLib.h"
//FUNCTION DEFINITIONS
void init_timer();
void adc_init();
//GLOBAL VARIABLES
unsigned int i;
void init_timer() {
CCTL0 = CCIE;
CCR0 = 1000000;
TACTL = TASSEL_2 + MC_2;
}
void adc_init(void)
{
//ADC10CTL0 & = ~ENC;
ADC10CTL0 = ADC10SHT_3 + ADC10ON + ADC10IFG + REF2_5V + REFON ;
ADC10CTL1 = INCH_0 + ADC10SSEL_3 + ADC10DIV_3;
ADC10AE0 = BIT0;
}
void main(void){
WDTCTL = WDTPW + WDTHOLD;// Stop Watchdog
BCSCTL1 = CALBC1_1MHZ; // calibration for basic clock system
DCOCTL = CALDCO_1MHZ; // calibration for digitally controlled oscillator
//Led for control of timer
P1DIR|=BIT3;
P1OUT|=BIT3;
//Watering Relay Pin
P1DIR|=BIT4;
P1OUT|=BIT4;
//Function Calls
init_timer();
adc_init();
lcdInit();// Initialize LCD
lcdSetText("Soil Moisture ", 0, 0);
ADC10CTL0 |= ADC10SC + ENC;
_BIS_SR(LPM0_bits + GIE);
while(1);
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
if(++i==100){ // Counter Control
P1OUT ^= BIT3;
ADC10CTL0 |= ADC10SC + ENC;
lcdSetText("Nem: ", 0, 1);
lcdSetInt(ADC10MEM,5,1);
if(ADC10MEM>400 && ADC10MEM<=750) {
lcdSetText("High ", 0, 0);
__delay_cycles(100);
lcdSetText("Motor working ", 0, 0);
P1OUT&=~BIT4;
}
else if(ADC10MEM<300) {
lcdSetText("Normal ",0,0);
P1OUT|=BIT4;
}
ADC10CTL0&=~ADC10IFG;
ADC10CTL0 |= ADC10SC + ENC;
i = 0;
}
}