Arduino controlling the power supply of a USB light

Hello everyone,

I have a light powered by USB that I wish to control automatically. For example, if condition A is met then switch on the light, if condition B is met, then switch off the light.

The conditions A and B are defined by a Python script running a large algorithm that is probably not relevant here. From my initial reading and googling, it looks like controling my USB light with an Arduino is actually the best solution (rather than switching ON/OFF the power of the usb port from the motherboard of my laptop). Thus, what I aim to achieve is that when condition A is met, python sends a signal to the arduino, which turns on the usb light, and when condition B is met, python sends a signal to the arduino, which turns off the usb ligtht.

I purchased the Mega2560 R3 complete starter kit a few weeks ago, so I have some modules such as the USB power supply module, which may be relevant here.

I think there are two main steps in my project, and the second is probably the most relevant to this forum:
1/ how to send signal from python to the mega2560
2/ how to design my circuit and code so that the mega2560 can switch on and off my usb light

Being a complete beginner, I'd highly appreciate any guidance in trying to achieve my objective. I have performed the few beginner tutorials provived with my starter kit, as well as few tutorial from the internet, but I still struggle understanding the key modules and steps I would need to complete my objective.

Thank you very much in advance for your help.

Sending a signal from a Python program to Arduino is commonly done and you should be able to find plenty of examples. Basically, you open a serial port in Python and send whatever data suits you to one on the Arduino.

In your case, the Mega has plenty of hardware serial ports so you can use say Serial2 to leave the primary serial port free for debugging purposes.

For ease of coding, just send a single character: 'A' or 'B'.

As to USB, I don't know. Looking at the pinout, it looks like you just have to provide 5V and ground but I wonder if the standard has other restrictions - current limits for example - that you need to worry about.

Note though that you will need to get that power from somewhere other than the Arduino because your light will likely pull too much current for it to supply. Look at a relay module or better, a MOSFET.

I very much doubt it! What is a "USB power supply module"? :worried:

What is a "USB light"? :thinking:

Need a proper citation - Web link.

How will the Python script connect to the Arduino? Indeed, why do you think an Arduino of any sort is involved, let alone the massively overrated Mega 2560?

The obvious way to control one on/ off device from a PC is to use either a parallel port adapter or indeed, just a USB interface module.

You then just need a logic-level FET connected to this to control your light. :+1:

Thank you for your insights.
Here is what I refer to as a power supply module: Breadboard Power Supply Module.
I refer to as a USB light a light that is powered through USB such as: https://www.amazon.co.uk/gp/product/B09QFVT3NR/

How will the python script connect to the arduino? This is actually also my question, so sorry I can't answer yours. But from my recent reading, a solution may be this: Using Python to control an Arduino - Python for Undergraduate Engineers

I didn't know Mega2560 was massively overrated. I thought that as a beginner I need to start somewhere, and those bundle starter kit seemed to me a good entry in the microcontroller world. I'll take good care of this advice in the future when designing the final concept of the objective I've been describing here.

Maybe having power supply coming from a breadboard power supply module, and arduino controlling a relay module that could do the on/off switch between the powered breadboard and the usb light is a solution?

Yes, that's what I guessed . :grin: Basically a fairly useless module. :astonished: I have half a dozen in a (used, washed) hommus tub on the desk in front of me. The listing says "700 mA" but in respect of the regulator on the board, having no heatsink it would not be able to supply that current for more than a second or so before overheating and shutting down.


The "USB Light" claims 5 W rating, at 5 V that is one Amp. It is not terribly likely that a PC (let alone a laptop) would provide that to a USB port but a USB "Phone charger" likely would. So you would need a separate power supply and a logic-level FET to control it from the USB interface module I indicated. Or a relay module, but that is bulkier and adds a little current demand for the relay.

But no Arduino required. The Python program could control that module by simply opening and closing the USB serial port, not sending any data to it.

The "bundled" kits are sort of OK. You clearly can use it though the UNO and Mega 2560 are a very inconvenient form factor and really only suited if you have a specific project requiring a "shield" that mounts on them. For most simple experiments a Nano and a "solderless breadboard" (which presumably you did get as that is what the Breadboard Power Supply Module mounts on) are much more practical. :grin:

Hi,
Using the material I had with me and following your advices, I have designed this:

In brief: Arduino controls a relay, which control the power (on/off) given to the usb ring light.

Problem is that the light intensity is very low.
(see edit below, problem solved)
Note that when I plug the light directly in the usb port of the power supply module, the light is very strong (reaches max intensity), so I think the power supply module is able to bring enough power to the light. Could it be that the relay (and the cables?) is losing power on the way? How could I upgrade this design so that I have enough power in the light while being able to control it on/off with the arduino?

Thank you in advance for your help.

EDIT: I leave the initial message in case people face the same issue. Initially the power supply module was on a breadboard, and its connections to the relay and USB terminal adapter were made using new wires from the breaboard. After switching this to wires directly pinned to the power supply module (no breadboard, just like in the diagram of my message) I then reached the intensities I was looking for. Now it works, but still wonder whether this is a correct and safe design?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.