loading
Micro-controllers are very neat. Have a few myself. Connecting to micro-controllers or to a PC is basically the same. So you do not have a micro-controller yet, grab an old PC and get to work.  This is an extension of the original instructable: Security with a Pentium I.  You can find the original instructable at https://www.instructables.com/id/Security-system-with-old-pentium-1/ . This time we add a pir sensor, heat sensors, and a emf sensor to the mix. My goal is to give you just enough information so you can make up your own system your way. That is half the fun of it to experiment. If you have a newer machine with the built-in parallel and joystick ports should do just as well, but be extremely careful.  USB ports with parallel and joystick interface cables tend not to work.

Among the other parts needed:
Both a db15 male joystick and a db25 male connector. You could use the one from the original project as I tried to use different pins to avoid conflict.

Note: As always do this at you own risk, I will not be responsible for any issues. All circuits and code are untested, contract a professional if you are unsure. Note each sensor should be on a separate pin. I just used the same pin for testing purposes.

Update: I am not an electronics specialist. If you have any concern with what is done here, ask a professional. I am testing the circuits and if there are any changes needed should be done soon so this instructable will tend to get updated once in a while.
----------------------------------------------------------------

pin     purpose
1       potentiometer common            (Joy A)
2       button 1                        (Joy A)
3       X coordinate potentiometer      (Joy A)
4       button common                   (Joy A)
5       button common                   (Joy B)
6       Y coordinate potentiometer      (Joy A)
7       button 2                        (Joy A)
8       unused
9       potentiometer common            (Joy B)
10      button 1                        (Joy B)
11      X coordinate potentiometer      (Joy B)
12      MIDI TXD (transmit)             (computer -> midi)
13      Y coordinate potentiometer      (Joy B)
14      button 2                        (Joy B)
15      MIDI RXD                        (midi -> computer)

 Also check out: https://www.instructables.com/id/Computerized-video-security-setup/

Step 1: How to Connect a Pir Sensor.

Movement means trouble at off hours, so you need a way to detect movement.

Needed:
5v pir sensor Be sure and check the pin outs as not all are the same. (Ours was a R/S 276-0033 aka Parallax 555-28027)
Use http://www.ladyada.net/learn/sensors/pir.html as a guide to test your sensor.
npn transistor 2n2222 or 2n3904.
5 volt relay.
10k ohm resistor.
1n4002 diode.
Wire.

Note the forth picture is for those who like a little more safety in the circuit.
--------------------------------------------------------------------------------------
Example code:
getpirdata:
r = STRIG(2)
SELECT CASE r
        CASE -1
                flag = 1
        CASE 0
                flag = 2
        CASE ELSE
                GOSUB errornotice
END SELECT
RETURN
--------------------------------------------------------------------------------------
          Joystick B             ____      Joystick A
                                /    |
                              /      |
                            /        |
                          /       1  |
                         |        O------- 5 Volt
              5 Volt -------O        |
                         |  9     2  |
                         |        O------- Button 1
            Button 3 -------O        |
                         |  10    3  |
                         |        O------- Resistor X-axis (joystick(1))
     Resistor X-axis -------O        |
      (joystick(2))      |  11    4  |
                         |        O------- Ground
            MIDI TXD -------O        |
                         |  12    5  |
                         |        O------- Ground
     Resistor Y-axis -------O        |
       (joystick(2))     |  13    6  |
                         |        O------- Resistor Y-axis (joystick(1))
            Button 4 -------O        |
                         |  14    7  |
                         |        O------- Button 2
            MIDI RXD -------O        |
                         |  15    8  |
                         |        O------- 5 Volt
                          \          |
                            \        |
                              \      |
                                \    |
                                  \__|

Digital
pin  2 = Button 1 = Strig(0)
pin  7 = Button 2 = Strig(1)
pin 10 = Button 3 = Strig(2)
pin 14 = Button 4 = Strig(3)
Analog
pin      3  =  Resistor =  Stick(0)
pin      6  =  Resistor =  Stick(1)
pin    11  =  Resistor =  Stick(2)
pin    13  =  Resistor =  Stick(3)

Step 2: How to Add a Heat Sensor.

