I use an inverter system as a backup power source for my desktop computer, however since I built it myself, it lacks a program which shuts it down before the battery reserve runs out.
I know how to detect a power cut using the Arduino, but I need some help for my next step. How can I create an interaction between the Arduino and my windows functions; such as shutting down?
Yes exactly, that is the answer I am looking for! I would like to try both alternatives, and require your guidance as I am somewhat under-experienced in this field.
If I were to use a relay, it would be powered by 5v, can this be taken from the Arduino or do I need a separate power supply? I have seen Arduino relays powered by a physical switch, but how will I close the relay with the Arduino, is it through a sketch?
For the second alternative, could you please elaborate on what a "small service" is and how it can monitor a USB port? My final question is if I can 'force shutdown' to avoid programs preventing it from shutting down.
I would greatly appreciate a detailed response for all my questions,
alexanderstroborg:
If I were to use a relay, it would be powered by 5v, can this be taken from the Arduino or do I need a separate power supply? I have seen Arduino relays powered by a physical switch, but how will I close the relay with the Arduino, is it through a sketch?
I normally power my relays from external power source. Some people says relays sometimes draw more power and can cause damage to GPIO pins.
In normal scenario a relay can be controlled by setting HIGH/LOW to INP pin, see one of my blog post
alexanderstroborg:
For the second alternative, could you please elaborate on what a "small service" is and how it can monitor a USB port?
Arduino is connected to the computer via a USB port.
In case of a power failure, the Arduino detetects it.
Arduino sends a serial message to the USB COM port.
A background service should listen to this COM port, if any time it receives a message like 'SHUTDOWN'. The service will invoke the shutdown command and shutdown the system.
Thank you for the replies, I only have a UNO R3 board at my disposal which does not support keyboard or mouse libraries like a Leonardo board would do. I know that there are ways to upgrade the firmware but that is not what I want to do.
However I do think that using the command prompt within windows 7 is the most effective way. How can I create an interaction between my Arduino and Windows? I've thought a lot about the second alternative that Sarouje suggested. Is there a way I can send a serial message from my Arduino straight into the command prompt? Instead of printing into my serial monitor, I would effectively print into the command prompt. If possible, the simpler alternative would revolve around executing a .bat file, but once again how can I open a file on my desktop through the Arduino or serial monitor?
I really appreciate your time, and it is helping me a lot!
pYro_65:
This can be done extremely simply in windows.
leonardo for example
Once that word fell my mind was like, uhm, simple...
Easiest way is a power button press. And you don't even need a relay. The power switch just pulls to GND (aka, one wire to the button is GND). All you need is a cheap optocoupler (PC817 for example) and a resistor. Done!
I would like to simply use a power button press, however it needs to be 'transferable' between computers, meaning that I cannot do physical modifications, rather just plug it in via USB.
The UPS service program created by spycatcher2k seems very promising and it recognizes my COM port, however the problem is that the hibernation feature had been disabled to save storage on my SSD. Also how can I send a capital 'Z' from the Arduino when the UNO does not support keyboard inputs; is there something I am missing?
Considering I do not know much about coding within windows 7, is there anyone that can lead me into a direction where I can code a program, similarly to spycatcher2k's UPS service to listen to a COM port, and then execute a shutdown or .bat file?
I am sorry for my repetition, your patience is appreciated,
However I have a problem with the program; basically it listens to a COM port until the Arduino sends a capital 'Z' through the serial monitor. I've created a sketch as spycatcher2k described, however when the UPS program 'listens' to the COM port, I get an error message when uploading my sketch saying "Port busy". What am I doing wrong?
It seems that I cannot use a COM port for two things simultaneously, how can I listen to a COM port while still being able to send serial data through it?