usb power out

Hi,

I started making a project with arduino, then port it to a breadboard with an atmega328, and it's been a lot of fun for someone new like me.

I was wondering how I can add a USB port into my project to be able to put a lamp on it for example.
If I want to power off and on the lamp on demand, what kind of hardware would you recommend?

Is this ok? https://www.amazon.es/TECNOIOT-0-9V-5V-Voltage-Converter-Supply/dp/B07HB3C13D/

Thank you for your help

What kind of lamp?

You can buy a USB to serial converter. They're usually built into a cable.

You can get a cheap 10A relay that will switch wall AC.

If you add bluetooth and your PC has BT as well, you won't need a cable.

Thank you for your help GoForSmoke.

I was looking at USB to serial converter, but it looks more like a power in? Sorry if I'm wrong, I'm not really familiar with the vocabulary yet. I'm trying to achieve the inverse I think? power out on a big USB port.

The idea was to put any usb lamp on it: https://www.google.com/search?q=usb+led+lamp&sxsrf=ACYBGNQqM1Hn8B6He40LfbAOWzWhq0dbxQ:1571134515164&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjutq6VhJ7lAhVB2-AKHXn5CjQQ_AUIEigB&biw=1361&bih=1066

the project is powered via a 9V battery for now (only thing I have) but I might switch this to micro usb.

The AVR chip can't host USB devices. It is like the lamp, not the PC the lamp plugs into.

The AVR can turn a relay on/off. You can power a real lamp with the relay.

The AVR can turn a transistor on/off to switch DC power to a big-bright led lamp. The AVR uses very small power to control the transistor (MOSFET is best efficient for this) which can take more power than the AVR chip much less one pin.

For a small led lamp you can connect leds and resistors to AVR pins and just turn the pins HIGH or LOW. Don't let any one pin source and/or sink more than 25-30mA continuous and try not to source/sink more than about 150mA total.

USB standard can power up to 500mA. The chip can't take that nor should it. It is good practice to minimize how much power goes through the chip.

That helps a lot, thank you! I guess I didn't understand what relay was all about

When using a relay do I still need to minimise/control the power? or is that only for the AVR pins?

Good (and still cheap) relay -modules- take very little power to control. A plain relay might (easily) need more than an Arduino pin can take to switch but the modules use external power to do the actual switching. Some have an opto-isolator, the AVR is electrically isolated from the relay as long as you don't ground them together (opposite of non-isolated wiring).

Do not turn a relay on and off a bunch of times quickly, it will get hot and may smoke on you.

Relays move physical parts quickly using magnet and coil. They have motor parts and make inductive surges but they are cheap and can make connections able to take a lot of power. Solid State relays (SSRs) are expensive compared, have no backsurge (the module deals with it) and can be switched at high frequency without getting hot.

You can get a relay shield. It's like a module only way more expensive.

I'll look into those Solid State Relay, I might need something that will switch it frequently (from a proximity sensor). Seeing the price right now, I'm hoping to find something cheaper

You want the lamp to switch on/off frequently?

The sensor, you sense with a pin. The sketch watches it 1000x faster than human sense and the sketch can watch time, how long a thing goes on --- the sketch decides when the lamp changes, not the sensor.

A thing as simple as a button does not act so simple when the pin is read many times a millisecond. When the button is pressed, just before it makes contact there will be sparks jumping between the contacts. Even at 3V this is true, for any voltage there is a gap however small that it will jump. At 5V as the button goes down the sparks jump for about 2ms, on release the sparks jump even longer.

With fast code it looks like the button is pressed and let go several times, to Arduino it looks like the switch "bounces" and the ways to handle that are called "debouncing". One way to debounce is to watch the pin change and then keep detecting and once the pin reads the same for some time (debounce interval) the sketch sets a status variable to the new state.
The status variable is what the rest of the sketch uses as button state, not the state of the pin it is wired to.

Arduino can detect events and times. It can relate those as a bigger thing, an abstraction that gets used to decide when to act.

Automate with Arduino, but save interrupts for special needs only. The tutorials below are not to my work but they are GOOD.

  1. Gammon Forum : Electronics : Microprocessors : How to do multiple things at once ... like cook bacon and eggs <-- tasking Arduino 1-2-3
  2. Gammon Forum : Electronics : Microprocessors : How to process incoming serial data without blocking <-- techniques howto
  3. Gammon Forum : Electronics : Microprocessors : Interrupts
    Your sketch can sense ongoing process events in time.
    Your sketch can make events to control it over time.