Temperature sensor. Part 1 (or part of a sous vide machine) based on:
http://www.sensorsmag.com/sensors/temperature/in-search-a-low-cost-temperature-sensor-part-1-702 , http://sablesystems.com/document-support_measurement-guide.html , and other articles.

Excessive heat Is a danger to computing equipment and you need to have some way to be alert you of this. You will probably have to do tests of actual temperatures to make your own table to correlate readings and actual temperatures. 

I will probably do this in two steps since there is more than one kind of heat sensor. we shall see.

Needed:
Silicon diode from old radio, 1n4148, or a 1n914
10k ohm resistor (10k pot would be better for calibration) When I went back and looked at my research, 12v was used not 5v so a 5k pot or 3.7k resistor might work better.
wire.
--------------------------------------------------------------------------------------
Will have to do some testing to see what value corresponds to
what temperature. there are several formulas available:
Results may vary.
pseudo code:

gettempdata:
r = STICK(2)
Temp = r
        print "temperature rating (0 - 255) is: "; temp
if temp  > some value then print "Warning, Too hot"
dangerflag = 1
...
...
...
RETURN

--------------------------------------------------------------------------------------
          Joystick B             ____      Joystick A
                                /    |
                              /      |
                            /        |
                          /       1  |
                         |        O------- 5 Volt
              5 Volt -------O        |
                         |  9     2  |
                         |        O------- Button 1
            Button 3 -------O        |
                         |  10    3  |
                         |        O------- Resistor X-axis (joystick(1))
     Resistor X-axis -------O        |
      (joystick(2))      |  11    4  |
                         |        O------- Ground
            MIDI TXD -------O        |
                         |  12    5  |
                         |        O------- Ground
     Resistor Y-axis -------O        |
       (joystick(2))     |  13    6  |
                         |        O------- Resistor Y-axis (joystick(1))
            Button 4 -------O        |
                         |  14    7  |
                         |        O------- Button 2
            MIDI RXD -------O        |
                         |  15    8  |
                         |        O------- 5 Volt
                          \          |
                            \        |
                              \      |
                                \    |
                                  \__|

Digital
pin  2 = Button 1 = Strig(0)
pin  7 = Button 2 = Strig(1)
pin 10 = Button 3 = Strig(2)
pin 14 = Button 4 = Strig(3)

Analog
pin  3  =  Resistor = Stick(0)
pin  6  =  Resistor = Stick(1)
pin 11  =  Resistor = Stick(2)
pin 13  =  Resistor = Stick(3)DIODES.  Yes, diodes. Ordinary silicon diodes, 1N4148, 1N914 or equivalent (as low as $1.99 for 50; see our listed suppliers ) are 
very linear temperature sensors over the range -50 to +150 degrees C. To use a diode as a temperature sensor, connect it as pictured (note that the cathode, denoted by a band, is oriented towards ground). R1 should be about 10,000 ohms. Connect the diode to the end of a length of shielded cable, and protect it with silicone or epoxy cement. The diode will develop about 0.6V, which will fall as its temperature rises. Use the CALIBRATE option of your data acquisition package (if, like ExpeData , it has one) to calibrate it,in the medium (air or water) that it will operate in . Because of self-heating, its calibration will change slightly if its medium changes. Resolution and accuracy are about 0.5 degree C - adequate for many purposes. You can supply the bias voltage from a digital output. 

Step 3: Temperature Sensor. Part 2

Temperature sensor. Part 2 (or part of a sous vide machine)

Excessive heat Is a danger to computing equipment and you need to have some way to be alert you of this.

Using a real temp sensor.

Needed:
wire
LM355
2k ohm resistor (changed value after going back and looking at my research.)
wire.
-------------------------------------------------------------------------------------
-Will have to do some testing to see what value corresponds to
what temperature. there are several formulas available.
Results may vary.
pseudo code:

gettempdata:
r = STICK(2)
Temp = r
        print "temperature rating (0 - 255) is: "; temp
if temp  > some value then print "Warning, Too hot"
dangerflag = 1
...
...
...
RETURN

