Can I configure an Arduino Uno as a power source to recharge a USB device while being powered by another external power device? I asked ChatGPT for input and it gave me this code:
#include <USBHost.h> // Include USB host library if needed for specific board/shield
void setup() {
// Initialize USB power if required (for boards with USB Host capability)
#ifdef USB_HOST_ENABLED
USBHost.begin(); // Only needed for USB Host shields or boards with host support
Serial.begin(9600);
Serial.println("USB power enabled.");
#endif
// Enable power to the USB port (depends on board; most Arduinos provide this automatically)
Serial.println("System ready. USB power is being supplied.");
}
void loop() {
// Continuously provide power to the USB port
// No specific commands are needed for simple powering.
// If needed, monitor the USB or other pins.
delay(1000);
}
Does this make any sense?
-
arduino.stackexchange.com/q/96277Matt– Matt2024年12月27日 06:33:11 +00:00Commented Dec 27, 2024 at 6:33
1 Answer 1
You are planning to plug a (say) 12V power source into the Arduino Uno power jack, and then plug something into the USB port, hoping that the Arduino's voltage regulator would provide 5V at the USB port?
I tested with my Uno, and under those circumstances it did indeed provide 5V at the USB port. However, it isn't designed to do that, and USB chargers generally negotiate with the plugged-in device via the data lines. Depending on the device, it may ignore the 5V and not charge.
Also you would be limited to a slow charge rate (say 500 mA) which may result in a slow charge.