moisture sensor with PIC16f887/877a coding

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

moisture sensor with PIC16f887/877a coding

Postby nina aem » Thu Sep 19, 2013 10:05 pm

i used the moisture sensor SN - M114 for my irrigation project..
then i have used the adc (potentiometer) programming.
the programming are working but it doesnt show the value of my sensor.
need help about the programming...
:cry: :cry: :cry:
Attachments
Untitled.png
nina aem
Freshie
 
Posts: 4
Joined: Thu Sep 19, 2013 9:37 pm

Re: moisture sensor with PIC16f887/877a coding

Postby Brian Griffin » Fri Sep 20, 2013 10:19 am

nina aem WROTE:i used the moisture sensor SN - M114 for my irrigation project..
then i have used the adc (potentiometer) programming.
the programming are working but it doesnt show the value of my sensor.
need help about the programming...
:cry: :cry: :cry:


Can you post your full code here? I can't see the whole working of the code here. :)
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

Re: moisture sensor with PIC16f887/877a coding

Postby nina aem » Sat Sep 21, 2013 11:09 pm

the programming done... but the another problem just show up..
i didnt know how to write a program to turn the water pum motor when the sensor detect the adc 0 - 300 and it will be delay for 5 second...
and turn off the motor when it reach the 300 - 950...
anybody can help me...
i try to use the relay but it not function...

here i include the full programming
CODE: SELECT_ALL_CODE
//==========================================================================
//   include
//==========================================================================
#include <htc.h>
#include "lcd.h"
#include "adc.h"
#include "system.h"

//   global variable
//===========================================================================
void delay_ms(unsigned int ui_value);

//   Configuration
//==========================================================================

__CONFIG(LVP_OFF&BOREN_OFF&FOSC_INTRC_CLKOUT&WDTE_OFF&PWRTE_ON);

//   main function
//==========================================================================
void main(void)
{
   PORTA = 0;                              // clear PORT
   PORTB = 0;                           
   PORTC = 0;
   PORTD = 0;                              
   
   TRISA = 0b11111111;                        // set PORTA as INPUT
   TRISB = 0b00000011;                      // set PORTB<7:2> AS OUTPUT , PORTB<1:0> as INPUT
   TRISC = 0b00000000;
   TRISD = 0b00000000;                        // set PORTD as output

   ANS2 = 0;                              // RA2 as DIGITAL I/O
   ANSELH = 0;                            // set PORTB as DIGITAL I/O for PIC16F887

   lcd_initialize();                        // Initialise LCD

   adc_initialize();                        // Initialise ADC

   unsigned char mode = 1;

while (1)                                 // Loop forever
   {
   switch(mode)
      {
   case 1:   lcd_clear();
         lcd_home();
         lcd_putstr("MOISTURE");
         delay_ms(1000);
         if (SW1 == 1)
            {
            lcd_clear();
            lcd_home();
            lcd_putstr("ADC :");                        // Put "ADC:" on LDC screen
            while (SW1 == 1)
               {
               unsigned int adc_value = 0;
               unsigned char i;
               CHS2 = 0;                              // select ADC channel AN0    
               CHS1 = 0;               
               CHS0 = 0;

               adc_on();                              // ON ADC
               for(i = 0 ; i < 10 ; i++)
                  {
                  adc_value = adc_value + ui_adc_read();      // take the value for 10 times
                  }
   
               adc_value = adc_value/10;            // Devide the final value by 10 to get the average result
               lcd_goto(0x05);
               lcd_bcd(4,adc_value);               // display on LCD with 4 digit number maximun.

               [b]/*if (adc_value == 0<=adc_value<=300)
                  {
                  Relay1 = 0;   
                  delay_ms(39);
                  }
               else
                   {
                  Relay1 = 1;   
                  }
               */

               }
   }
}

/*******************************************************************************
* PRIVATE FUNCTION: delay_ms
*
* PARAMETERS:
* ~ ui_value   - The period for the delay in miliseconds.
*
* RETURN:
* ~ void
*
* DESCRIPTIONS:
* Delay in miliseconds.
*
*******************************************************************************/
void delay_ms(unsigned int ui_value)
{
   while (ui_value-- > 0) {
      __delay_ms(1);      // macro from HI-TECH compiler which will generate 1ms delay base on value of _XTAL_FREQ in system.h
   }   
}
nina aem
Freshie
 
Posts: 4
Joined: Thu Sep 19, 2013 9:37 pm

Re: moisture sensor with PIC16f887/877a coding

Postby nina aem » Wed Sep 25, 2013 9:13 pm

please help...
the coding still not working :cry: :cry: :cry: :cry: :cry:
nina aem
Freshie
 
Posts: 4
Joined: Thu Sep 19, 2013 9:37 pm

Re: moisture sensor with PIC16f887/877a coding

Postby robosang » Thu Sep 26, 2013 8:03 am

Make it simple first. Use LED is sufficient to show the output. Makesure the program is working.
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: moisture sensor with PIC16f887/877a coding

Postby nina aem » Thu Sep 26, 2013 11:59 am

i hve used the led.. but it i cant get the output...
:cry: :cry:
nina aem
Freshie
 
Posts: 4
Joined: Thu Sep 19, 2013 9:37 pm


Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 19 guests