--------------------------------------------------------------------------------------
          Joystick B             ____      Joystick A
                                /    |
                              /      |
                            /        |
                          /       1  |
                         |        O------- 5 Volt
              5 Volt -------O        |
                         |  9     2  |
                         |        O------- Button 1
            Button 3 -------O        |
                         |  10    3  |
                         |        O------- Resistor X-axis (joystick(1))
     Resistor X-axis -------O        |
      (joystick(2))      |  11    4  |
                         |        O------- Ground
            MIDI TXD -------O        |
                         |  12    5  |
                         |        O------- Ground
     Resistor Y-axis -------O        |
       (joystick(2))     |  13    6  |
                         |        O------- Resistor Y-axis (joystick(1))
            Button 4 -------O        |
                         |  14    7  |
                         |        O------- Button 2
            MIDI RXD -------O        |
                         |  15    8  |
                         |        O------- 5 Volt
                          \          |
                            \        |
                              \      |
                                \    |
                                  \__|

Digital
pin  2 = Button 1 = Strig(0)
pin  7 = Button 2 = Strig(1)
pin 10 = Button 3 = Strig(2)
pin 14 = Button 4 = Strig(3)

Analog
pin  3  =  Resistor = Stick(0)
pin  6  =  Resistor = Stick(1)
pin 11  =  Resistor = Stick(2)
pin 13  =  Resistor = Stick(3)

Step 4: Temperature Sensor. Part 3

Temperature sensores are in many items we use every day. You have a thermostat in a dryer, a thermister in some computer fans, and etc. WE use the analog game port to check the readyness of a clothes dryer thermost. About to pul the thermistor from a computer fan ti let the computer be a thermometer. Made a quickie special cable to attach such items.                                 

Step 5: How to Detect EMF.

Magnets or magnetic fields can kill hard drives and computer equipment, so it is imperative that you have some defence against these issues. Antenna should be far enough away from computer as not to affect the signal. You will need to experiment to see what value are dangerous and which are not.

Needed:
Several feet of wire.
3.3meg ohm resistor.

--------------------------------------------------------------------------------------
Example code:
  pseudo code:
getmagdata:
r = STICK(1)
maglevel = r
print "maglevel (0-255) is: "; maglevel
if maglevel > some value then print"Warning, magnetic danger"
dangerflag = 1
...
...
RETURN

--------------------------------------------------------------------------------------
          Joystick B             ____      Joystick A
                                /    |
                              /      |
                            /        |
                          /       1  |
                         |        O------- 5 Volt
              5 Volt -------O        |
                         |  9     2  |
                         |        O------- Button 1
            Button 3 -------O        |
                         |  10    3  |
                         |        O------- Resistor X-axis (joystick(1))
     Resistor X-axis -------O        |
      (joystick(2))      |  11    4  |
                         |        O------- Ground
            MIDI TXD -------O        |
                         |  12    5  |
                         |        O------- Ground
     Resistor Y-axis -------O        |
       (joystick(2))     |  13    6  |
                         |        O------- Resistor Y-axis (joystick(1))
            Button 6 -------O        |
                         |  14    7  |
                         |        O------- Button 2
            MIDI RXD -------O        |
                         |  15    8  |
                         |        O------- 5 Volt
                          \          |
                            \        |
                              \      |
                                \    |
                                  \__|

Digital
pin  2 = Button 1 = Strig(0)
pin  7 = Button 2 = Strig(1)
pin 10 = Button 3 = Strig(2)
pin 14 = Button 4 = Strig(3)

Analog
pin  3  =  Resistor = Stick(0)
pin  6  =  Resistor = Stick(1)
pin 11  =  Resistor = Stick(2)
pin 13  =  Resistor = Stick(3)

Step 6: Extra Inputs.

Lets say you want some extra door pir sensors, you can use this circuit to do this.  This circuit used 3 k ohm pull-up resistors and extra 330 ohm "safety" resistors between the parallel port and rest of the circuit. Note you will need something like the https://www.instructables.com/id/No-solder-parallel-port-break-out/ to set it up.

  • D3: state of pin 15 (ERROR) inverted- not
  • D4: state of pin 13 (SELECTED)
  • D5: state of pin 12 (PAPER OUT)
  • D6: state of pin 10 (ACK)
  • D7: state of pin 11 (BUSY) inverted- not
