What is the CN3065?
The CN3065 is a small linear charger for one 4.2 V lithium-ion or LiPo cell, designed to be fed by a solar panel (or 5 V from micro-USB). Most hobby boards carry a CN3065 chip, a charge-current resistor, two JST connectors for the panel and the battery, a micro-USB socket and a red/green status LED pair. It charges the cell and nothing else: there is no 5 V or 3.3 V output, and a basic module has no battery protection. To run an Arduino or ESP32 from it you add a protected cell and a boost converter such as the MT3608.
What sets it apart from a plain USB charger is how it behaves when the sun fades. If the panel cannot supply the set current, the chip's input monitor lowers the charge current instead of letting the panel voltage collapse, so charging continues at whatever the panel can give. This guide covers the specifications, every connection, how the charge cycle works, how to set the current, how to size a panel, how to power a project from it safely, and the faults you are most likely to meet. When you are ready to build, the Arduino Uno guide and the ESP32 guide add battery monitoring and a solar sensor node.
Specifications
| Parameter | Value |
|---|---|
| Input voltage | 4.4 to 6 V (absolute maximum 6.5 V) |
| Battery | One Li-ion/LiPo cell |
| Charge voltage | 4.2 V ±1 % |
| Charge current | 500 mA typical, up to 1 A |
| Charge current formula | ICH = 1800 / RISET (ohms, amps) |
| Precharge | 10 % of the set current, below about 3.0 V |
| Termination | At 10 % of the set current |
| Recharge threshold | Restarts below about 4.1 V |
| Thermal regulation | Reduces current at about 115 °C |
| Sleep current | Under 3 µA from the battery |
| Solar behaviour | Lowers the charge current when the input sags (not MPPT) |
| Status outputs | CHRG and DONE, open-drain, drive the LEDs |
| Temperature input | TEMP pin for an NTC thermistor (disabled by tying it low) |
| Typical module | About 40 × 20 mm, two JST PH2.0 connectors plus micro-USB |
Pinout
| Pin | Name | Description |
|---|---|---|
| 1 | SOLAR+ | Panel positive (JST PH2.0). Open-circuit voltage must stay at or below 6 V |
| 2 | SOLAR− | Panel negative |
| 3 | BAT+ | Battery positive (JST PH2.0). Connect the cell here, not a load |
| 4 | BAT− | Battery negative and common ground |
| 5 | USB | Micro-USB 5 V input, an alternative to the panel |
Wiring & code
Setting up CN3065 with ESP32
An ESP32 suits a solar node because it can sleep at microamps and wake only to send a reading. This guide shows how to power an ESP32 board from a CN3065-charged cell through a boost converter, read the battery and panel voltage on ADC1 pins, run a deep-sleep reporting node, and serve a status page. For the charger itself, specifications and panel sizing, read the CN3065 overview.
What you need
1ESP32 DevKit (WROOM-32)
- Notes
- Any ESP32 board with a 5 V input pin
1CN3065 solar charger module
- Notes
- Set to suit your cell
1Small solar panel
- Notes
- Open-circuit voltage under 6 V, about 2 W for a sensor node
1Protected single Li-ion/LiPo cell
- Notes
- A protected 18650 or flat LiPo pack
1MT3608 boost converter
- Notes
- Set to exactly 5.0 V with a meter first
4100 kΩ resistors
- Notes
- Two voltage dividers: battery on GPIO34, panel on GPIO35
2100 nF capacitors
- Notes
- One from each ADC pin to GND
Wiring
Cell → CN3065 BAT+/BAT−—
- Notes
- Protected cell, polarity checked
Panel → CN3065 SOLAR+/SOLAR−—
- Notes
- Voc under 6 V
Cell BAT+ → MT3608 IN+; BAT− → IN−—
- Notes
- Powers the converter from the cell
MT3608 OUT+ (5.0 V)5V / VIN
- Notes
- The board's 5 V input; do not also power over USB
MT3608 OUT− and BAT−GND
- Notes
- All grounds joined
BAT+ → 100 kΩ → GPIO34 → 100 kΩ → GNDGPIO34
- Notes
- ADC1 channel, input-only pin. Halves the cell voltage. Add 100 nF to GND
SOLAR+ → 100 kΩ → GPIO35 → 100 kΩ → GNDGPIO35
- Notes
- ADC1 channel. Halves the panel voltage. Add 100 nF to GND
Warning
Use ADC1 pins (GPIO32 to 39) for the battery and panel readings. ADC2 pins are shared with Wi-Fi and give wrong or failed readings once Wi-Fi is on. Set the MT3608 to 5.0 V with a meter before connecting, and never power the board from USB and the converter at once. The ESP32 pins are 3.3 V only: the dividers keep the pin below 3 V.
How the readings work
Each divider halves the voltage, so a full cell (4.2 V) reads 2.1 V and a 6 V panel reads 3 V at the pin. Set the pin to the 11 dB attenuation range so the ADC reaches about 3.1 V, and use analogReadMilliVolts(), which applies the ESP32's factory calibration. The ESP32 ADC is not perfectly linear, so check one reading against a multimeter and trim with an offset if needed. See ESP32 ADC pins: ADC1 vs ADC2.
Sketch 1 - Battery and panel monitor
const int BAT_PIN = 34;
const int PANEL_PIN = 35;
const float V_TABLE[] = {3.30, 3.50, 3.60, 3.70, 3.80, 3.90, 4.00, 4.10, 4.20};
const int P_TABLE[] = { 0, 10, 20, 35, 50, 65, 80, 90, 100};
const int N = 9;
int percentFromVolts(float v) {
if (v <= V_TABLE[0]) return 0;
if (v >= V_TABLE[N - 1]) return 100;
for (int i = 1; i < N; i++) {
if (v <= V_TABLE[i]) {
float f = (v - V_TABLE[i - 1]) / (V_TABLE[i] - V_TABLE[i - 1]);
return P_TABLE[i - 1] + f * (P_TABLE[i] - P_TABLE[i - 1]);
}
}
return 100;
}
float readDivided(int pin) {
uint32_t sum = 0;
for (int i = 0; i < 16; i++) { sum += analogReadMilliVolts(pin); delay(2); }
return (sum / 16.0) / 1000.0 * 2.0; // millivolts to volts, undo the 1:2 divider
}
void setup() {
Serial.begin(115200);
analogSetPinAttenuation(BAT_PIN, ADC_11db);
analogSetPinAttenuation(PANEL_PIN, ADC_11db);
}
void loop() {
float bat = readDivided(BAT_PIN);
float panel = readDivided(PANEL_PIN);
Serial.printf("Battery %.2f V (about %d %%) Panel %.2f V\n", bat, percentFromVolts(bat), panel);
delay(2000);
}Sketch 2 - Deep-sleep solar node
The node wakes every 10 minutes, reads the battery, reports, and goes back to sleep. If the cell is low it skips Wi-Fi (the biggest energy cost) and sleeps for an hour to give the panel time to recharge it.
wake → read battery → battery OK? yes → Wi-Fi + report → sleep 10 min
no → skip Wi-Fi → sleep 1 hourReplace the report step with your own publish call, for example MQTT from the ESP32.
#include <WiFi.h>
const char* WIFI_SSID = "YOUR_WIFI";
const char* WIFI_PASS = "YOUR_PASSWORD";
const int BAT_PIN = 34;
const uint64_t SLEEP_NORMAL_S = 600; // 10 minutes
const uint64_t SLEEP_LOW_S = 3600; // 1 hour when the cell is low
const float LOW_BATTERY_V = 3.50;
RTC_DATA_ATTR int bootCount = 0; // survives deep sleep
float readBatteryVolts() {
uint32_t sum = 0;
for (int i = 0; i < 16; i++) { sum += analogReadMilliVolts(BAT_PIN); delay(2); }
return (sum / 16.0) / 1000.0 * 2.0;
}
void goToSleep(uint64_t seconds) {
Serial.printf("Sleeping for %llu s\n", seconds);
Serial.flush();
esp_sleep_enable_timer_wakeup(seconds * 1000000ULL);
esp_deep_sleep_start();
}
void setup() {
Serial.begin(115200);
analogSetPinAttenuation(BAT_PIN, ADC_11db);
bootCount++;
float bat = readBatteryVolts();
Serial.printf("Boot %d, battery %.2f V\n", bootCount, bat);
if (bat < LOW_BATTERY_V) {
Serial.println("Battery low: skipping Wi-Fi");
goToSleep(SLEEP_LOW_S);
}
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASS);
unsigned long start = millis();
while (WiFi.status() != WL_CONNECTED && millis() - start < 10000) delay(100);
if (WiFi.status() == WL_CONNECTED) {
Serial.println(WiFi.localIP());
// Publish bat here (MQTT, HTTP or a database) before sleeping
} else {
Serial.println("Wi-Fi failed, will retry next wake");
}
WiFi.disconnect(true);
goToSleep(SLEEP_NORMAL_S);
}
void loop() {}Why the order matters. Wi-Fi can pull a couple of hundred milliamps in short bursts, so a weak cell sags and the board browns out. Reading the battery first and skipping Wi-Fi when it is low keeps the node alive until the sun returns. The MT3608 itself idles at roughly 100 to 200 µA, so for a node averaging well under 1 mA consider a low-quiescent-current 3.3 V regulator that works across the cell's 3.0 to 4.2 V range. The deep sleep guide has the energy-budget maths.
Sketch 3 - Status page
Serves the battery and panel readings as JSON, so a browser, script or dashboard can read them. Useful for checking the system on the bench; a node that sleeps cannot serve pages, so use it while developing.
#include <WiFi.h>
#include <WebServer.h>
const char* WIFI_SSID = "YOUR_WIFI";
const char* WIFI_PASS = "YOUR_PASSWORD";
const int BAT_PIN = 34;
const int PANEL_PIN = 35;
WebServer server(80);
float readDivided(int pin) {
uint32_t sum = 0;
for (int i = 0; i < 16; i++) { sum += analogReadMilliVolts(pin); delay(2); }
return (sum / 16.0) / 1000.0 * 2.0;
}
void handleRoot() {
char json[120];
snprintf(json, sizeof(json), "{\"battery_v\":%.2f,\"panel_v\":%.2f}",
readDivided(BAT_PIN), readDivided(PANEL_PIN));
server.send(200, "application/json", json);
}
void setup() {
Serial.begin(115200);
analogSetPinAttenuation(BAT_PIN, ADC_11db);
analogSetPinAttenuation(PANEL_PIN, ADC_11db);
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) delay(300);
Serial.println(WiFi.localIP());
server.on("/", handleRoot);
server.begin();
}
void loop() {
server.handleClient();
}ESP32-specific problems
Battery reading is wrong or stuck
- Likely cause
- A divider on an ADC2 pin while Wi-Fi is on
- Fix
- Use GPIO32 to 39 (ADC1)
Reading is slightly off
- Likely cause
- ESP32 ADC non-linearity
- Fix
- Compare with a multimeter and add an offset in code
Reading noisy
- Likely cause
- No capacitor on the divider
- Fix
- Add 100 nF from the ADC pin to GND and keep the averaging
Brownout resets when Wi-Fi starts
- Likely cause
- Cell sagging under the Wi-Fi burst
- Fix
- Use a stronger cell, add 470 µF on the 5 V rail, skip Wi-Fi when the battery is low
Node drains the cell overnight
- Likely cause
- MT3608 idle current or a board LED or regulator wasting power
- Fix
- Measure the sleep current; consider a lower-quiescent regulator
Node never wakes after a sunny day
- Likely cause
- Cell empty, protection tripped
- Fix
- Charge the cell, increase the panel size or the sleep time
Does not connect to Wi-Fi
- Likely cause
- 5 GHz network or weak signal
- Fix
- Use 2.4 GHz; see the Wi-Fi troubleshooting guide
ESP32 FAQ
Can I power the ESP32 straight from the cell? The ESP32 chip runs at 3.3 V, and most dev boards expect 5 V on the 5V/VIN pin, so you need a boost converter (as here) or a board with a Li-ion input and its own regulator.
Which pins are safe for the readings? GPIO32 to 39 are on ADC1 and keep working with Wi-Fi. GPIO34 to 39 are input-only, which suits a divider. See the ESP32 pinout guide.
How long will a solar node last? Divide the cell capacity by the average current. A node that draws 10 µA asleep and 150 mA for 5 seconds every 10 minutes averages about 1.3 mA, so a 2,000 mAh cell lasts roughly 64 days before any sun and before converter losses.
Why skip Wi-Fi when the battery is low? Wi-Fi is the largest energy cost, and skipping it lets the panel recover the cell instead of draining it further.
Does this work with an ESP32-S3 or C3? Yes, with their own ADC1 pins; check your board's pinout, because the pin numbers differ.
Next: the CN3065 overview covers panel sizing and the charge cycle. For the energy-budget maths read ESP32 deep sleep and battery life.








