Introduction: Take Over "your" World Using BASIC

Pinky:        "Gee, Brain, what do you want to do tonight?"
The Brain: "The same thing we do every night, Pinky—try to take over the world!"
--Pinky and the Brain

Trying to come up with an amazing Halloween or Christmas display?

What if I told you that you could control ANY device from a simple BASIC program?
What if I told you that you could detect 100+ inputs from a device that will cost you less than $5.00

Take over the world from BASIC?  Ok, maybe not the entire world, but you'll have a great time scaring candy munching "trick or treaters" this year using a little BASIC computer that won't require a degree in rocket science to program.   Once more, you'll be able to take the "tricks" you learn here as the head-start for a great Christmas display.

I'm going to intentionally write this Instructable to be as "open" as possible so that you can flex it into your projects. I'm going to give you the ingredients for how to make "cookies" here, but you get to decide how they will look and taste. 

Here's what you'll need:

A Pocket Mini Computer
The Pocket Mini Computer is a little Propeller based microcomputer that behaves like a 1980's computer.  On the surface, it appears to be an interesting nostalgia toy, but we'll push the project further with this Instructable, using it as an easy control device for Halloween or Christmas display fun.  You can build your own Pocket Mini Computer from scratch, or buy an easy-to-assemble kit from here.  (If you've never heard of the Pocket Mini Computer, check out this Instructable.)

A PS/2 Keyboard
You should be able to score one of these from an old computer you didn't throw away, or Goodwill for less than $5.00, heck a lot of computer shops will give you one just for asking.  It doesn't have to be pretty,  Even if there is food and hair growing from the keys, it's PERFECT for what we have in mind.

An X10 Firecracker Kit
A four piece kit can be had from Ebay between $30-$40.  It is perfect for controlling 110v devices without having to worry about getting electrocuted from high voltage, or accidentally frying the family pooch.   You'll need the CM17A firecracker with the receiver.  Order the kit with more than device controller, I promise you'll want it after you start playing with this.

Update on the X10 Gear:
I've been talking to Martin at who tells me that you can build this project using the CM17A ($4.99) and the TM751 Receiver Module ($14.99).  I bought my gear from his shop via Ebay and can vouch for his service.

A few minor electronics parts: (I promise, this is an EASY circuit to build)
A solderless breadboard (or perf board if you want to make this permanent project.)
TC4427 level-shifter IC (source: Digikey)
An 8pin DIP socket (source: Radio Shack)
A DB9 male connector (source: Radio Shack)
A couple 10k resistors (source: Radio Shack)
One 0.1uf capacitor  (source: Radio Shack)

Step 1: Creating the X10 Circuit

The X10 Firecracker is a PC serial device.  I'm going to show you how to interface it to your Pocket Mini Computer with a simple circuit.

I've created mine on a "solderless" breadboard, but this image has a PCB layout and schematic.

Here's step-by-step instructions for building it on a PCB "perf" board:
  1. Place 8pin socket at J5-J8
  2. Red wire from N2 to H2
  3. Red wire from F2 to F7
  4. Small jumper wire from N4 to M4
  5. Small Jumper wire from M7 to L7
  6. Purple wire from N6 to L6
  7. Purple wire from N8 to L8
  8. 10k resistor from M5 to K6
  9. 10k resistor from M9 to K8
  10. Wire from M1 to 9pin-5
  11. Wire from F6 to 9pin-4
  12. Wire from F8 to 9pin-7
  13. Solder row of 4 male pins P1-P4
  14. Solder row of 4 (or more) male pins P6-P9
  15. Insert TC4427 facing left
Once you have the circuit completed, connect the following wires to your Pocket Mini Computer:
  1. P4 to Vss on the Pocket Mini Computer
  2. P2 to 5v on the Pocket Mini Computer  (This can be found on the first pin of the iR connector)
  3. P6 to P13 on the Pocket Mini Computer
  4. P9 to P12 on the Pocket Mini Computer

Step 2: BASIC and the X10

Ever write or see this BASIC program?

20 GOTO 10

The Pocket Mini Computer is programmed in the same type of BASIC language.  BASIC is considered one of the easiest programming languages in the world and has a rich history of devices and machines which use it.   It's generally considered slow and not very functional, but we've taught the BASIC on the Pocket Mini Computer a few new tricks.

Download and add the file, X10.BIN to your Pocket Mini Computer's microSD card.  

This will add the ability to control X10 devices from BASIC  

Let's give it a test!

Plug a lamp into an X10 module set as A1 and turn it on.

Type in the following BASIC program and RUN it.

10 BRUN "X10.bin" A1 OFF

The lamp to turn off, and your Pocket Mini Computer reset.  Perfect!   Let's turn the lights back on before we continue.  RUN the following program.

10 BRUN "X10.bin" A1 ON

Ok, we can control devices in the outside world, ready to detect input?  Read on!
(BTW, if you've got the Pocket Mini Computer with SRAM, try the program in the image. <smirk>)

Step 3: Seeing the Outside World From BASIC

The Pocket Mini Computer measures exactly 2"x3".  Not a lot of room there to connect too many devices. 

Or is there?

If you've been programming your X10 devices in BASIC, you are already using a device that contains over 100 switch connections!  Here's where that old PS/2 keyboard comes in!  Grab a screw driver and start disassembling it, because today you won't just see a keyboard any more.  Today you'll see a way to read input from over 100 different switches!

Put a screwdriver to the backside and start ripping it apart!  I got an old Gateway PS/2 keyboard that someone tossed it.  Freebie!

Step 4: Keyboard Input PCB Board.

The keyboard uses a little circuit board, located in the top right inside the keyboard casing.

Unscrew all of the screws and remove it with it's PS/2 cable (The cable that plugs into a computer).  
There's some other great Instructables out there for what to do with those flexible, plastic circuit sheets, so don't just toss them out.

Step 5: Preparing the Keyboard Circuit.

Once you have the keyboard circuit and it's PS/2 wire removed, carefully unsolder those worthless slide-in connectors and replace them with either male or female pin headers.   (I chose male headers for my project, but either will work just fine.)

Removing the old connectors is pretty easy.  Use a pair of wire cutters to snip away all of the plastic, leaving the pins themselves.  Heat the backside of the old pins with your soldering iron and they will fall out easy.

Once you have the holes cleaned out, insert your headers and solder them in place.

Can you believe I've seen this same circuit sold online for more than $60.00?

Step 6: Hacking the Keyboard Circuit

The keyboard uses a system of "rows" and "columns" to detect a key.

Looking at our keyboard circuit, you'll see one short row of pins, (the rows), and a second longer row of pins (the columns).  When a connection is made between one of the rows and one of the columns a key has been pressed on the keyboard.

We disposed of the other bits of keyboard, so we can use a simple wire as a switch.

Plug your keyboard circuit into your Pocket Mini Computer and turn it on.

Connect a wire to the first connection on the "rows" side and touch it to one of the "columns" side.
(Don't worry!  It's all 5v "battery level voltages" and you'll hurt nothing!)

A key press will appear on the screen.  It didn't?  Try the next one!  Heck, pull the wire down the "columns" side and watch all kinds of keystrokes appear on your Pocket Mini Computer.  Cool huh?

Step 7: Better Switches

So using a simple wire acts a switch completes a connection between rows and columns on the keyboard circuit.

Time to upgrade!

Let's look at some "other" more interesting switches and how they work.

1. The pressure pad, (or stomp switch)

Pressure mats can be purchased, but they tend to be a little pricey.  
Using some foil, cardboard, and lots of duct tape, you can create your own pressure mat.  
(Some great instructions for how to create one can be found here.)

2. The magnetic switch

Magnetic switches work by activating or deactivating when a magnet is nearby.  They are common to alarm systems and can be had from both Ebay or your local Radio Shack.   If you use a magnetic switch, you want one that is "N/O" or normally open.   An inexpensive version of this is called a "magnetic reed switch" which closes when a magnet is put nearby.

3. The tilt switch

Thirty years ago, cars commonly used a mercury tilt switch to detect when the trunk was open and activate the trunk light.  Mercury is a poison that isn't used in this manner any more, but you can still get tilt switches.  Instead of mercury, they usually use a small metal ball inside to make complete the circuit when the switch is tilted.

4. The Thermal switch

This is an inexpensive switch that triggers when high temperatures are detected.  Commonly used in furnaces.   You can obtain an old thermostat swtich from an old household A/C system that can trigger on whatever temperature you set.

5. The motion switch

Motion switches detect movement within a specified radius.  Want a cheap motion switch?  There's information on hacking the PIR motion switch that is used in an air fresher here

Step 8: Putting It All Together

This Instructable has taught you how to safely control any 110v device from BASIC, then we hacked a simple PS/2 keyboard, making it into a 100+ switch input device.   Let's put the two together and see how it works.

Plug an "unhacked" PS/2 keyboard into your Pocket Mini Computer and type in the following program:

10 COLOR 63,0
20 CLS
40 PRINT " "
70 PRINT " "
110 IF a = 49 then BRUN "X10.bin" A1 ON
120 IF a = 50 then BRUN "X10.bin" A1 OFF
130 IF a = 51 then BRUN "X10.bin" A2 ON
140 IF a = 52 then BRUN "X10.bin" A2 OFF

Once you've typed it in, save it, then hit F1 twice to put it into the start up file of your PMC.  This will cause the program to start automatically every time you turn on your Pocket Mini Computer.  (You can clear it later with the NEW command.)

Once you run this program, you will have control over two different X10 connected devices by pressing keys 1-4 on your keyboard.

Time to get out our modified keyboard and get out those switches!

Questions about this project or the Pocket Mini Computer?  There's a dedicated forum for the project full of friendly people.

Have a great time & Happy Holidays from!

Hack It! Contest

Participated in the
Hack It! Contest