Solar Battery Charger With 5V USB Output
by NamNam_2008 in Circuits > Electronics
74 Views, 1 Favorites, 0 Comments
Solar Battery Charger With 5V USB Output
In this project, I designed and built a compact solar battery charger. The aim was to charge a single Li-ion cell using a small solar cell and to provide a stable 5V output for small electrical devices.
The device consists of several functional blocks. The solar cell supplies energy to an energy-harvesting charge controller. This charges the battery whilst simultaneously protecting it from over-discharge and over-voltage. A step-up converter then converts the battery voltage into a regulated 5V output voltage for a USB-A socket.
A microcontroller measures the battery voltage via a voltage divider. Depending on the battery voltage, several LEDs are switched on so that the current state of charge can be easily read. The whole assembly was built on a dedicated printed circuit board and housed in a 3D-printed casing. The solar cell is mounted on a movable bracket so that it can be folded out for operation and aligned with the light source.
This project combines electronics, PCB design, microcontroller programming and mechanical design in a small, practical device.
Supplies
For this project, the following materials and tools were used.
Electronic Components
- look on the Stueckliste
Mechanical Parts
- Custom PCB
- 3D printed enclosure
- 3D printed solar panel holder
- M3 screws
- M2 screws and nuts
- Threaded inserts
- Wires for the solar panel
Tools
- Soldering iron
- Solder
- Multimeter
- Lab power supply
- Oscilloscope, optional
- 3D printer
- Screwdriver
- Side cutter
- Programmer for the microcontroller, for example a SNAP debugger
- CAD software for the enclosure
- PCB design software for the circuit board
Downloads
Manufacture and Assemble the PCB
First, manufacture the PCB using the Gerber files.
Send the Gerber files to a PCB manufacturer or make the PCB yourself. Use the uploaded bill of materials to order and place all components correctly.
After you receive the PCB, solder the components onto the board.
A simple soldering order is:
- Solder the small resistors and capacitors first.
- Solder the ICs.
- Solder the inductors and larger capacitors.
- Solder the LEDs and the push button.
- Solder the USB-A socket.
- Solder the screw terminal for the solar panel.
- Solder the programming header.
- Solder the battery holder.
- Solder the jumper, test points and wire bridges.
Pay attention to the direction of the ICs, LEDs, USB socket and battery holder.
After soldering, check the PCB carefully for solder bridges or wrongly placed parts.
Before connecting a battery, measure with a multimeter to make sure there is no short circuit between battery plus and GND.
Upload the Program to the PCB
In this step, the AVR64DD14 microcontroller is configured in MCC and the firmware is uploaded to the PCB.
Before uploading the firmware, open the project in MPLAB X and start the MPLAB Code Configurator. Select the AVR64DD14 as the target device and configure the pins and peripherals as described below.
MCC Configuration
ADC Configuration
Enable ADC0.
The ADC is used to measure the battery voltage. The battery voltage is connected to the microcontroller through a voltage divider on pin PC1.
Configure the ADC with these settings:
- ADC module: ADC0
- Input mode: Single-Ended
- Resolution: 12-bit
- Result alignment: Right justified
- Positive input channel: AIN29
- ADC pin: PC1
The ADC channel AIN29 is used because the battery voltage divider is connected to pin PC1.
Voltage Reference Configuration
Open the VREF settings in MCC.
Set the ADC reference to the internal reference voltage:
- Enable force ADC voltage reference
- ADC voltage reference source: Internal 1.024V reference
This reference is used so the ADC can measure the divided battery voltage correctly.
Configuration Bit Setup
In the configuration settings, select the single supply option:
- Device used in a single supply configuration: Enabled
The circuit only uses one supply voltage from the battery, so this option must be enabled.
Pin Configuration
Open the pin grid / pin matrix in MCC and configure the pins like this:
PinFunction in MCCUsed for
PC1
ADC0 / AIN29 input
Battery voltage measurement
PD4
GPIO output
Red battery LED
PD5
GPIO output
Yellow battery LED 1
PD6
GPIO output
Yellow battery LED 2
PD7
GPIO output
Green battery LED
PF7
UPDI
Programming connection
The LED pins must be configured as digital outputs.
The ADC pin PC1 must be configured as an analog input.
The UPDI pin PF7 must stay reserved for programming and debugging.
Unused pins can stay unused or as normal GPIO pins. They are not needed for this project.
LED Output Pins
The four battery status LEDs are connected to Port D.
Use this order in the firmware:
- PD4 = red LED
- PD5 = first yellow LED
- PD6 = second yellow LED
- PD7 = green LED
These pins are switched by the firmware to show the battery level.
Generate the Code
After all settings are correct, click Generate in MCC.
Then check that the generated project contains the ADC and port initialization.
In the main program, the firmware should first call:
SYSTEM_Initialize();
After that, the program can repeatedly measure the battery voltage and update the LEDs.
The ADC measurement uses this channel:
ADC0_CHANNEL_AIN29
This channel belongs to pin PC1, where the battery voltage divider is connected.
Upload the Firmware
After the MCC configuration is finished, upload the firmware to the microcontroller on the PCB.
Connect the programmer to the 2x3 programming header on the PCB. Make sure the connector is plugged in the correct direction.
Then open the project firmware on the computer and upload it to the AVR64DD14 microcontroller.
After uploading, power the PCB carefully. The button and LEDs should now work.
The LEDs are used as the battery level indicator:
- Red LED only: battery low
- Red + one yellow LED: battery partly charged
- Red + two yellow LEDs: battery good
- Red + two yellow LEDs + green LED: battery almost full
Do a short test before putting the PCB into the case.
Downloads
3D Print the Case
Now print the mechanical parts.
Print these parts:
- Bottom part of the case
- Top part of the case
- Solar panel holder
After printing, check that the PCB fits into the bottom part of the case.
Also check that the holes for the LEDs, button and USB-A socket line up correctly.
The solar panel holder should move freely, but it should not be too loose. It needs to hold the solar panel at an angle when opened.
Clean the printed parts if needed and remove any support material.
Assemble and Test the Device
In this step, the solar panel, PCB and 3D printed case are assembled into the final device.
1. Attach the Solar Panel to the Solar Panel Plate
First, prepare the 3D printed solar panel plate.
Clean the surface of the plate so the double-sided tape can stick properly. Then place double-sided tape on the plate and remove the protective film.
Now place the solar panel in the center of the plate. Make sure the cable output points toward the middle of the case. Press the solar panel firmly onto the plate so it sticks well.
2. Prepare the Bottom Plate With Threaded Inserts
Place the bottom part of the case on the table.
Insert the four M3 brass threaded inserts into the prepared holes. Use a soldering iron to carefully press the inserts straight into the plastic until they are flush with the surface.
Let the plastic cool down. After that, test each insert with an M3 screw to make sure the threads work correctly.
Then hold the bottom plate under the case and attach it with four M3 screws.
3. Connect the Solar Panel to the PCB
Place the PCB next to the case.
Guide the solar panel wires into the case. Make sure the wires are not bent too sharply.
Connect the plus and minus wires of the solar panel to the screw terminal on the PCB. Check the polarity before tightening the screws.
After tightening the screw terminal, gently pull on the wires to check that they are fixed properly.
4. Place the PCB Into the Case
Place the case so that the USB opening and LED holes face forward.
Carefully insert the PCB from above.
Make sure that:
- The USB socket fits through the rectangular opening.
- The LEDs line up with the round holes.
- The button is placed under the square button opening.
- No cables are trapped under the PCB.
When everything is aligned, screw the PCB into the case with four M3 screws. The screws go into the threaded inserts in the bottom plate.
5. Assemble the Solar Panel Holder
The solar panel holder has two types of arms:
- Inner arms: these are connected directly to the solar panel plate.
- Outer arms: these are used to support the solar panel when it is opened.
Mount the Inner Arm Holders
Clip the left inner arm holder into the left cutout on the top of the case.
Then clip the right inner arm holder into the right cutout.
Make sure both holders sit firmly in place.
Mount the Inner Arms and the Solar Panel Plate
Push the right inner arm onto the pin of the right holder until it clicks into place.
Attach the solar panel plate to this right inner arm.
Then push the left inner arm onto the pin of the left holder and connect it to the solar panel plate as well.
Check that the solar panel plate can rotate between the left and right inner arms.
Mount the Outer Support Arms
Push the right outer arm onto the lower pin on the right side of the case.
Then push the left outer arm onto the lower pin on the left side of the case.
Fold both outer arms down and check that their holes line up with the holes in the case. These arms will support the solar panel when it is opened.
6. Final Test
Open and close the solar panel plate several times. Check that the solar panel wires are not stretched, pinched or trapped.
Fold the outer arms into the support position and place the solar panel plate on them. Check that the device stands stable.
Press the button and check if the LED indicator works.
Finally, plug a USB cable or USB plug into the USB socket to make sure the opening is aligned correctly.
The device is now fully assembled.