user88944: i am using 3.7~4.2V lithium battery. I am using internal voltage reference to read constant battery voltage as we know that the battery voltage level depletes overtime. The problem is that my sensor (mini solar panel) reads max value under little light and does not go beyond that level no matter how much light falls onto it in the later stage. I need my logic to be <<< if read sensor voltage less than 3V detect night and do something whereas if voltage level is above 3V detect day and go to sleep. The entire project is ready i just need to figure out this.
void setup(){
 Serial.begin(9600);
 pinMode (A0, INPUT);
 pinMode (A1, INPUT);
}

void loop() {  
 printVolts();
  //REFS1 AND REFS0 to 1 1 -> internal 1.1V refference
  analogReference( INTERNAL);
  //We read A1 (MUX0)
  ADMUX = 0b00000000;   
  DIDR0 = 0;  
  // Start AD conversion
  ADCSRA |= (1<<ADSC);
  // Detect end-of-conversion
  while (bit_is_set(ADCSRA,ADSC));
  val = ADCL | (ADCH << 8);
  val = val * 5.7; //Multiply by the inverse of the divider
  Serial.println("val:     ");
  Serial.println(val); 
}    
void printVolts()
{
  int sensorValue = analogRead(A1);
  voltage =  (sensorValue/ val) * 1023.; 

delay(1000);
Serial.println(                    "voltage:  ");
Serial.print(voltage); 
 }

Currently i am using arduino board as a prototype, later on, i will be using attiny IC.
//////////////////////////////////edit1//////////////////////////////

////////////////////////Reads max under ceiling light

////////////////////////////////////Voltage after covering full panel with hand

//////////////////////////edit2///////////////////////////////////////////
#include <avr/io.h>
float val;
float voltage;
int led = 8;
void setup(){
 Serial.begin(9600);
 pinMode (A0, INPUT);
 pinMode (A1, INPUT);
 pinMode (led, OUTPUT);

}

void loop() {  
 printVolts();
  //REFS1 AND REFS0 to 1 1 -> internal 1.1V refference
    ADMUX = _BV(REFS0)  | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  //We read A1 (MUX0)
  ADMUX = 0b00000000;   
  // Start AD conversion
  ADCSRA |= (1<<ADSC);
  // Detect end-of-conversion
  while (bit_is_set(ADCSRA,ADSC));
 long result = ADCL | (ADCH << 8);
 val = result;
  val = val * 5.7; //Multiply by the inverse of the divider
  Serial.println("val:     ");
  Serial.println(val);
}
 void printVolts()
{
  int sensorValue = analogRead(A1);
  voltage =  ((sensorValue/ val) * 1023.); 
delay(1000);
Serial.println(                    "voltage:  ");
Serial.print(voltage); 
if (voltage<=199){
    digitalWrite (led, HIGH);
  }
  else if (voltage>=200){
    digitalWrite (led, LOW);
  }
}

This code should work.
//////////////////////////EDIT3////////////////////////////////////////////
ATtiny44A
#include <avr/io.h>
float val;
float voltage;
int led = 3;
#define solar 2 

void setup(){
 Serial.begin(9600);
 pinMode (A0, INPUT);
 pinMode (A1, INPUT);
 pinMode (led, OUTPUT);

}

void loop() {  
 printVolts();
  //REFS1 AND REFS0 to 1 1 -> internal 1.1V refference
     ADMUX = _BV(MUX5) | _BV(MUX0) ;
  //We read A1 (MUX0)
  ADMUX = 0b00000001;   //PA1   
  // Start AD conversion
  ADCSRA |= (1<<ADSC);
  // Detect end-of-conversion
  while (bit_is_set(ADCSRA,ADSC));
 val = ADCL | (ADCH << 8);
 //long result = ADCL | (ADCH << 8);
  //val = result;
  val = val * 5.7; //Multiply by the inverse of the divider
  Serial.println("val:     ");
  Serial.println(val);
}
 void printVolts()
{
  int sensorValue = analogRead(2); //PA2
  voltage =  (sensorValue/ val) * 1023.; 

delay(1000);
Serial.println(                    "voltage:  ");
Serial.print(voltage); 
if (voltage<=214){
    digitalWrite (led, HIGH);
  }
  else if (voltage>=214){
    digitalWrite (led, LOW);
  }
}

