QT PY - reading voltage from A2

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
imgodot
 
Posts: 61
Joined: Fri Apr 15, 2022 9:36 am

QT PY - reading voltage from A2

Post by imgodot »

I have a QT PY and the lipoly breakout board and the 3.7V battery from Adafruit.

I want to display the power source and voltage.
My code below reads the A2 pin.

With the USB powering things, the "voltage" reads 3.62.
When the battery is powering it, the "voltage" reads 3.05.

The breakout board text stated anything over 4.7 V was USB.
Does that mean my USB is outputting less voltage or an I determining the voltage incorrectly?

Code: Select all

  int sensorValue = analogRead(A2);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);
  // print out the value you read:
  Serial.println(voltage);  

User avatar
neradoc
 
Posts: 542
Joined: Wed Apr 27, 2016 2:38 pm

Re: QT PY - reading voltage from A2

Post by neradoc »

Hmmmm according to the schematic, the pin is connected via a 100k/100k voltage divider, so divided by two.
And since the QT PY is a 3.3V device, that means that 3.3V = 1023.

So math math math and: V = analog_read * 2 * 3.3 / 1023 if I'm not mistaken.
Your 3.62 turns into 4.78. Not quite 5V but above the threshold.

That is, if my EE and math are not failing me (or me failing them).

User avatar
imgodot
 
Posts: 61
Joined: Fri Apr 15, 2022 9:36 am

Re: QT PY - reading voltage from A2

Post by imgodot »

Nera,

Thanks for the help.
It appears to work as expected.

-- Paul

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”