๐ŸŽ„โ›„โ„๏ธ๐ŸŽ It's beginning to look a lot like ADABOX-mas! The next ADABOX from Adafruit ships soon! Get yours now, or give as a gift! ๐ŸŽ„โ›„โ„๏ธ๐ŸŽ
0

Issue when program run through battery
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Issue when program run through battery

by amitshishodia on Wed Jun 12, 2019 3:00 am

Dear all
i am facing some problem

1. I have use feather m0 adalogger board i have connected my board to USB as well as battery. i have measure the battery voltage at pin 9 (A7) it show half of the BAT pin of board. With the help of battery voltage i have blinking LED on pin 10 when board connected to USB program properly work(if and else condition both are work) and when i remove USB(only battery connect) program not work properly only else condition are work.

Code: Select all | TOGGLE FULL SIZE
const int ledPin = 12;
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600); 
  pinMode(ledPin, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int Batteryvoltage = analogRead(A7);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = (Batteryvoltage * (3.3 / 1023.0)*2);
  // print out the value you read:
  Serial.println(voltage);

  if (voltage<3.1)
  {
  digitalWrite(ledPin, HIGH);
  delay(100);
  digitalWrite(ledPin, LOW);
  delay(100);
  }
  else
  {
  digitalWrite(ledPin, HIGH);
  delay(1000);
  digitalWrite(ledPin, LOW);
  delay(1000);
    }
 }

amitshishodia
 
Posts: 61
Joined: Thu May 30, 2019 7:29 am

Re: Issue when program run through battery

by adafruit_support_bill on Wed Jun 12, 2019 5:49 am

Code: Select all | TOGGLE FULL SIZE
float voltage = (Batteryvoltage * (3.3 / 1023.0)*2);

Your calculation is assuming an analog reference voltage of 3.3v. If the battery voltage drops to 3.3v, the Feather's 3.3v voltage regulator can no longer produce a 3.3v regulated output. So the analog reference voltage will always be less than the battery voltage and your voltage calculation will not be accurate.

adafruit_support_bill
 
Posts: 75043
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.