///////////////////////////EDIT////////////////////////////////////////
VALUE WITH analogReference(INTERNAL) command.
179.47val:
5831.10
voltage:
179.47val:
5831.10
voltage:
179.47val:
5831.10
voltage:
179.47val:
5831.10
voltage:
179.47val:
5831.10
voltage:
179.47val:
it maxes out under little light and cannot go beyond this level.
 ADMUX |=  (0<<REFS0) |(1<<REFS1);
 ADMUX = _BV(MUX5) | _BV(MUX0) ;

if I use these commands then serial monitor shows:
voltage:
132.47val:
3357.30
voltage:
infval:
3334.50
voltage:
132.23val:
3345.90
voltage:
133.00val:
3351.60
low reading
voltage:
8.24val:
3351.60
voltage:
7.94val:
3351.60
voltage:
7.63val:
3351.60
voltage:
9.46val:
3351.60
High reading
voltage:
183.75val:
3357.30
voltage:
178.86val:
3357.30
voltage:
181.00val:
3357.30
voltage:
181.61val:
3351.60

user7859: 
The problem is that my sensor (mini solar panel) reads max value under little light and does not go beyond that level no matter how much light falls onto it in the later stage.

Open voltage is not a good way to read the light level hitting a solar panel in this situation. Much better is to measure the current generated by the solar cell by adding a resistor across it here...

The value of the resistor can be found using...
V=IR
... where ...
V=1.1 volts
I=the maximum current the solar cell can generate in full light
If you do this, then you can read the A1 pin using the 1.1V ref and you will be able to measure the full range of light conditions using the solar cell with simple Arduino code like this..
analogReference(INTERNAL);  // a built-in reference, equal to 1.1 volts 
int v=analogRead(A1);       // Returns value 0-1023 representing light level

PS: Note if you measure the battery voltage with a divider as shown, you will be drawing current (about 0.8 milliamps when the battery reaches its minimum voltage) ALL THE TIME - even when the circuit is off. You do not want to do this with a lithium battery since under-voltaging it can potentially cause permanent damage to it. You really should heed my answer to your other question here.
PPS: It is usually best to ask your real question directly rather than asking a bunch of questions that are synthetic and reflect problems you think you have rather than the problems you actually do have. Your supplied code and drawings should match the thing you are asking and the thing you are actually working on (and each other!). It is often the case that the problem is not where you think it is, and so showing code and drawings that do not reflect what is really going on just wastes people's effort and does not ultimately help you solve your real problem. :)

88944: <p>i am using 3.7~4.2V lithium battery. I am using internal voltage reference to read constant battery voltage as we know that the battery voltage level depletes overtime. The problem is that my sensor (mini solar panel) reads max value under little light and does not go beyond that level no matter how much light falls onto it in the later stage. I need my logic to be &lt;&lt;&lt; if read sensor voltage less than 3V detect night and do something whereas if voltage level is above 3V detect day and go to sleep. The entire project is ready i just need to figure out this.</p>
<pre><code>void setup(){
 Serial.begin(9600);
 pinMode (A0, INPUT);
 pinMode (A1, INPUT);
}

void loop() {  
 printVolts();
  //REFS1 AND REFS0 to 1 1 -&gt; internal 1.1V refference
  analogReference( INTERNAL);
  //We read A1 (MUX0)
  ADMUX = 0b00000000;   
  DIDR0 = 0;  
  // Start AD conversion
  ADCSRA |= (1&lt;&lt;ADSC);
  // Detect end-of-conversion
  while (bit_is_set(ADCSRA,ADSC));
  val = ADCL | (ADCH &lt;&lt; 8);
  val = val * 5.7; //Multiply by the inverse of the divider
  Serial.println(&quot;val:     &quot;);
  Serial.println(val); 
}    
void printVolts()
{
  int sensorValue = analogRead(A1);
  voltage =  (sensorValue/ val) * 1023.; 

delay(1000);
Serial.println(                    &quot;voltage:  &quot;);
Serial.print(voltage); 
 }
