title: getting wrong output in atmega16
body: <p>I am trying to build an automatic plant watering system using ATmega16.The logic is, the sensor will give an analog input at PA0 which will be compared with a preset value to turn on/off water pump.</p>
  
  <p>The following is the code fragment we used:</p>
  
  <pre><code>#include&lt;avr/io.h&gt;
  int adc(void);
  void pump(void);
  int adc_value;
  int main(void)
   {
    DDRC=0x01;                          //Defining PC0 as output
    ADCSRA=0x87;                    //Setting the mode of operation
    ADMUX=0x00;                     //Selection of channel and bit alignment
    while(1)
     {
       adc_value=adc();                //reading moisture level
       pump();                               //Pump activator routine
     }
     return 0;
   }
  
  int adc(void)
  {
     int lower_bits,higher_bits,result; 
     ADCSRA |= (1 &lt;&lt; ADSC)|(1 &lt;&lt; ADIF);  //Turn on conversion and clear flag
     while(ADCSRA &amp; (1 &lt;&lt; ADIF) == 0);  //wait for flag
     lower_bits=ADCL;
     higher_bits=ADCH;
     result=lower_bits|(higher_bits&lt;&lt;8);         //Accessing converted value by shifting
     return result;
   }
  
  void pump(void)
   {
    if(adc_value&gt;=700)                                //Pump ON trigger point
     {
       PORTC|=(1&lt;&lt;0);
     }
    else if(adc_value&lt;=600)                        //Pump Off trigger point
     {
       PORTC&amp;=~(1&lt;&lt;0);
     }
   }
  </code></pre>
  
  <p>Is there anything wrong in the code? Because after burning it, i am getting  low voltage**(0.15**) for wet soil and high voltage(4.84) for dry soil from the analog sensor input which is ok … but the problem is, I am <strong>always</strong> getting voltage like <strong>0.7</strong> (and sometimes like  0.15) at PC0  in both cases(I am using multimeter for measuring this). There in no change in the values for dry and wet soil at PC0.. in such case where is the actual problem? Is there anything wrong in the circuit design or in the code?</p>