I am currently using the PIC24FJ128GA010 and I am planning to use Input/Output port to connect my 4.2 V LiPo battery and to check if the voltage value doesn't go below 3.7 V.

I am thinking to connect it to any of my input/output pin but I am wondering two questions:

  1. Is it the correct pin?
  2. Should I do a specific montage with resistor?
  • \$\begingroup\$ When you ask if it is the correct pin do you mean a standard I/O pin? \$\endgroup\$ Sep 3, 2012 at 15:06
  • \$\begingroup\$ Yes, should I use Analog or Digital ? \$\endgroup\$
    – Mattew
    Sep 3, 2012 at 15:18
  • \$\begingroup\$ You should avoid digital. You have two options, use an ADC or use an Analog comparator. The last on one should be preferable if you only need to check if the voltage dropped bellow your threshold. \$\endgroup\$ Sep 3, 2012 at 15:22
  • \$\begingroup\$ @Mattew: Why 3.7V ? If you stop at 3.7V on the discharge curve, you'd be stopping after having used less than 50% of a LiPo's capacity (depending on your current draw). See discharge curves for a Sanyo Li-ion battery \$\endgroup\$
    – boardbite
    Sep 3, 2012 at 19:05
  • \$\begingroup\$ Possible duplicate of How to measure battery voltage from a microcontroller \$\endgroup\$
    – JYelton
    Jan 18, 2019 at 20:38

2 Answers 2


The PIC24F etc. is a 3.3 V device, so you can't apply the LiPo's voltage directly to an input pin.

You can use an ADC (Analog-to-Digital Converter) channel, or a built-in comparator. The ADC will give you the actual voltage at any time, the comparator only good/no good.

Like I said you can't apply the battery's voltage directly: it's too high. Use a resistor divider to scale the 4.2 V down to 3.3 V. A 10 kΩ resistor in series with a 33 kΩ will do fine. The divider will draw a constant current of 100 µA, which isn't much, but you don't want this 24/7. You can use a logic level gate P-MOSFET as a high-side switch to enable or disable the divider, like the Si2303.

  • \$\begingroup\$ I think the ADC is a good idea, I am looking for a really small solution (not enough space). If I use ADC, do I still need to use the resistor divider/P-MOSFET? \$\endgroup\$
    – Mattew
    Sep 3, 2012 at 15:42
  • \$\begingroup\$ @Mattew - The FET only takes a few mm\$^2\$, 0402 resistors even less. You need the divider; the inputs are 5 V tolerant, but according to the datasheet that's only for the digital inputs. A higher than 3.3 V on the analog inputs may damage them. You can drop the FET, but them the resistor divider will (slowly) drain the battery. \$\endgroup\$
    – stevenvh
    Sep 3, 2012 at 15:54

(Credit for much of this goes to @stevenvh's suggestion... For sake of more visual readers, I'm just providing a rough schematic of my circuit based on the suggestion!)

EDIT: Schematic further refined with a suggestion made by @Nick and @stevenvh:

enter image description here
More in this thread.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.