</code></pre>
<p>Currently i am using arduino board as a prototype, later on, i will be using attiny IC.</p>
<p>//////////////////////////////////edit1//////////////////////////////</p>
<p><a href="https://i.stack.imgur.com/0AnIR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0AnIR.png" alt="Circuit" /></a></p>
<p>////////////////////////Reads max under ceiling light
<a href="https://i.stack.imgur.com/YQWmF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YQWmF.png" alt="Reads max under ceiling light" /></a></p>
<p>////////////////////////////////////Voltage after covering full panel with hand
<a href="https://i.stack.imgur.com/Ax5VH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ax5VH.png" alt="Voltage after covering full panel with hand" /></a></p>
<p>//////////////////////////edit2///////////////////////////////////////////</p>
<pre><code>#include &lt;avr/io.h&gt;
float val;
float voltage;
int led = 8;
void setup(){
 Serial.begin(9600);
 pinMode (A0, INPUT);
 pinMode (A1, INPUT);
 pinMode (led, OUTPUT);

}

void loop() {  
 printVolts();
  //REFS1 AND REFS0 to 1 1 -&gt; internal 1.1V refference
    ADMUX = _BV(REFS0)  | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  //We read A1 (MUX0)
  ADMUX = 0b00000000;   
  // Start AD conversion
  ADCSRA |= (1&lt;&lt;ADSC);
  // Detect end-of-conversion
  while (bit_is_set(ADCSRA,ADSC));
 long result = ADCL | (ADCH &lt;&lt; 8);
 val = result;
  val = val * 5.7; //Multiply by the inverse of the divider
  Serial.println(&quot;val:     &quot;);
  Serial.println(val);
}
 void printVolts()
{
  int sensorValue = analogRead(A1);
  voltage =  ((sensorValue/ val) * 1023.); 
delay(1000);
Serial.println(                    &quot;voltage:  &quot;);
Serial.print(voltage); 
if (voltage&lt;=199){
    digitalWrite (led, HIGH);
  }
  else if (voltage&gt;=200){
    digitalWrite (led, LOW);
  }
}
</code></pre>
<p>This code should work.</p>
<p>//////////////////////////EDIT3////////////////////////////////////////////</p>
<p>ATtiny44A</p>
<pre><code>#include &lt;avr/io.h&gt;
float val;
float voltage;
int led = 3;
#define solar 2 

void setup(){
 Serial.begin(9600);
 pinMode (A0, INPUT);
 pinMode (A1, INPUT);
 pinMode (led, OUTPUT);

}

void loop() {  
 printVolts();
  //REFS1 AND REFS0 to 1 1 -&gt; internal 1.1V refference
     ADMUX = _BV(MUX5) | _BV(MUX0) ;
  //We read A1 (MUX0)
  ADMUX = 0b00000001;   //PA1   
  // Start AD conversion
  ADCSRA |= (1&lt;&lt;ADSC);
  // Detect end-of-conversion
  while (bit_is_set(ADCSRA,ADSC));
 val = ADCL | (ADCH &lt;&lt; 8);
 //long result = ADCL | (ADCH &lt;&lt; 8);
  //val = result;
  val = val * 5.7; //Multiply by the inverse of the divider
  Serial.println(&quot;val:     &quot;);
  Serial.println(val);
}
 void printVolts()
{
  int sensorValue = analogRead(2); //PA2
  voltage =  (sensorValue/ val) * 1023.; 

delay(1000);
Serial.println(                    &quot;voltage:  &quot;);
Serial.print(voltage); 
if (voltage&lt;=214){
    digitalWrite (led, HIGH);
  }
  else if (voltage&gt;=214){
    digitalWrite (led, LOW);
  }
}
</code></pre>
<p>///////////////////////////EDIT////////////////////////////////////////
VALUE WITH analogReference(INTERNAL) command.</p>
<p>179.47val:<br />
5831.10
voltage:<br />
179.47val:<br />
5831.10
voltage:<br />
179.47val:<br />
5831.10
voltage:<br />
179.47val:<br />
5831.10
voltage:<br />
179.47val:<br />
5831.10
voltage:<br />
179.47val:</p>
<p>it maxes out under little light and cannot go beyond this level.</p>
<pre><code> ADMUX |=  (0&lt;&lt;REFS0) |(1&lt;&lt;REFS1);
 ADMUX = _BV(MUX5) | _BV(MUX0) ;
