Skip to main content
Post Reopened by Juraj
Rollback to Revision 5
Source Link
Juraj
  • 18.3k
  • 4
  • 32
  • 50

After several tries, i was successful with reading stable battery voltage using internal voltage reference of 1.1v, now the issue i face is that i cannot read stable sensor voltage, could you please let me know how can i read my sensor voltage? or do i need additional voltage divider (my sensor goes directly to A0 and GND pin).

 void setup(){ Serial.begin(9600); } void loop() { //REFS1 AND REFS0 to 1 1 -> internal 1.1V refference ADMUX |= B11000000; //We read A1 (MUX0) for battery voltage ADMUX |= B00000001; //We read A0 for sensor voltage ADMUX |= B00000000; // for my sensor // Start AD conversion ADCSRA |= B11000000; // Detect end-of-conversion while (bit_is_set(ADCSRA,ADSC)); float val = ADCL | (ADCH << 8); val = val * 5.7; // Using 4.7k and 1k voltage divider Serial.println(val); } 

Something like the code below must workout but unfortunately it does not help!

 int sensorValue = analogRead(A0); voltage = ((sensorValue/ val) * 1023.); delay(1000); Serial.println("voltage: "); Serial.print(voltage); if (voltage<=215){ digitalWrite (led, HIGH); } else if (voltage>=215){ digitalWrite (led, LOW); } 

I cannot find the issue, it should work, i believe.

//////////////////////new edit/////////////////////////////////////

const long internalReference = 1078L; //measured AREF to be 1.078 ~ 1.078*1000= 1078V void setup() { // put your setup code here, to run once: Serial.begin (115200); } void loop() { analogReference (INTERNAL); ADMUX |= B00000000; ADCSRA |= B11000000; //ADEN and ADSC equal to 1 (Start conversion) while(bit_is_set(ADCSRA, ADSC)); //Wait for conversion to end long val = ADCL | (ADCH << 8); //Get analog read value float voltage = (val/internalReference)*1024; Serial.println (voltage); } 

enter image description here

After several tries, i was successful with reading stable battery voltage

After several tries, i was successful with reading stable battery voltage using internal voltage reference of 1.1v, now the issue i face is that i cannot read stable sensor voltage, could you please let me know how can i read my sensor voltage? or do i need additional voltage divider (my sensor goes directly to A0 and GND pin).

 void setup(){ Serial.begin(9600); } void loop() { //REFS1 AND REFS0 to 1 1 -> internal 1.1V refference ADMUX |= B11000000; //We read A1 (MUX0) for battery voltage ADMUX |= B00000001; //We read A0 for sensor voltage ADMUX |= B00000000; // for my sensor // Start AD conversion ADCSRA |= B11000000; // Detect end-of-conversion while (bit_is_set(ADCSRA,ADSC)); float val = ADCL | (ADCH << 8); val = val * 5.7; // Using 4.7k and 1k voltage divider Serial.println(val); } 

Something like the code below must workout but unfortunately it does not help!

 int sensorValue = analogRead(A0); voltage = ((sensorValue/ val) * 1023.); delay(1000); Serial.println("voltage: "); Serial.print(voltage); if (voltage<=215){ digitalWrite (led, HIGH); } else if (voltage>=215){ digitalWrite (led, LOW); } 

I cannot find the issue, it should work, i believe.

//////////////////////new edit/////////////////////////////////////

const long internalReference = 1078L; //measured AREF to be 1.078 ~ 1.078*1000= 1078V void setup() { // put your setup code here, to run once: Serial.begin (115200); } void loop() { analogReference (INTERNAL); ADMUX |= B00000000; ADCSRA |= B11000000; //ADEN and ADSC equal to 1 (Start conversion) while(bit_is_set(ADCSRA, ADSC)); //Wait for conversion to end long val = ADCL | (ADCH << 8); //Get analog read value float voltage = (val/internalReference)*1024; Serial.println (voltage); } 

enter image description here

Post Closed as "Needs details or clarity" by sempaiscuba, VE7JRO, jsotola
deleted 257 characters in body
Source Link

After several tries, i was successful with reading stable battery voltage using internal voltage reference of 1.1v, now the issue i face is that i cannot read stable sensor voltage, could you please let me know how can i read my sensor voltage? or do i need additional voltage divider (my sensor goes directly to A0 and GND pin).

After several tries, i was successful with reading stable battery voltage using internal voltage reference of 1.1v, now the issue i face is that i cannot read stable sensor voltage, could you please let me know how can i read my sensor voltage? or do i need additional voltage divider (my sensor goes directly to A0 and GND pin).

After several tries, i was successful with reading stable battery voltage

deleted 3126 characters in body
Source Link
 void setup(){ Serial.begin(9600); } void loop() { //REFS1 AND REFS0 to 1 1 -> internal 1.1V refference ADMUX |= B11000000; //We read A1 (MUX0) for battery voltage ADMUX |= B00000001; //We read A0 for sensor voltage ADMUX |= B00000000; // for my sensor // Start AD conversion ADCSRA |= B11000000; // Detect end-of-conversion while (bit_is_set(ADCSRA,ADSC)); float val = ADCL | (ADCH << 8); val = val * 5.7; // Using 4.7k and 1k voltage divider Serial.println(val); } 

Something like the code below must workout but unfortunately it does not help!

 int sensorValue = analogRead(A0); voltage = ((sensorValue/ val) * 1023.); delay(1000); Serial.println("voltage: "); Serial.print(voltage); if (voltage<=215){ digitalWrite (led, HIGH); } else if (voltage>=215){ digitalWrite (led, LOW); } 

I cannot find the issue, it should work, i believe.

//////////////////////new edit/////////////////////////////////////

const long internalReference = 1078L; //measured AREF to be 1.078 ~ 1.078*1000= 1078V void setup() { // put your setup code here, to run once: Serial.begin (115200); } void loop() { analogReference (INTERNAL); ADMUX |= B00000000; ADCSRA |= B11000000; //ADEN and ADSC equal to 1 (Start conversion) while(bit_is_set(ADCSRA, ADSC)); //Wait for conversion to end long val = ADCL | (ADCH << 8); //Get analog read value float voltage = (val/internalReference)*1024; Serial.println (voltage); } 

/////////////////////////////updated code///////////////////////

int led = 8; void setup(){ Serial.begin(9600); pinMode (led,OUTPUT); } void loop() { //REFS1 AND REFS0 to 1 1 -> internal 1.1V refference analogReference (INTERNAL); //ADMUX = B11000000; //We read A1 (MUX0) int value = analogRead (A1); //ADMUX = B00000001; //int sensor = analogRead(A1); // Start AD conversion ADCSRA |= B11000000; // Detect end-of-conversion while (bit_is_set(ADCSRA,ADSC)); float val = ADCL | (ADCH << 8); val = val * 5.7; //Multiply by the inverse of the divider value=val; Serial.println(val); float voltage = val * analogRead(A0) / 1023; voltage = ADCL | (ADCH << 8); Serial.print ("voltage at A0:"); Serial.println(voltage); Serial.print ("Solar panel voltage:"); Serial.println(voltage * 5.7); delay(1000); if (voltage>=174){ //1.1V digitalWrite (led,HIGH); } else{ digitalWrite(led,LOW); } } 

enter image description here

enter image description here

enter image description here

 void setup(){ Serial.begin(9600); } void loop() { //REFS1 AND REFS0 to 1 1 -> internal 1.1V refference ADMUX |= B11000000; //We read A1 (MUX0) for battery voltage ADMUX |= B00000001; //We read A0 for sensor voltage ADMUX |= B00000000; // for my sensor // Start AD conversion ADCSRA |= B11000000; // Detect end-of-conversion while (bit_is_set(ADCSRA,ADSC)); float val = ADCL | (ADCH << 8); val = val * 5.7; // Using 4.7k and 1k voltage divider Serial.println(val); } 

Something like the code below must workout but unfortunately it does not help!

 int sensorValue = analogRead(A0); voltage = ((sensorValue/ val) * 1023.); delay(1000); Serial.println("voltage: "); Serial.print(voltage); if (voltage<=215){ digitalWrite (led, HIGH); } else if (voltage>=215){ digitalWrite (led, LOW); } 

I cannot find the issue, it should work, i believe.

//////////////////////new edit/////////////////////////////////////

const long internalReference = 1078L; //measured AREF to be 1.078 ~ 1.078*1000= 1078V void setup() { // put your setup code here, to run once: Serial.begin (115200); } void loop() { analogReference (INTERNAL); ADMUX |= B00000000; ADCSRA |= B11000000; //ADEN and ADSC equal to 1 (Start conversion) while(bit_is_set(ADCSRA, ADSC)); //Wait for conversion to end long val = ADCL | (ADCH << 8); //Get analog read value float voltage = (val/internalReference)*1024; Serial.println (voltage); } 

/////////////////////////////updated code///////////////////////

int led = 8; void setup(){ Serial.begin(9600); pinMode (led,OUTPUT); } void loop() { //REFS1 AND REFS0 to 1 1 -> internal 1.1V refference analogReference (INTERNAL); //ADMUX = B11000000; //We read A1 (MUX0) int value = analogRead (A1); //ADMUX = B00000001; //int sensor = analogRead(A1); // Start AD conversion ADCSRA |= B11000000; // Detect end-of-conversion while (bit_is_set(ADCSRA,ADSC)); float val = ADCL | (ADCH << 8); val = val * 5.7; //Multiply by the inverse of the divider value=val; Serial.println(val); float voltage = val * analogRead(A0) / 1023; voltage = ADCL | (ADCH << 8); Serial.print ("voltage at A0:"); Serial.println(voltage); Serial.print ("Solar panel voltage:"); Serial.println(voltage * 5.7); delay(1000); if (voltage>=174){ //1.1V digitalWrite (led,HIGH); } else{ digitalWrite(led,LOW); } } 

enter image description here

enter image description here

enter image description here

added 1103 characters in body
Source Link
Loading
added 110 characters in body
Source Link
Loading
added 87 characters in body
Source Link
Loading
added 589 characters in body
Source Link
Loading
deleted 2 characters in body
Source Link
Loading
Source Link
Loading