Controlling Electronic Devices Made Easy

Introduction:

In this article I will walk you through making a device that controls electronic devices using your computer. This will give you a lot of power. For example, I am able to turn the lights on or off in my room from anywhere in the world via SSH. I know there are a few of these out there but mine is better. Mine doesn’t have complicated schematics with diodes resistors, 12Volt power supplies (where the hell are you suppose to get this from), and transistors. It’s simply a relay wall plug and wire. Below is the schematic. Click on the image to resize it.

schmeatic

What you will need:

Before you get started here is a run down of what you will need. Most of this stuff can be purchased at a local Wal-Mart or Target for a decent price.

  • A Relay. part# G3MC-201PL-DC5 (the most important component)
  • Light Socket
  • Wire
  • Solder Iron
  • Solder Wire
  • Tape
  • Scissors
  • Wall plug. Rip this off any old electrical device. and split the two wires. I used one from an blow dryer that doesn’t work.

Step 1:

The first thing you want to do is take the wall plug and solder one side to any of the relays load legs. Then connect the other wire of the wall plug to the socket. I put tape over the soldered leg to give it that extra hold and because when I solder the other leg it’s important not to get a short.

step1

Step 2:

Now solder a wire to the next relay leg. **Don’t use an extremely thin wire like from your headphones**. Use wire that can handle 120 V AC.

Step 3:

Connect that wire to the other end of the socket. What you should have now is a wall plug with one end attached to one of the relay legs and the other end attached to the socket. Also you should have a wire that can handle 120V AC connected to the other side of the socket and the other relay load leg. This should form a loop. What opens and closes the loop is the relay. When the input legs receive 5 volts it closes the load legs and current flows.

Step 4:

Now solder two wires to the input legs of the relay. These will receive 5 volts from the parallel port and create a short in the load legs closing the circuit and allowing current to flow and thus turning on the electronic component. The circuit is now complete. Connect one wire to the 6 pin the other to the 22 pin.

Step 5:

Make some kind of box to hold the circuit. I used the box that my relay came with from mouser.com. Below is what i put together.

Step : 6

Creating the application. Can’t get any easier than this.

LINUX CODE:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <asm/io.h>

#define base 0×378 /* printer port base address */

main(int argc, char **argv)

{

int value;

if (argc!=2)

fprintf(stderr, “Error: Wrong number of arguments. This program needs one argument which is number between 0 and 255.n”), exit(1);

if (sscanf(argv[1],”%i”,&value)!=1)

fprintf(stderr, “Error: Parameter is not a number.n”), exit(1);

if ((value<0) || (value>255))

fprintf(stderr, “Error: Invalid numeric value. The parameter number must be between 0 and 255n”), exit(1);

if (ioperm(base,1,1))

fprintf(stderr, “Error: Couldn’t get the port at %xn”, base), exit(1);

outb((unsigned char)value, base);

}

WINDOWS CODE:
MUST HAVE THIS DLL IN THE SAME FOLDER: inpout32.dll

#include <stdio.h>
#include <conio.h>
#include <windows.h>

/* Definitions in the build of inpout32.dll are: */

/* short _stdcall Inp32(short PortAddress); */

/* void _stdcall Out32(short PortAddress, short data); */
/* prototype (function typedef) for DLL function Inp32: */

typedef void (_stdcall *oupfuncPtr)(short portaddr, short datum);
#define PPORT_BASE 0×378

/* After successful initialization, these 2 variables

will contain function pointers.

*/
oupfuncPtr oup32fp;

/* Wrapper functions for the function pointers

- call these functions to perform I/O.

*/

void Out32 (short portaddr, short datum)

{

(oup32fp)(portaddr,datum);

}

int main(int argc, char **argv)

{

HINSTANCE hLib;
int value;
if (argc!=2)

{

fprintf(stderr, “Error: Wrong number of arguments. This program needs one argument which is number between 0 and 255.n”);

exit(1);

}
if (sscanf(argv[1],”%i”,&value)!=1)

{

fprintf(stderr, “Error: Parameter is not a number.n”);

exit(1);

}
if ((value<0) || (value>255))

{

fprintf(stderr, “Error: Invalid numeric value. The parameter number must be between 0 and 255n”);

exit(1);

}

/* Load the library */

hLib = LoadLibrary(“inpout32.dll”);
if (hLib == NULL) {

fprintf(stderr,”LoadLibrary Failed.n”);

return -1;

}
/* get the address of the function */

oup32fp = (oupfuncPtr) GetProcAddress(hLib, “Out32″);
if (oup32fp == NULL) {

fprintf(stderr,”GetProcAddress for Oup32 Failed.n”);

return -1;

}

/***** Write the data register */

Out32(PPORT_BASE,value);
printf(“Port write to 0x%X, datum=0x%2Xn” ,PPORT_BASE ,value);

/* finished – unload library and exit */

FreeLibrary(hLib);

return 0;

}

Conclusion :

If something is not clear or you need some help you can send me an email at foughtnlost AT gmail.com I want everyone to get this working because in my next article I will go over on how to turn off your lights using a cell phone and fetchmail.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>