</code></pre>
<p>if I use these commands then serial monitor shows:</p>
<p>voltage:<br />
132.47val:<br />
3357.30
voltage:<br />
infval:<br />
3334.50
voltage:<br />
132.23val:<br />
3345.90
voltage:<br />
133.00val:<br />
3351.60</p>
<p>low reading</p>
<p>voltage:<br />
8.24val:<br />
3351.60
voltage:<br />
7.94val:<br />
3351.60
voltage:<br />
7.63val:<br />
3351.60
voltage:<br />
9.46val:<br />
3351.60</p>
<p>High reading</p>
<p>voltage:<br />
183.75val:<br />
3357.30
voltage:<br />
178.86val:<br />
3357.30
voltage:<br />
181.00val:<br />
3357.30
voltage:<br />
181.61val:<br />
3351.60</p>
 7859: <blockquote>
<p>The problem is that my sensor (mini solar panel) reads max value under little light and does not go beyond that level no matter how much light falls onto it in the later stage.</p>
</blockquote>
<p>Open voltage is not a good way to read the light level hitting a solar panel in this situation. Much better is to measure the current generated by the solar cell by adding a resistor across it here...</p>
<p><a href="https://i.stack.imgur.com/jAJuL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jAJuL.png" alt="enter image description here" /></a></p>
<p>The value of the resistor can be found using...</p>
<p><code>V=IR</code></p>
<p>... where ...</p>
<p><code>V</code>=1.1 volts</p>
<p><code>I</code>=the maximum current the solar cell can generate in full light</p>
<p>If you do this, then you can read the <code>A1</code> pin using the 1.1V ref and you will be able to measure the full range of light conditions using the solar cell with simple Arduino code like this..</p>
<pre><code>analogReference(INTERNAL);  // a built-in reference, equal to 1.1 volts 
int v=analogRead(A1);       // Returns value 0-1023 representing light level
</code></pre>
<p>PS: Note if you measure the battery voltage with a divider as shown, you will be drawing current (<a href="https://www.google.com/search?q=%283.7%20volts%29%2F%284.7%20kiloohms%29%20in%20milliamps" rel="nofollow noreferrer">about 0.8 milliamps when the battery reaches its minimum voltage</a>) ALL THE TIME - even when the circuit is off. You do not want to do this with a lithium battery since under-voltaging it <a href="https://www.mpoweruk.com/lithium_failures.htm#:%7E:text=under-voltage%20%2F%20over-discharge" rel="nofollow noreferrer">can potentially cause permanent damage</a> to it. You really should heed my answer to your other question <a href="https://arduino.stackexchange.com/a/92269/7859">here</a>.</p>
<p>PPS: It is usually best to ask your real question directly rather than asking a bunch of questions that are synthetic and reflect problems you <em>think</em> you have rather than the problems you actually do have. Your supplied code and drawings should match the thing you are asking and the thing you are actually working on (and each other!). It is often the case that the problem is not where you think it is, and so showing code and drawings that do not reflect what is really going on just wastes people's effort and does not ultimately help you solve your real problem. :)</p>