------------------------------------------------------------------------------------------------------
pseudo code:
rem pport 1
rem 2^7  <=  pin  11        
rem 2^6  <=  pin  10          
rem 2^5  <=  pin  12         
rem 2^4  <=  pin  13          
rem 2^2  <=  pin  15  

N = INP(&H379)
select case N
case N and 2^6
      print "line 10 is closed"
case N and not 2^7
      print "line 11 is closed"
case N and 2^5
      print "line 12 is closed"
case N and 2^4
      print "line 13 is closed"
case N and not 2^2
      print "line 15 is closed"
end select


------------------------------------------------------------------
CLS
DEFINT A-Z
Address = 889: REM 889 = port address, other addresses could be 633 or 957
PRINT "Press the enter key to read printer port pins (15,13,12,10,11)"
PRINT "A (0) reading indicates the pin is at ground level, (1) indicates"
PRINT "the pin is at a high level or unterminated."
INPUT A$
V = INP(Address)
PRINT V
P11 = 1
IF V > 127 THEN P11 = 0: V = V - 128
IF V > 63 THEN P10 = 1: V = V - 64
IF V > 31 THEN P12 = 1: V = V - 32
IF V > 15 THEN P13 = 1: V = V - 16
IF V > 7 THEN P15 = 1
PRINT
PRINT "Pin 15 ="; P15
PRINT "Pin 13 ="; P13
PRINT "Pin 12 ="; P12
PRINT "Pin 10 ="; P10
PRINT "Pin 11 ="; P11
END

Step 7: Qbasic Notes.

STRIG()
Syntax:

STRIG(n)

Return Value(s):

The status of the specified joystick button (trigger).
See Also: STICK()

There are two status types for each button on each joystick, making the valid values of n ranging from 0 to 7. The return value of STRIG(n) will be either 0 (inactive) or -1 (active). The following chart shows what is indicated when the STRIG() value is -1.

  STRIG(0)  button 1 on joystick 1 pressed since last STRIG(0)
  STRIG(1)  button 1 currently pressed
  STRIG(2)  button 2 on joystick 1 pressed since last STRIG(2)
  STRIG(3)  button 2 currently pressed
  STRIG(4)  button 1 on joystick 2 pressed since last STRIG(4)
  STRIG(5)  button 1 currently pressed
  STRIG(6)  button 2 on joystick 2 pressed since last STRIG(6)
  STRIG(7)  button 2 currently pressed

The many combinations of STRIG() output enable extremely detailed reading of the joysticks' buttons. Unlike the STICK() function, the STRIG function is based on digital input, and thus is very reliable.

If you are interested in wiring a burgler alarm to your door, or making a similar project, get a cheap joystick to take apart. Add wires to extend the physical range of the buttons, wire them to other devices, and see what you can accomplish. It's great fun getting real-world input into the computer!

---------------------------------------------------------------


STICK()
Syntax:

STICK(n)

Return Value(s):

The current value of the specified joystick coordinate.
See Also: STRIG()

The STICK() variable is actually a small array containing the four values: the x-y pair of joystick 1 and the x-y pair of joystick 2. Valid values for n are 0 to 3.

  joy1x = STICK(0)
  joy1y = STICK(1)
  joy2x = STICK(2)
  joy2y = STICK(3)

An important detail of the STICK array is that the values of STICK(1), STICK(2), and STICK(3) are "refreshed" only when STICK(0) is referenced. Therefore, simply calling STICK(1) without calling STICK(0) should cause no change in value, despite the movement of the joystick.

Since the development of computers beyond the XT-PC (a.k.a 8086), joysticks have become more and more incompatible with QBasic programming, so do not expect perfect results. The following program should print out the current x-y coordinates of the joystick. They can then be translated into whatever form needed:

  start:
  PRINT "Joystick1 x: ", STICK(0)
  PRINT "Joystick1 y: ", STICK(1)
  GOTO start

Good use of ASCII graphics. It looks like you have put a lot of hard work into your instructable.
Still have a bit of tweaking to do, but I have updated this instructable a bit.

About This Instructable

6,494views

22favorites

License:

Bio: computoman.blogspot.com Bytesize articles instead of a trilogy in one post.
More by Computothought:Coffeepot meals Easy sun hat Easy cakes and pies. 
Add instructable to: