Script To Shut Down My Pc

sakis33

Greece

Hello forum..!

May i ask if it is possible to create a Script that can shut down my PC when the voltage goes less than 4,5V?

confused

By — Last update

ARC Pro

Upgrade to ARC Pro

Get access to the latest features and updates before they're released. You'll have everything that's needed to unleash your robot's potential!

#1  

The following script command will immediately shutdown the computer, forcing the shutdown even if there are running applications or other logged on users:


exec("shutdown.exe", "/p /f")

replace the /p with /s if you want 1 minute of warning, and if you want to abort the shutdown during the warning period, open a command prompt and type


shutdown /a

Keep in mind that any unsaved work will be lost, so use with caution. If you want to be sure not to lose any work, instead of /s or /p you can use /h and it will hibernate the computer instead of shutting it down.

Alan

PRO
Synthiam
#2  

Here's to expand on alan's command. Create an EZ-Script control that will run and check in a loop...


:loop

# if voltage is less than 4.5 and the ez-b is connected
IF (getVoltage() < 4.5 and isConnected(0))

  say("Shutting computer down in one minute")

  exec("shutdown.exe", "/s /f")

ENDIF

  # check every minute
sleep(60 * 1000)

goto(loop)

Have the EZ-Script control automatically start when the ez-b is connected in the SETTINGS menu of the connection control. Assuming your named your script "POWER CHECK"


ControlCommand("Power Check", ScriptStart)

#3  

Good Morning & thanks for the reply Alan and Dj Sures:)

i forgot to write that i use the EZ-B V3 Controller!

it is very helpful for my project.

i am going to test it !

PRO
Synthiam
#4  

the v3 controller will not work with GetVoltage().

You will have to connect the +5 on the ADC port and use GetADC() instead. Simply add a jumper on ADC0 between the +5 and Signal

#5  

ok Dj .. and code still the same.

thanks again.

PRO
Synthiam
#6  

No, the code would have to change from using getvoltage to adc. Because there is no voltage monitor on the v3. You can rig one of the adc ports to the +5 using a jumper to get the voltage.

#7  

@sakis33 do you want to monitor your "PC's" voltage or the robot's voltage on the EZB? I think the examples provide so far are how to monitor and react to if the EZB voltage is low.

#8  

Hello again Dj,

something like that code:

:loop

if (GetADC( adc0 ) <4.5 and IsConnected( 0 ) )

Say(&quot; shutting computer in one minute &quot; ) 

Exec( &quot;shutdown.exe&quot;, &quot;/s/f&quot; )

EndIf

Sleep(60*1000 )

Goto (loop)

#9  

Hi justin..,

as i write i want to create a Script that can shut down my PC when the voltage goes less than 4,5V?

i use V3 controller with a pc board. i want to know robot's voltage .

#10  

User-inserted image

A jumber on ADC 0 between +5 & signal, like the photo?

PRO
Synthiam
#11  

You got it!

But, the GetADC() is gonna return an 8 bit value between 0-255 on the v3. So a little bit of math is needed to get the voltage.

255 = 5v 127 = 2.5v 0 = 0v

That means 255 / 5 = 51

So 4.5 * 51 = 229.5

Your code will actually be GetAdc(ADC0) < 229

PRO
USA
#12  

I dont think it will work.

5v is the voltage reference, if the voltage drops to 4.5 the voltage reference will be 4.5 so the scale will be the same.

I m not familiar with ezb v3's voltage regulator does the board works with 4.5 ?

PRO
Canada
#13  

I'd recommend using a 2 resistor voltage divider to sense the voltage:

Voltage source ---VVV---ADC0---VVV-----GND

If the voltage source is 10V or lower a pair of 10kohm resistors would be fine to cut the voltage in half (5V max) and then tap the ADC0 sense line from the center connection of the resistors.

The EZ-Bv3 should work at input voltages 4.5V and a bit below but @ptp is right, as the voltage drops the analog voltage reference also gets lower the scale will stay the same so the ADC0 value won't change as you'd expect it should.

PRO
Canada
#14  

I guess we should clarify, are you using the same power supply for your ez-bv3 and your PC @sakis33?

#15  

Hello jeremie..,

yes i use the same power supply for ez-b v3 and my pc .

so you think that is not going to work ? i think that you have a point ...., i am going to try it again today and i give a reply:)

PRO
Synthiam
#16  

It'll work the way described as I have done with robots in the past. The latest version of the v3 uses a more efficient voltage regulator for the pic and Bluetooth that will operate as low as 3 volts.

#17  

Good morning from Sunshine Greece!

Ouf..! I try it and waiting ..

User-inserted image