Creating a AC Current contolled relay with an Uno for computer gear and more

Hey guys! I've been playing with an Arduino Uno for awhile and want to build a little project. I am working on building a AC Current controlled relay with an Arduino Uno for computer gear. The basic idea is to have a CT coil measure AC current flowing through my PC power cable and have the Arduino switch on a relay that will control an standard 120v AC outlet. This outlet will have my computer speakers and other peripherals plugged into it so they switch on and off automatically when the PC is powered up and down.

I did some research and found info on choosing a burden resistor to match a CT coil and build the voltage divider for the input, I have connected a UNO to a relay board (onboard transistors) so the hardware side I think I have a handle on, but am open to advice. It is the programing that I run into issues. I have Googled for several nights and can't find a sketch for what seems like a simple project, I searched for some time and feel it's time to ask some experts here! :slight_smile:

What I need in the sketch is for it to switch the relay on when AC current is at approximately 3 amps and off at 2 amps, I may have to play with this value later. Later I may also implement a second UNO with the same setup to monitor my pool pump, it draws a lot more current than a PC, about 11amps per phase (only need to read one phase). The gap between the on and off will provide some hysteresis so the relay isn't switching too often and bouncing.

I would also like to add a turn-on time delay to the relay so that once the AC Current threshold is met (3amps for example) the relay doesn't come on right a way but waits 10 seconds for example, again I can play with the value later I just am not familiar with how to add this to the code. There would be no turn-off delay for the relay.

I welcome any input and appreciate anyone's help in creating the sketch or pointing me in the right direction, Thank you. :slight_smile:

Where is the code you tried?

Do you already have a good current reading? Because on AC that's going to be the biggest challenge...

An uhm, why not simply use the USB or something to detect the PC is on?

Thanks for your response. I haven't found any code to even start with. I found some unrelated projects that use a current sensor but are very elaborate and have hundreds of lines of code, and are not well noted so I don't know what safe to delete out.

I don't have the hardware put together yet. I will start with a CR Magnetics CR8450-1000 CT coil.

The PC is just one idea, but I have several projects I would like to use this Arduino setup in, some have no switched output so current sensing covers all of them and I'm interested in doing a current sensing project. I also would like to have the current displayed in amps on an LCD screen. I have done the "Hello World" sketch in the past so I feel I can get the LCD going, I assume its just a matter of a "print command" in the right part of the sketch to have the LCD display the CT coil's value.

I suggest to get started by interfacing your current sensor with an Arduino, following these instructions, and just use analogRead() to see the signal, with output to the serial monitor or serial plotter at 115200 Baud.

Takes just a few lines of code.