Switchable USB charger

What I want to do is a USB charger using a 7805, a type-A female USB port and powered by a cell phone charger. You see a lot of howtos - for example on Instructables.

I'll need it to charge a keychain spy cam (google image search). But additionally I want to control the charging cycle using an Attiny85. This Attiny85 will set the 5V output to the USB on or off - triggered periodically or by some sensors.
So the 5V output from the 7805 would power the Attiny85 and the USB port.

I don't know how to switch the 5V to the USB on and off. I have some 2N2222 lying around, but is this advisable? According to this datasheet it can handle more than 5V and up to 600mA. I guess the spy cam won't draw more than 500mA...? I also guess it is out of the question using an optocoupler, right?

So what do you think: Is it advisable to use a 2N2222?

What do you mean by "charging"?

Are you sure the devices you are attempting to "charge" don't already have a charging circuit? In which case, you are just controlling when power is turned on or off.

Hi James

yes, the camera gets charged by plugging its UBS cable to a port.

But the thing is that the camera goes into kind of "charging mode" when plugged into USB. This means that I can't take photos while the camera gets power over the USB cable.

So I want the camera plugged in USB all the time but I have to make sure it doesn't get powered when Arduino triggers a photo. This means I have to interrupt the 5V to USB by Arduino and I'm asking myself if I can do it with a 2N2222 transistor.

The 2N2222 can be used to switch your load (camera charging circuit) on and off.

this is my set up and it works like a charm :slight_smile:

The load should be switched from the "high" side/collector of the 2N2222, not the "low" side.

http://www.kpsec.freeuk.com/trancirc.htm

James, thanks for the link!

Ok, this is my design I finally came up with:

And a description of the full project on my blog.

For about $3 you can by a component from Digikey, the Micrel MIC2545 that essentially does what you need without very much complexity. Added
bonus: It's Fully USB compliant... so no fear of worst case scenario hurting your device.

http://teacher.en.rmutt.ac.th/ktw/Resources/PC%20Interface%20softwares%20&%20Documents/DataSheet/USB/UsbBookNote/Chapter13/Micrel/MIC2545ds.pdf