Tuesday, November 8, 2011

Turn on the lights in your house with the computer

Turn the lights on your home computer by Enigmaelectronica

This is a project which is often mixed with the electronic programming, joining them with interfaces, which in this case, it is through an optocoupler.
The idea is based on a series of power control 8 devices [usually lights] in a house orany place requiring the control of electricity by remote.
In my previous post publish my compilation of Turbo Pascal, which is patched andready to use without risking the dreaded BSOD error in DOS:
DIVISION BY ZERO ERROR 20
Why choose Pascal?
1) First, because language is a fast and easy.
2) At the time of compiling libraries not needed.
3) For this project we will use a powerful computer
4) Can be used without installing executable first, without even having to use anyoperating system, at least MS-DOS have enough.
Interface Diagram
Here is the interface used to connect the parallel port of the computer:


It should be noted that we must make 8 of these circuits to control the program that I leave later.
It is easier this circuit but to the contrary, in my opinion, this circuit is easier to prove that confused with the set of transistors ...
For the connection:
Perform 8 of these circuits, then put the input (R1) to each output pin parallel port pin2 to pin 9.
The port should work with the address 378h Base 1 at address $ 0040 and segment0008
bone port LPT1.
If you want to know how it works, so this port, like others, seek my post aboutelectronic books or software and access to ports.
First Download the Pascal compiler, later I will give you the link

Now let's start with the issue, I know the interface:
Integrated Circuits Using the motorola company, which by its simplicity does not stopus useful things such as "zero-crossing" and a nearby insulation voltage greater than1 kV.
MOC used is the 3040 (or equivalent MOC3041) or alternatively also like the following diagram:
The TRIAC depends on what you want to control [for Solid State] interrupting their electricity.
If the load is then using a TIC226D REISTIVA not exceeding 400 volts the
If the load is inductive then using a TIC226M of 600 volt control
of the above must be careful not to overload the workload of the capacitor C1, putting it to a suitable value slightly higher than the burden of TRIAC.
The value of R1 depends on the input voltage, R1 = 1000
(Uin - 1.3) / ILED (mA)
where:
Uin is expressed in Volts
R1 is in Ohms
ILED is the current through the LED in the optocoupler expressed in milli Amps.
example:
Uin = 12
ILED = 30 mA in the MOC3040
R1 = 356 ohms total, standard sought is 330 ohms near
12 - 1.3 = 10.7
10.7 / 30 = 0,356 = 356 ohms
Now we know that the parallel port gives a TTL value of 5 volts applied themathematical formula for calculating the resistance of the MOC3040 use:
5 - 1.3 = 123 Ohms = approaching a commercial value gives R1 125 Ohm
Now we proceed to the programming load:
here's the source code: if they want to change it. If you wish, you can download, if you want to save all the work of compilation of the source code below.
Source Code (some libraries are not used, can eliminate)

use DOS, graph, Crt, SVGA256, Txt;
label 100;
var
graphdriver, graphmode: integer;
name: string [17];
Font: array [0 .. 767] of byte;
key Ch: Char;
p: word absolute $ 0040:0008;
a, b, c, d, e, f, g, h: integer;
{--------------------------}
starting procedure;
begin;
textbackground (blue);
ClrScr;
gotoxy (17:10);
textcolor (white);
writeln ('starting graphical environment, wait a few seconds');
gotoxy (10,30);
writeln ('Please enter your name below to display');
gotoxy (10.33);
writeln ('user during the program');
writeln;
gotoxy (44.33);
textcolor (white);
textbackground (blue);
gotoxy (45.33);
read (name);
gotoxy (44.33);
delay (300);
ClrScr;
end;

Title procedure;beginSetMode (1);Bar (horizontal width {0,0,320}, {200} vertical width, background color {blue});Print2 (10,5,62, 'Enigma Software Laboratories') is violet {9} 16 is blackPrint2 (10,10,62, ");Print2 (30,50,62, 'CONTROL PORT');Print2 (10,160,62, 'Press the [ENTER]');Print2 (10,185,62, '(c) 2005 Guatemala Gerson Enigma');Ch: = ReadKey; Ch: = # 0;{This is the main background of the program}Bar (0,0,320,200, blue background {color});Bar (background color 2,2,316,20,9 Bluelight {});bar (2,186,316,18,9) message {background esc and F11}bar (2,2,3,199,9);bar (316,2,3,199,9);Print2 (115,10,62, 'Port Control');Print2 (90,190,65, name);print2 (5,190,62, 'Operator:');bar (7,35,220,88, black);} {switch fundend;{--------------------------}iniciodatos procedure, {all bits to zero}begindelay (100);port [p]: = 0;a: = 0;b: = 0;c: = 0;d: = 0;e: = 0;f: = 0;g: = 0;h: = 0;delay (100);end;procedure status;beginprint2 (85,25,65, 'State');Print2 (5,126,65, '');print2 (5,125,65, '[F1] Terminal 1 [F7] Terminal 7');print2 (5,135,65, '[F2] Terminal 2 [F8] Terminal 8');print2 (5,145,65, '[F3] Terminal 3 [F9] Select. All');print2 (5,155,65, '[F4] Terminal 4 [F10] Help Menu');print2 (5,165,65, '[F5] Terminal 5');print2 (5,175,65, '[F6] Terminal 6 [ESC] Exit');end;procedure instructions;beginend;{--------------------------}state procedure;beginif port [p] = port [p] -1 Then bar (10,40,200,10, black); print2 (10,40,62, 'switch [1] off');if port [p] = port [p] +1 Then bar (10,40,200,10, black); print2 (10,40,62, 'switch [1] On');if port [p] <> -1 or +1 Then bar (10,40,200,10, black); print2 (10,40,62, 'switch [1] Data Error');if port [p] = port [p] -2 Then bar (10,50,200,10, black); print2 (10,50,62, 'switch [2] off');if port [p] = port [p] +2 Then bar (10,50,200,10, black); print2 (10,50,62, 'switch [2] On');if port [p] <> -2 or +2 Then bar (10,50,200,10, black); print2 (10,50,62, 'switch [2] Data Error');if port [p] = port [p] -4 Then bar (10,60,200,10, black); print2 (10,60,62, 'switch [3] off');if port [p] = port [p] +4 Then bar (10,60,200,10, black); print2 (10,60,62, 'switch [3] On');if port [p] <> -4 or +4 Then bar (10,60,200,10, black); print2 (10,60,62, 'switch [3] Data Error');if port [p] = port [p] Then -8 bar (10,70,200,10, black); print2 (10,70,62, 'switch [4] off');if port [p] = port [p] +8 Then bar (10,70,200,10, black); print2 (10,70,62, 'switch [4] On');if port [p] <> -8 or +8 Then bar (10,70,200,10, black); print2 (10,70,62, 'switch [4] Data Error');if port [p] = port [p] -16 Then bar (10,80,200,10, black); print2 (10,80,62, 'switch [5] off');if port [p] = port [p] +16 Then bar (10,80,200,10, black); print2 (10,80,62, 'switch [5] On');if port [p] <> -16 or +16 Then bar (10,80,200,10, black); print2 (10,80,62, 'switch [5] Data Error');if port [p] = port [p] -32 Then bar (10,90,200,10, black); print2 (10,90,62, 'switch [6] off');if port [p] = port [p] +32 Then bar (10,90,200,10, black); print2 (10,90,62, 'switch [6] On');if port [p] <> -32 or +32 Then bar (10,90,200,10, black); print2 (10,90,62, 'switch [6] Data Error');if port [p] = port [p] -64 Then bar (10,100,200,10, black); print2 (10,100,62, 'switch [7] off');if port [p] = port [p] +64 Then bar (10,100,200,10, black); print2 (10,100,62, 'switch [7] On');if port [p] <> -64 or +64 Then bar (10,100,200,10, black); print2 (10,100,62, 'switch [7] Data Error');if port [p] = port [p] -128 Then bar (10,110,200,10, black); print2 (10,110,62, 'switch [8] off');if port [p] = port [p] +128 Then bar (10,110,200,10, black); print2 (10,110,62, 'switch [8] On');if port [p] <> -128 or +128 Then bar (10,110,200,10, black); print2 (10,110,62, 'switch [8] Data Error');end;procedure keys;beginstate;repeatbeginch: = readkey;if (ch = # 0) then beginch: = readkey;case ch of# 59: begin {F1}a: = a +1;if frac (a / 2) = 0 Thenbeginbar (10,40,210,10, black);print2 (10,40,62, 'switch [1] off');port [p]: = port [p] -1endelsebeginbar (10,40,210,10, black);print2 (10,40,62, 'switch [1] On');port [p]: = port [p] +1end;end;# 60: begin {F2}b: = b +1;if frac (b / 2) = 0 Thenbeginbar (10,50,210,10, black);print2 (10,50,62, 'switch [2] off');port [p]: = port [p] -2endelsebeginbar (10,50,210,10, black);print2 (10,50,62, 'switch [2] On');port [p]: = port [p] +2end;end;# 61: begin {F3}c: = c +1;if frac (c / 2) = 0 Thenbeginbar (10,60,210,10, black);print2 (10,60,62, 'switch [3] off');port [p]: = port [p] -4endelsebeginbar (10,60,210,10, black);print2 (10,60,62, 'switch [3] On');port [p]: = port [p] +4end;end;# 62: begin {F4}d: = d +1;if frac (d / 2) = 0 Thenbeginbar (10,70,210,10, black);print2 (10,70,62, 'switch [4] off');port [p]: = port [p] -8endelsebeginbar (10,70,210,10, black);print2 (10,70,62, 'switch [4] On');port [p]: = port [p] +8end;end;# 63: begin {F5}e: = e +1;if frac (e / 2) = 0 Thenbeginbar (10,80,210,10, black);print2 (10,80,62, 'switch [5] off');port [p]: = port [p] -16endelsebeginbar (10,80,210,10, black);print2 (10,80,62, 'switch [5] On');port [p]: = port [p] +16end;end;# 64: begin {F6}f: = f +1;if frac (f / 2) = 0 Thenbeginbar (10,90,210,10, black);print2 (10,90,62, 'switch [6] off');port [p]: = port [p] -32endelsebeginbar (10,90,210,10, black);print2 (10,90,62, 'switch [6] On');port [p]: = port [p] +32end;end;# 65: begin {F7}g: = g +1;if frac (g / 2) = 0 Thenbeginbar (10,100,210,10, black);print2 (10,100,62, 'switch [7] off');port [p]: = port [p] -64endelsebeginbar (10,100,210,10, black);print2 (10,100,62, 'switch [7] On');port [p]: = port [p] +64end;end;# 66: begin {F8}h: = h +1;if frac (h / 2) = 0 Thenbeginbar (10,110,210,10, black);print2 (10,110,62, 'switch [8] off');port [p]: = port [p] -128endelsebeginbar (10,110,210,10, black);print2 (10,110,62, 'switch [8] On');port [p]: = port [p] +128end;end;# 70: {[F11]}beginbar (7,35,210,88, black);} {switch fundprint2 (10,40,62, 'Created by');print2 (10,60,62, 'Gerson Hernandez');print2 (10,90,62, '(c) 2005 enigma');end;# 68: {[F10]}begininstructions;title;keys;end;# 67: {[F9]}beginbar (7,35,210,88, black);} {switch fundprint2 (10,40,62, 'On All [F2]');print2 (10,50,62, 'Turn off all [F3] ");print2 (10,60,62, 'Back [Esc]');print2 (10,80,62, 'Status:');repeatbeginch: = readkey;case ch of# 60:begin {F2}bar (10,100,210,10, black);print2 (10,100,62, 'All Fired');port [p]: = 255;end;elsebeginbar (10,100,210,10, black);print2 (10,100,62, 'All Off');port [p]: = 0;end;end;end;Until ch = # 27;bar (7,35,210,88, black);} {switch fundkeys;end;end;end;end;Until ch in [# 27];end;out procedure;beginBar (horizontal width {0,0,320}, {200} vertical width, background color {Blue});print2 (19,50,62, 'Leaving the program');print2 (90,120,62, 'logout');print2 (10,186,62, 'Created by Gerson Hernandez (c) 2005');sound (2700);delay (100);nosound;Delay (700);end;{---- ---- Main Program}beginFiler ('0808art. Fnt ', 0,96,8, Font);InstallFont (1,8,8,32,96,8, Font);iniciodatos;Home;Title;status;keys;out;{Ch: = ReadKey; Ch: = # 0;}end.

endnotes
The optocoupler interface must be set to the following pin parallel port:
The program uses libraries in graphical mode if they do not want to wear or not toremove what is not interested
Pines of data:
[2] [3] [4] [5] [6] [7] [8] [9]
The pins from 18 to 25 are connected together to ground (0 volts = GND) and the remaining pins are not used.
They want things easy?
Then I leave the program and compiled:
Filename: PORT.rar
Filesize: 8 kB
Upload-Date: 31/05/2009
Download-Link:
http://rapidshare.com/files/239146411/PORT.rar
http://www.megaupload.com/?d=A5128QFU
Ahhh ¿? Do not like the DOS?
You want to do in Visula Basic?
Thanks to the valuable assistance of engineer Gerson Hernandez a very special friend, this time I have them the second and final part of the tutorial.
We will do this using Visual Basic 6.0 Service Pack 1
All this is possible thanks to a library closed source but free to use, it is the IO.DLL library that can be obtained from the website:http://www.geekhideout.com/iodll.shtmlAlthough I can download it from here, attached.Go on:The control is done from this library, you first need to have the interface connected and ready, in addition to the LPT parallel port in the right direction: 378Then put the Visual Basic form with the labels you see in the picture above.chek the option button and the button also need to be.good for lack of time I leave the source code, if gentlemen, the source code of how to control parallel port by me, Enigma:This part is the beginning of the source code of the form FORM:
Option ExplicitPublic Out_TTL As Byte 'BYTE containing the port to takePublic In_Port As Integer 'continental reading the address of LPTPublic Out_Port As Integer 'contains the direcc.para write to LPTThis button is very useful, we can close the program and let the states of the pins as they want, without having the program is always open.
Private Sub Command2_Click ()EndEnd SubIn section this code will LOAD FORM
Private Sub Form_Load () 'initial procedure'Set the COMBOLIST cmbLptSelectcmbLptSelect.AddItem "0 × 378"cmbLptSelect.AddItem "0 × 278"cmbLptSelect.AddItem "0x3BC"'Set as default LPT1cmbLptSelect.ListIndex = 0SetLPTAddress' stable base address of the LTPPort_Reset 'reset TTL outputsEnd SubBy putting this avoid going through the X Window Active
Private Sub Form_QueryUnload (Cancel As Integer, UnloadMode As Integer)Cancel = 1 'prevents out by' X 'End SubThis option closes the program and all that is executed on system memory
Private Sub Form_Unload (Cancel As Integer) 'if you exit the programPort_Reset 'then reset TTL outputsEndEnd SubOnly with the CMD called EXIT button to exit the system can
Private Sub cmdSalir_Click () 'if I press EXIT, resetPort_Reset 'TTL outputs and leave the programEndEnd SubThis reset and set to 0 all parallel port pins
Private Sub Port_Reset () 'reset procedure for TTL outputsPortOut Out_Port, 0End SubThis command sets the port type program and its direction is parallel
Private Sub cmbLptSelect_Click ()SetLPTAddress' call routine will determine the direction'Chosen basis of the new LPTEnd SubThis code shows the form of help, and some want to bring credit
Private Sub cmdHelpOnLpt_Click ()frmHelpOnLpt.ShowEnd SubThis section is to select one of the 4 possible directions parallel port
Private Sub SetLPTAddress () 'sets the direction for caesarean'To the selected portSelect Case cmbLptSelect.ListIndexCase Is = 0= & H378 Out_PortCase Is = 1= & H278 Out_PortCase Is = 2Out_Port = & H3BCEnd SelectIn_Port Out_Port + 1 =End SubHere are the codes of all CHECK BUTTON for each parallel port output
Private Sub Chkttl0_Click () 'TTL0 invest stateIf chkTTL0.Value = 1 ThenSetPortBit Out_Port, 0chkTTL0.Caption = "Output TTL0 = 1 - HIGH"ElseClrPortBit Out_Port, 0chkTTL0.Caption = "Output TTL0 = 0 - UNDER"End IfEnd Sub
Private Sub Chkttl1_Click () 'TTL1 invest stateIf chkTTL1.Value = 1 ThenSetPortBit Out_Port, 1chkTTL1.Caption = "Output TTL1 = 1 - HIGH"ElseClrPortBit Out_Port, 1chkTTL1.Caption = "Output TTL1 = 0 - UNDER"End IfEnd Sub
Private Sub Chkttl2_Click () 'TTL2 invest stateIf chkTTL2.Value = 1 ThenSetPortBit Out_Port, 2chkTTL2.Caption = "Output TTL2 = 1 - HIGH"ElseClrPortBit Out_Port, 2chkTTL2.Caption = "Output TTL2 = 0 - UNDER"End IfEnd Sub
Private Sub Chkttl3_Click () 'TTL3 invest stateIf chkTTL3.Value = 1 ThenSetPortBit Out_Port, 3chkTTL3.Caption = "Output TTL3 = 1 - HIGH"ElseClrPortBit Out_Port, 3chkTTL3.Caption = "Output TTL3 = 0 - UNDER"End IfEnd Sub
Private Sub Chkttl4_Click () 'TTL4 invest stateIf chkTTL4.Value = 1 ThenSetPortBit Out_Port, 4chkTTL4.Caption = "Output TTL4 = 1 - HIGH"ElseClrPortBit Out_Port, 4chkTTL4.Caption = "Output TTL4 = 0 - UNDER"End IfEnd Sub
Private Sub Chkttl5_Click () 'TTL5 invest stateIf chkTTL5.Value = 1 ThenSetPortBit Out_Port, 5chkTTL5.Caption = "Output TTL5 = 1 - HIGH"ElseClrPortBit Out_Port, 5chkTTL5.Caption = "Output TTL5 = 0 - UNDER"End IfEnd Sub
Private Sub Chkttl6_Click () 'TTL6 invest stateIf chkTTL6.Value = 1 ThenSetPortBit Out_Port, 6chkTTL6.Caption = "Output TTL6 = 1 - HIGH"ElseClrPortBit Out_Port, 6chkTTL6.Caption = "Output TTL6 = 0 - UNDER"End IfEnd Sub
Private Sub Chkttl7_Click () 'TTL7 invest stateIf chkTTL7.Value = 1 ThenSetPortBit Out_Port, 7chkTTL7.Caption = "Output TTL7 = 1 - HIGH"ElseClrPortBit Out_Port, 7chkTTL7.Caption = "Output TTL7 = 0 - UNDER"End IfEnd SubIt shows us an image such as a wiring diagram, useful for who wants to arm
Private Sub Image2_Click ()End SubMost importantly, we must put a TIMER and the double click and enter the following code
Private Sub Timer1_Timer () 'timer from 50ms to cool inReading Dim As Byte 'display the status ofDim State (3) As Byte 'INPUT 0-3Dim Estado_Str (3) As StringLoop As Byte DimRead = Portin (In_Port) 'read the input port'Filter only the bit's I need to knowState (0) = Read And & H8 '= 00001000 in binaryState (1) = Reading And & H10 '= 00010000 in binaryState (2) = Reading And & H20 '= 00100000 in binaryState (3) And & H40 = Reading '= 01000000 in binaryFor Loop = 0 To 3If State (Loop) <> 0 ThenEstado_Str (Loop) = "1 - HIGH"ElseEstado_Str (Loop) = "0 - UNDER"End IfNext LooplblInput0.Caption = "INPUT 0 =" & Estado_Str (0)lblInput1.Caption = "INPUT 1 =" & Estado_Str (1)lblInput2.Caption = "INPUT 2 =" & Estado_Str (2)lblInput3.Caption = "INPUT 3 =" & Estado_Str (3)End SubThen create a module called MODULE.BAS containing the following:
Public Declare Sub PortOut Lib "IO.DLL" (ByVal Port As Integer, ByVal Data As Byte)Public Declare Sub PortWordOut Lib "IO.DLL" (ByVal Port As Integer, ByVal Data As Integer)Public Declare Sub PortDWordOut Lib "IO.DLL" (ByVal Port As Integer, ByVal Data As Long)Portin Public Declare Function Lib "IO.DLL" (ByVal Port As Integer) As BytePortDWordIn Public Declare Function Lib "IO.DLL" (ByVal Port As Integer) As LongPublic Declare Sub SetPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte)Public Declare Sub ClrPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte)Public Declare Sub NotPortBit Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte)GetPortBit Public Declare Function Lib "IO.DLL" (ByVal Port As Integer, ByVal Bit As Byte) As BooleanRightPortShift Public Declare Function Lib "IO.DLL" (ByVal Port As Integer, ByVal Val As Boolean) As BooleanLeftPortShift Public Declare Function Lib "IO.DLL" (ByVal Port As Integer, ByVal Val As Boolean) As BooleanIsDriverInstalled Public Declare Function Lib "IO.DLL" () As BooleanThen run with F5 and then generate the compiled EXE.If you want to get all the source code can download Thanks to the collaboration of the backup of the files I use in a company engineer Gerson Hernandez.Download the file in ISO formatName puerto_paralelo_Files.isoFile Format Disk Image ISOSize: 7999 KBStatus: File availableContent: Source code control program parallel port in Visual BasicLinks:Rapidshare Mirrorhttp://rapidshare.com/files/340298467/puerto_paralelo_Files.isoMegaUpload Mirrorhttp://www.megaupload.com/?d=8GDJWQIMSource: http://www.taringa.net/posts/downloads/11574713/Enciende-las-luces-de-tu-casa-por-computadora.html

No comments:

Post a Comment