Saturday, May 18, 2013

Voltage Scaler (Voltage Divider)

Introduction

Sometimes you need to quickly and easily scale a voltage down to another voltage, within a circuit.

There's a two component circuit which can take in any voltage as its input, and have an exact percentage of that voltage as its output. If the input voltage doubles or triples, the output voltage doubles or triples as well.

Note: 1. This can only scale a voltage down, it can never scale up to voltage higher than its input. 2. The output will be much lower current than what is supplied to the input (Only low milli amps).

Applications

Some examples of situations where you'd need a voltage divider:
  1. Voltage from a 0-32 Volt sensor is too high for a 5 Volt micro-controller or a common 20 Volt meter to read without being damaged.
  2. A 12 Volt power supply is too high a voltage to power a 5 volt Micro-Controller, a sensor or an LED.

The circuit

Ingredients:
2 x Resistors (Any wattage, Resistance values determined by formula below).

Strange as it sounds, you really do only need two resistors. That's the easy part, the slightly difficult part is the calculation of their values (If you've used fractions, its easy as!).

Diagram:



OutputV = InputV/(R1Ohms+R2Ohms)*R2Ohms

Commonly Needed Combinations

For upto 32 volts input, scaled to 5 volts output: Scale 32 volts down to 15.625% (1/6.4).
 - R1=640 Ohms, R2=100Ohms. Are close enough.


For upto 5 volts input, scaled to 3.3 volts output: Scale 5 volts down to 66% (3/2).
 - R1=8.2K Ohms, R2=5.6K Ohms. Are close enough.



VBS Tricks (.vbs Script)

Introduction

These are some of my favourite .vbs scripts in existence. VisualBasic Scripts (.vbs files) can be written in notepad , just like batch files, but they have significant control over everything in a PC. As much control as a complete PC program - but without any fuss, and they can be run on PC's you have no administrator rights on. The only trade off i've found is that for every vbs script you run, there will be a copy of wscript.exe running in the 'Processes' tab of Task Manager. That's a pain if you're trying to be incognito.

What you'll need:
 - A PC with Windows XP/Vista/7 - that's it! this'll already have notepad on it - and that's all you'll need.

To run the script specified, do this:
  1. Copy the code given into a notepad file, then save the file as anything.vbs (Make sure you have '*.* All files' selected, otherwise the resulting file will be anything.vbs.txt).
  2. Double-Click the file you just made or,
  3. Create a batch file with the line 'start anything.vbs' in it, then run the batch file.

Terminate a running process/program

Change 'notepad.exe' in the line that says strProcessToKill = "notepad.exe"  to the name of the process you want to terminate. Tis will terminate all occurences of that .exe which are running at the time. Like a quick version of Task Manager - handy for software developers. To find the .exe program name of the process you want to terminate:
  1. Press Ctrl+Alt+Del, 
  2. Click Task Manager,
  3. In Task Manager, Click the tab called 'Processes'.
  4. Find the name of your process in the 'Description' column,
  5. Find its equivalent in the 'Image Name' column (This will end with '.exe').
'Terminate all processes involving the name <strProcessToKill>
Option Explicit
Dim strComputer,strProcessToKill, objWMIService, colProcess, objProcess
strComputer = "."
strProcessToKill = "notepad.exe"
Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!\\" _
   & strComputer _
   & "\root\cimv2")
Set colProcess =
objWMIService.ExecQuery _
   ("Select * from Win32_Process Where
Name = '" & strProcessToKill & "'")
For Each objProcess in
colProcess
   msgbox "... terminating " &
objProcess.Name
   objProcess.Terminate()
Next

PC Speaking text

Displays a message box on the screen, where the user has to type in some text to be spoken. Only works on Windows PC's (They all contain Sound API which is used for this).

    Dim msg, sapi
    msg=InputBox("Enter your text for conversion:","Text-To-Speech Converter")
    Set sapi=CreateObject("sapi.spvoice")
    sapi.Speak msg

Run a Batch (.bat) file, with no command prompt window

This runs the batch file called 'testfile.bat', from the same folder as where this code is run.

    CreateObject("Wscript.Shell").Run "testfile.bat", 0, False

Run a Batch (.bat) file, with no command prompt window - drag n drop

This runs a batchfile, when you drag the batch file onto the vbs file which contains this code.


    CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False