My goal is to run a electric motor at my computer startup (open vent) then the reverse instance at power off (close vent). Then next time when i start computer i want it to "open vent" and when i power down "close vent". How do i make my Arduino run these scripts without saving the last script? And how do i make a script that runs without opening the Arduino Sketch program window (just in the background)?
If powered from the PC the Arduino board will run every time the PC is powered up so opening the vent on startup is no problem. Doing something at PC shutdown requires an external power supply for the Arduino and a method of detecting that power is no longer available from the PC. What hardware have you got ?
I was thinking of connecting the arduino with a molex cable that i mod, 2 pin on the molex is a 12v 1 + and 1 - that i connect to a berrel 12 v dc to plug in to my arduino. The other 2 pins are 5 v 1 +, 1 - that i plug in to the L293D shield i got to run 5v motor. That way i wont get power through usb but from my psu instead. After this i was thinking of making a 3 pin usb cable (remove the 5v power cord) but keep the gnd, data + and data -. Its for an internal USB straight in to the motherboard.
If i turned off the Arduinos auto skript start at power up and made windows run a script at autostart, log in. Then a auto script at turn off that would be nice. But how could i make my Arduino scripts to run in the background without the Sketch window to appear?
If i turned off the Arduinos auto skript start at power up and made windows run a script at autostart, log in.
Why would you do that ?
how could i make my Arduino scripts to run in the background without the Sketch window to appear?
You don't need to have a PC window open in order for the Arduino board to run. It will run as soon as the board is powered up and does not even need to be connected to a PC
Yes i know that but the problem comes when im going to turn off the computer, i need the vent to go back to where it was at the startup and if i would run the secound script every time im turing off the computer, thats the script that are loaded to the memory at the arduino. When i power up the computer next time the motors will run the wrong way i need the first script to run at power up and secound at power off, then next time i power up i need the first script again. like a macro that uploads the first script after i ran the 2nd script, thanks for your patience sir.
Do a bit of research and find out which leads from the PC power supply are live when the computer is running and which are always so. With any luck you can use that to indicate when the machine has been shut down.
And you don't need two different "scripts" or programs in the Arduino. Just one program that does two different things depending on the state of some input.
As previously said if you want it to do something after the PC is switched off then the Arduino can't be powered from the PC. No power, no program running.
This seems like a grossly over engineered project!
You need:
A motor
A spring
A switch to detect the fully open position
A resistor
You arrange it so that when the motor is powered it opens the vent, when it is not powered the spring closes the vent. When the vent is fully open it operates the switch. The switch inserts some resistance into the supply so the motor has just enough current to stop the spring closing the vent, but not enough to sustain any damage.
You power the whole thing from your PC power supply.
You can run a batch file from Windows on startup and another on shutdown.
In those batch files you can execute an MQTT message to tell your Arduino hardware to do something.
slipstick:
As previously said if you want it to do something after the PC is switched off then the Arduino can't be powered from the PC. No power, no program running.
Windoze uses "soft power switching" - you press the power button and the OS shuts itself down and eventually removes power to most of the computer - but not all. There is still a "pilot" (standby) supply operating - the purple wire on the power supply to re-start the machine either from the power button, wake-on-LAN or a clock alarm. All you have to do is to find a convenient connection.