You are on page 1of 15

Home Sign Up!

Explore Community Submit

Control real world devices with your PC


by Dr_Acula on October 22, 2007

Table of Contents

intro: Control real world devices with your PC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

step 1: Gather the parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

step 2: Download and install some software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

step 3: Build a download circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

step 4: Protoboard layout of the download circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

step 5: Download the picaxe program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

step 6: Reconfigure the circuit as a serial interface circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

step 7: Write some VB interface code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

step 8: Design the VB.Net form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

step 9: Add A Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

step 10: Add a couple of buttons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

step 11: Form with all the controls added . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

step 12: Add some code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

step 13: Run the program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

step 14: Input devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

step 15: Controlling devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

Customized Instructable T-shirts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

http://www.instructables.com/id/Control-real-world-devices-with-your-PC/
intro: Control real world devices with your PC
This Instructable shows you how to interface a PC and microcontroller. This demo will sense the value of a pot or any analog input and also control a servo. Total cost is
under $40 including the servo. The servo turns on a microswitch and then the microswitch turns on a lamp. In a practical application the pot could be a temperature
sensor and the servo could be turning on a heater. The servo could be replaced with a relay or other power controller. The picaxe is programmed in a simplified version
of basic and the interface uses VB.Net. All software is available for free.

A related Instructable shows how to link two microcontrollers via the internet http://www.instructables.com/id/Worldwide-microcontroller-link-for-under-20/

step 1: Gather the parts


Parts list:

Picaxe 08M chip available from many sources including Rev Ed http://www.rev-ed.co.uk/picaxe/ (UK), PH Anderson http://www.phanderson.com/ (USA) and Microzed
http://www.microzed.com.au/ (Australia)

Protoboard, servo, microswitch, 9V battery, 4xAA batteries and holder, tag strip, 10k resistor, 22k resistor, 33uF 16V capacitor, 0.1uF capacitor, 7805L low power 5V
regulator, 10k pot, wires (solid core telephone/data wire eg Cat5/6), 6V lightbulb, D9 female socket and cover, 2 metres of 3 (or 4) core data wire, battery clips

The above companies also sell USB to serial devices which are useful for laptops which don't have a serial port. It is worth noting that some USB to serial devices don't
work as well as others and it is worth getting one from one of the above suppliers as they have been tested for use with picaxe chips. The one that is known to work is
http://www.rev-ed.co.uk/docs/axe027.pdf Of course, if your computer has a serial port (or an old serial port card) then this won't be an issue.

http://www.instructables.com/id/Control-real-world-devices-with-your-PC/
step 2: Download and install some software
We will need the VB.Net and the picaxe controller software.

VB.Net (Visual Basic Express) is available from http://msdn2.microsoft.com/en-us/express/aa718406.aspx

If this link does not work then search in Google for: visual basic express download

The picaxe software is available from http://www.rev-ed.co.uk/picaxe/

You will need to register with microsoft to get the download - if this is a problem use a fake email or something. I actually found it helpful giving my real email as they send
occasional updates.

step 3: Build a download circuit


This download circuit uses a picaxe chip, a couple of resistors, a regulator and a 9V battery. More information is available in the picaxe documentation and this should
only take a few minutes to build once all the parts are to hand.

I might also add that picaxes do run happily on 3 AA batteries. A 5V regulated supply is useful for running analog inputs as the reference voltages don't change, but for
simple on/off circuits a regulated supply is not needed. The 5V reg can be left out in these situations.

step 4: Protoboard layout of the download circuit


This photo shows the download cable which is simply a D9 plug and a couple of metres of some multi core cable. Most modern PCs have a D9 serial port connection. A
PC built before about 1998 might have a 25 pin connector. I soldered about 1cm of solid core wire onto the end of the flexible wires and then put heatshrink around this -
the solid core wires go into a protoboard much better than flexible wires.

http://www.instructables.com/id/Control-real-world-devices-with-your-PC/
step 5: Download the picaxe program
Click on the blue arrow to download. If it doesn't download there are some debugging suggestions in the picaxe instruction manual. You can try downloading a simple
program to turn a led on and off to check the chip works. This program as it is does nothing until it is connected to a PC as it is waiting for the PC to send it something. If it
downloads ok then it is working and the chip is programmed and the next step is to reconfigure the chip as a serial interface chip.

Copy and paste the code below. To view it with color syntax look in View/Options/Editor. The color conventions are similar to VB.Net

main:serin 3,N2400,("Data"),b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13
readadc 1,b1' read the pot then send this back
serout 0,N2400,("Data", b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13)
select case b0' read data bit b0
case <140' if <140 then set servo to one position
servo 2,120
pause 1000' pause a second
else
servo 2,160
pause 1000
endselect
low 2' turn off the servo as serin does this anyway
goto main

step 6: Reconfigure the circuit as a serial interface circuit


Two subtle changes have been made to the picaxe circuit. The 22k resistor that used to go to leg 2 now goes to leg 4. And leg 2 has been grounded. The only purpose of
leg 2 is to receive programming data from the PC so once the chip is programmed it can be tied to ground. If you go back to programming the chip to correct bugs etc
then disconnect leg 2 from ground and reconnect the 22k to leg 2. The picaxe talks back to the PC via leg 7 so this does not need to change.

A pot has been added and the servo has been added. The servo is not really necessary and a led and a 1k resistor would work fine and/or any circuit you wish to
connect. I just used a servo to show how clicking something on a screen can make something actually move.

The servo is run off its own power supply. This separate power supply would not be needed if the picaxe were just turning leds on and off.

The picaxe is ready to go - now we need some VB code.

http://www.instructables.com/id/Control-real-world-devices-with-your-PC/
step 7: Write some VB interface code
Once VB.Net is installed run it and select File/New Project and select Windows Application. You can click File/Save All right at the beginning and save to wherever you
like and then in the future either start the project from within VB.Net or by clicking on a .sln file that will be created.

step 8: Design the VB.Net form


VB creates a new blank form called Form1.vb. You can change the name of this now or later or just leave it as Form1 if the project is simple. We will leave it as it is. To
add some control we need to open the toolbox which is circled in green. The toolbox can be opened and closed whenever it is needed - usually the first step is to add the
controls then close the toolbox and work on code. You can leave it open all the time but it does take up a bit of screen.

http://www.instructables.com/id/Control-real-world-devices-with-your-PC/
step 9: Add A Timer
We have scrolled down the toolbox and selected a timer. Double click on the timer to add it. A picture of a clock called Timer1 will appear at the bottom of the screen and
over at the right the timer properties are highlighted. You can edit these or they can be changed in the text body of the code. We will leave them as they are and change
them in the body of the text.

As an aside, the toolbox does look a bit daunting but only a few are needed for most programs - these would include Buttons, Text boxes, Labels, Timers, Picture boxes,
Check boxes and Radio boxes. Perhaps open a new program and have a play with a few sometime.

step 10: Add a couple of buttons


Click on the button tool and draw the size of the button on Form1. We are going to need two buttons, a picture box and a label. Go ahead and add these - the next
screenshot shows these all drawn in. Size and position is not important and you can rename them later if you like.

step 11: Form with all the controls added


Form1 is now laid out. The box next to Button2 is a small picture box. You can put pictures in this but we are just going to use it to indicate which button has been
pressed by changing it from red to green. Label1 displays the picaxe registers.

http://www.instructables.com/id/Control-real-world-devices-with-your-PC/
step 12: Add some code
Over on the right circled in green are several useful buttons - the second from the right is the View Code button and the right button is the View Designer. In practice
when writing code one goes back and forth between these views. Generally if one is in Designer mode double clicking on an object such as a button brings up a spot in
the Code View to add some code or takes one to the piece of code that runs when the button is pressed. In this way the program flow becomes quite intuitive - the user
clicks on things and bits of code run and change the screen and so on.

For our purposes though we are going to cheat and paste in a whole slab of working code.

The code view will have Public Class Form1 ...End Class - highlight this and delete it. Now take all of the code below and paste it in.

Imports System.IO
Imports Strings = Microsoft.VisualBasic ' so can use things like left( and right( for strings
Public Class Form1
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Integer) ' for sleep statements
Dim WithEvents serialPort As New IO.Ports.SerialPort ' serial port declare
Dim PicaxeRegisters(0 To 13) As Byte ' registers b0 to b13
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Timer1.Enabled = True ' put this in code as defaults to false when created
Timer1.Interval = 5000 ' 5 seconds
PictureBox1.BackColor = Color.Red ' set to position 'red'
Array.Clear(PicaxeRegisters, 0, 13) ' probably not needed as array declared blank
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
' timer ticks every 5 seconds
Call SerialTxRx() ' talk to picaxe
End Sub
Sub SerialTxRx()
Dim LabelString As String ' string to display byte values
Dim DataPacket(0 To 17) As Byte ' entire data packet "Data"+14 bytes
Dim i As Integer ' i is always useful for loops etc
Label1.Text = "" ' clear the text on the screen
For i = 0 To 3
DataPacket(i) = Asc(Mid("Data", i + 1, 1)) ' add the word "Data" to the packet
Next
For i = 0 To 13
DataPacket(i + 4) = PicaxeRegisters(i) ' add all the bytes to the packet
Next
If serialPort.IsOpen Then
serialPort.Close() ' just in case already opened
End If
Try
With serialPort
.PortName = "COM1" ' Most new computers default to com1 but any pre 1999 computer with a serial mouse will probably default to com2
.BaudRate = 2400 ' 2400 is the maxiumum speed for small picaxes
.Parity = IO.Ports.Parity.None ' no parity
.DataBits = 8 ' 8 bits
.StopBits = IO.Ports.StopBits.One ' one stop bit
.ReadTimeout = 1000 ' milliseconds so times out in 1 second if no response
.Open() ' open the serial port
.DiscardInBuffer() ' clear the input buffer
.Write(DataPacket, 0, 18) ' send the datapacket array
Call Sleep(300) ' 100 milliseconds minimum to wait for data to come back and more if data stream is longer
.Read(DataPacket, 0, 18) ' read back in the data packet array
.Close() ' close the serial port
End With
For i = 4 To 17
LabelString = LabelString + " " + Str(DataPacket(i)) ' turn into a text string
Next
Label1.Text = LabelString ' put the text string on the screen
Catch ex As Exception
'MsgBox(ex.ToString)' uncomment this if want to see the actual error message
Label1.Text = "Timeout" ' will display this if picaxe not connected etc
End Try
End Sub
http://www.instructables.com/id/Control-real-world-devices-with-your-PC/
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PictureBox1.BackColor = Color.Red ' change the box to red
PicaxeRegisters(0) = 120 ' an arbitrary value for the servo
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
PictureBox1.BackColor = Color.Green ' box to green
PicaxeRegisters(0) = 160 ' arbitrary value for the servo
End Sub
End Class

step 13: Run the program


Power up the picaxe if it isn't powered up. Run the vb.net program by clicking on the green triangle at the top of the screen near the middle. To the right of the run triangle
are a pause button and a stop button, or the program can be stopped by clicking on the top right x or with File/Exit if you have added a menu. The program can be
compiled if you like but for debugging let's leave it running within VB.

The timer is sending out bytes every 5 seconds so it takes 5 seconds for the display to come up.

The label1 is displaying a dump of the 14 picaxe registers. These are sent to the picaxe and then send back again. It almost certainly isn't necessary to send all 14 and
your code can be changed to suit. The second byte with a value of 152 is the value of the pot which changes from 0 to 255.

If button1 is clicked it sends a value of 120 in the first byte and if button2 is clicked it sends 160 and the picaxe program decodes these and moves the servo.

This code shows how to send data and get data back from a microcontroller. The microcontroller can turn on all sorts of devices - I have about 30 round my house
running sprinklers, lights, security, detecting cars in driveways, turning on a number of 3.6Kw pumps and sensing the level of water in tanks. Picaxes can be daisychained
on a common bus and can even communicate with each other via radio links.

It is also possible to upload and download data from websites and hence use the internet to connect devices anywhere in the world
http://www.instructables.com/id/Worldwide-microcontroller-link-for-under-20/

The next two pages also contain some examples of how to use different sensors and how to control different devices.

Dr James Moxham
Adelaide, South Australia

http://www.instructables.com/id/Control-real-world-devices-with-your-PC/
step 14: Input devices
The picaxe programmer contains some very useful help files, one of which is called "Interfacing circuits" and it is also available at http://www.rev-
ed.co.uk/docs/picaxe_manual3.pdf

This shows how to control motors, sense the environment and other useful control.

In addition to these cirucits, there are a few that I use over and over again.

Temperature - the LM35 temperature sensor produces a voltage which can go straight into a picaxe and can be read with a readadc or readadc10 command.

Light - a light dependent resistor has a resistance that varies from a few hundred ohms in bright sunlight to over 5 megohms in pitch black. Measure the resistance at the
light level you want to switch at and put the LDR in series with a resistor of about the same value. Eg I wanted to detect the lights of a car pulling into the carport to turn
on some lights. The resistance was about 1M from indirect light so I put a 1M in series with the LDR.

Switch - some switches switch between 5V and 0V (a single pole double throw switch) but some just turn on and off. If a switch turns on it can send 5V to a picaxe chip
but if it is off the picaxe pin would be 'floating' and could be any value. This circuit shows how to pull the input down to ground when the switch is off. This is the circuit to
use for most pushbutton switches.

Potentiomter - a good old fashioned knob. Twiddle the knob and read the voltage into the chip.

There are all sorts of other electronic devices that create a voltage from 0-5V or can be easily configured to do so. Examples are magnetic sensors, humidity, speed,
touch, infrared light, pressure, colour and sound. Sensors in general cost only a few dollars each.

step 15: Controlling devices


The picaxe help file contains a great explanation of how to control motors and lights. In addition I find there are a few circuits I use over and over.

The first is a simple transistor circuit. A picaxe chip can turn on a maximum of 20mA per pin which is good for turning on a LED but not much else. A 547 transistor
increases the current to 100mA which is good for small light bulbs.

The second circuit shows a mosfet. Mosfets need virtually no current to drive them - only volts so they can be directly controlled by a picaxe. There are all sorts of
mosfets available but my preference is one called the BUK555 60B http://www.ortodoxism.ro/datasheets/philips/BUK555-60A.pdf It can be directly driven from 5V (unlike
some which need 10V) but the main advantage is it has an extremely low resistance when turned on - 0.045 ohms which is not much more than the resistance of the
wires one would connect to it. This means it doesn't get hot when driving quite high loads which saves power and also saves on heatsink costs. As an example driving a
5amp load like a car headlamp; watts=current squared x resistance, so W=5*5*0.045=1.12 watts which would only need a heatsink like a 1inch square piece of thin
aluminium.

The third circuit shows a relay. There are several parameters for all relays - the coil voltage, coil resistance and the load voltage and current. For instance a relay might
have a 12V coil with a coil current of 30mA, coil resistance of 400 ohms and might be able to drive up to 240V at 1 amp. The coil current is more volts and amps than a
picaxe can supply, so we use the transistor circuit to switch the coil. There is a diode included as well - this supresses the back EMF when the relay turns off. Back EMF
is what creates the spark for a sparkplug so you don't want these high voltages anywhere in a circuit. The contacts will have a maximum current and volts - the current
might be a few amps and the volts are often 240V so switching 12V or 24V will be well within range. If you are inexperienced with electronics don't play with mains
voltages.

There are also small relays that have coil voltages of 5V or 6V. For these relays you may not need a seperate 12V supply but just watch the coil resistance as many of
these have current draws of over 100mA. If so and you are using a 78L05 100mA 5V regulator you might want to change this to a 7805 regulator which can supply up to
1 amp.

Relays are particularly useful for switching AC - eg 24VAC garden sprinkler solenoids, 12VAC garden lights and in electrically noisy environments such as a car. They are
also useful for controlling big loads, eg a picaxe supplying 20mA at 5V = 0.1W controlling a transistor 12V at 100mA=1.2W to a relay 24V 100mA =2.4W to a contactor
driving a 3600W pump. If you want to control power like that then get an electrician to wire up a control box and give you two wires coming out (coil wires for a 12V relay)
that you can control. This way the electrician can sign off on the power box and you can do all the electronics without having to worry about being electrocuted.

Another use for relays is a reverse control for a motor. Using pulse width modulation into a mosfet you can control the speed of a DC motor, and with a DPDT power relay
you can change the direction. This is a simple way of controlling big motors like the ones used in 'robot wars'.

Please post a comment if you need help building something.


http://www.instructables.com/id/Control-real-world-devices-with-your-PC/
Related Instructables

Temperature
Cisco Console sensor /
A Really Simple Automated Assembling the hacking a serial to Null Modem weatherstation
RS232 9 pin Sex Lighting Using Dragon Rider mouse by Serial Adapter by chr
Change. by DMX and Perl Automatic 500 for use with bikerbob2005 by jwilson27 Meade ETX 125
russ_hensel by toastyboy Tubular Bells by the AVR Dragon Telescope
Tolaemon by barney_1 heavy electrical
wiring mod by
kouker

Advertisements
Customized Instructable T-shirts

Comments
47 comments Add Comment

Unit042 says: Oct 4, 2008. 12:08 PM REPLY


"watts=current squared x resistance"
Huh? I was taught that watts = volts x amps.

Suggestion: Excellent instructible. Pictures where appropriate, and step-by-step instruction. I've been wanting to make things move with a click of the mouse,
but wasn't sure how. I have a few picaxes "fresh outta the box", so this is perfect for them. Perhaps a line-by-line explanation as to what the VB code does. If
you could do that, then those familiar to programming can translate it to their favorite language or simply add on to the code provided.

Dr_Acula says: Oct 4, 2008. 4:42 PM REPLY


Both are correct:
I= current, V=volts, W=Watts and R=resistance then
W=V*I (as you say)
V=I*R (Ohms law)
So if you take W=V*I and substitute the V from Ohms Law as I*R you get
W=I*R*I
Or W=I squared *R

Which is kind of anti intuitive. The bottom line is when switching big currents, you don’t have any control over the I, so the only thing you can vary is the
R, and so it has to be as small as possible. It may explain why, in the world of semiconductors, relays are still popular.
http://www.instructables.com/id/Control-real-world-devices-with-your-PC/
I'll have a look at commenting the vb code more.

Unit042 says: Oct 4, 2008. 5:33 PM REPLY


Quite an answer! I suppose you get that question a lot.
Now, how does I get squared all of a sudden?

Unit042 says: Oct 4, 2008. 5:37 PM REPLY


Oh, wait...
V=I*R
W=V*I
substitute V's equivalent (I*R) for:
W=(I*R)*I

Now I get it! Oh, my brain, MY BRAIN!!!!

Is it just me, or is thinking harder on Saturdays?

Unit042 says: Oct 5, 2008. 6:36 PM REPLY


Stumbled across a tidbit... some guy uses PHP to control his serial port success fully:
http://www.communitymx.com/content/article.cfm?page=2&cid=8658A

I don't know a lick of PHP, and this application of it makes this language worth taking a look at.
...After looking at the following link, the language looks much more complicated and hard to learn. Maybe I should look up a few books from
my library.
http://en.wikipedia.org/wiki/Php

cpaynebarnes says: Aug 9, 2008. 3:51 AM REPLY


Great info. I am interested in building a differential temperature pump controller for a solar hot water system. Basically it turns on a 1/6 hp pump when the
temp of the solar panels exceeds the temp of the water in a storage tank. Any thoughts?

sunworks says: Oct 5, 2008. 6:10 PM REPLY


Any update or notes / pictures / details you can share on building adifferential temperature pump controller for a solar hot water system?

I've been looking for a long time for instructions on how to do this or get enough help / details where a couple of us can get this accomplished.

Has this project accomplished what you want?


Are you looking at adding features?
What proto board did you use?

Actually, I'd like to start by making a differential control for a hot-air solar system, but understand these are nearly identical apps.

Thanks for any additional info.

Dr_Acula says: Aug 9, 2008. 4:24 AM REPLY


A perfect application for this device. I've even thought of one day building one myself. Use the LM35 temperature sensor. I've had one strapped to the
rubber hose of my car radiator measuring the temperature of the engine, and it has been working for over a year, and it turns on the radiator fan when
over 65C. More reliable than the sensor that came with the car (and the original microcontroller board, which died).

So you will need to sense a few temperatures. Use several LM35s and strap them to the pipes in question. Wrap them up with a few turns of duct tape to
act as insulation. If the 08M runs out of inputs/outputs, there is the 14M chip which costs a few cents more and has 14 pins.

Then drive a BC547 (or 2n2222) via a 2k7 resistor, then switch a relay and use that to turn on a pump. If you need a schematic etc, pls email me
moxhamj@internode.on.net

In a nutshell - it is certainly possible and it is possible with just one chip, a relay, a few temperature sensors and a few resistors/capacitors.

lolcat360 says: Aug 20, 2008. 1:38 PM REPLY


man thats complicated

FreshPineSent says: Sep 24, 2008. 8:54 PM REPLY


I suppose it's hard to solder and such without opposible thumbs.

Esmagamus says: Aug 20, 2008. 8:52 PM REPLY


THAT simple? Shocked...

http://www.instructables.com/id/Control-real-world-devices-with-your-PC/
yedead1 says: Jun 11, 2008. 3:49 PM REPLY
you might be getting the errors because VB/VB.Net was never designed to be with serial based hardware it would probably be better if it was programmed in
either Visual C++ or C# also PIC chips can be programmed in the C language

natalie. says: Jun 30, 2008. 7:52 AM REPLY


thanks (:

natalie. says: Jun 29, 2008. 8:05 PM REPLY


would it be possible if u could provide the programming codes in C#, and hardware codes in C?

Dr_Acula says: Jun 29, 2008. 9:34 PM REPLY


The picaxe hardware is programmed in basic only. However, have a look at Arduino which is programmed in C. The chips are very similar to use. As
for VB.Net, looking at the history of C and VB over the last 25 years, these two progams are slowly merging into the same language within the .net
framework. I am sure this can be done in C, but sorry, I can't program very well in C. I only know basic and machine code.

Dr_Acula says: Jun 11, 2008. 5:06 PM REPLY


Using a protocol of "PC sends data, and picaxe sends response" this has been running for a year sending packets twice a minute with no faults. The
latest versions of VB.net (2005 and 2008 versions) seem much more stable with serial ports. vb.net and the several versions of c.net seem to be evolving
into the same language - lots of structures are quite similar in both languages now. So I'm sure it could be coded in c for free as well.

qz9090 says: Jul 15, 2008. 8:17 AM REPLY


Nice instrucable, easy to read and understand.

I was wondering when you develop an application with VB.net 2005 or 2008, what operating system will the application run on? You don't mention
the hardware or software configuration of you PC.

Thanks.

Dr_Acula says: Aug 1, 2008. 7:10 AM REPLY


PC is 2.4Ghz and application is XP. Any PC running XP will do though and I have this running on machines from 700Mhz to 2.8Ghz.

trendyironicname says: Jan 14, 2008. 2:19 PM REPLY


This is a freaking awesome instructable. I'm running into a problem though. Everytime I try to get past step 12, I hit a snag. I wind up getting 23 build errors
starting with these..
'Sub Main' was not found in 'WindowsApplication1.Form1'.
Type 'IO.Ports.SerialPort' is not defined.
Array declarations cannot specify lower bounds.
Keyword is not valid as an identifier.
Name 'Timer1' is not declared.
.....
I was hoping you could nudge me in the right direction.
Thanks again.

Dr_Acula says: Jan 14, 2008. 5:12 PM REPLY


There are lots of possibities here - we will need to work through them one at a time. Timer1 not being declared suggests that a timer object has not been
pasted on the main form. Sub main is pretty fundamental. Can I just check you are using VB.Net and have pasted all the code? Next step - copy and
paste what code you have into an email and send it too me at moxhamj@internode.on.net If you look over at the right of the screen there are a whole lot
of sub menus that open up as trees - in some of these are further text descriptions of the position of buttons on the screen. If you could copy and paste
the text there as well it would be helpful.

odin84gk says: Oct 24, 2007. 10:34 AM REPLY


Correct me if I am wrong, but normal serial communications are done well outside of the voltage levels of a PIC. To compensate for these voltages (+12Vdc
and -12Vdc), we use a MAX232 to shift serial communications to the 5V required by most PIC and ATmega microcontrollers.
The VB code should be the same, but you will need to do your own PIC code. If you do a little more research, you will find a multitude of projects that can
help you out.

stienman says: Oct 24, 2007. 1:24 PM REPLY


Yes, normal RS-232 communications stipulate a -12 and +12 VDC signalling scheme, with receivers treating 0 and +3 as the sensing levels (due to cable
voltage drop, and to make tricks like this fall within the spec.

So the PIC is fine, as the RS-232 has to send out at least +3 for one signal, and 0 or a negative voltage for the other signal.

The PIC has internal clamp diodes that, as long as the current is low, will short signals that are out of range to the positive or negative supply, so the PIC
is protected, and will still see high and low as necessary.

The TX pin will send +5 and 0, so it will be within spec as well.

http://www.instructables.com/id/Control-real-world-devices-with-your-PC/
The only trick is that RS-232 is inverted - a 1 (high, mark) is -12, while a 0 (low, space) is +12. So the serial handling routine inside the PIC has to invert
the received data.

This trick is really not a great production idea, though, since it doesn't provide adequate ESD and short protection, so the PIC is still pretty exposed to
possible damage while a real RS-232 transceiver will have ESD, short, overcurrent, etc protections, and will drive 'real' RS-232 signals for greater device
compatibility.

For connecting with PCs, though this is usually sufficient.

-Adam

membrane says: Nov 4, 2007. 6:57 PM REPLY


Yah I like to use the max-232 chip for interfacing microcontrollers they're cheap too.

Dr_Acula says: Oct 24, 2007. 3:58 PM REPLY


The 22k and 10k in the configuration shown (which is not a voltage divider though it looks like one at first glance) essentially limits the current such
that the picaxe translates -12 and +12 into values which are detected as 0v/5V low and high. This 22k/10k circuit is a 'poor mans' level translator,
though proper level translators can be used as well. The signal back to the PC exploits the fact that a PC will accept 0V and 5V as valid signal levels.

Incidentally, the 22k/10k circuit also works into other chips as well - eg I have used a series of pairs of HC04 inverters to act as buffers and also to
drive leds to show the signals going back and forth. These leds are sometimes useful for debugging but the main reason I did this is I once zapped a
chip due to having -12V on a protoboard in amongst a rats nest of wires. By all means use level translators if you are building a production version.

stienman says: Oct 25, 2007. 5:20 AM REPLY


Keep in mind also that many RS-232 devices (notoriously laptops) also use these tricks, which means that you may only have 3.3v or 5v coming
in, which may not trigger the PIC input with the given circuit. This is one reason why one might remove the resistor going to ground and instead
depend on the clamping diode.

-Adam

Dr_Acula says: Oct 25, 2007. 5:42 AM REPLY


Agree. A quick test is to get out a multimeter and measure the volts on the output from the PC - should be minus 12V.

membrane says: Nov 4, 2007. 6:54 PM REPLY


I remember doing this a while back using an old TRS-80 M100 and some solid state relays to control some lights.
I now have several pic axes and lots of MSC-51 controllers on hand.

photozz says: Oct 30, 2007. 9:20 AM REPLY


Of course, you can do basic power control with just the LPT port and a SSR. Cost, >$5
http://www.instructables.com/id/Peripheral-Power-control-with-screen-saver/

Dr_Acula says: Oct 30, 2007. 3:23 PM REPLY


I agree and much of my home automation is controlled from an LPT. However, some newer computers don't have a printer port. Also a printer port can't
do analog inputs or fast PWM or servo control. It is easier to zap a printer port with shorts or high voltages, whereas a serial port is fairly robust as it is
designed for +/-12V. There are lots of wires to connect to a parallel port. All in all the serial port probably works out better unless it is a simple on/off sort
of control.

wi-fi astronomer says: Nov 1, 2007. 4:24 PM REPLY


You can get one of those PCI printer fitting cards. Better yet, you can get a card with two printer fittings. With a DOS boot floppy and a QBASIC
programme, you can control solid state relays like the "Halloween controller". I first did something like this in 1993 with a Commodore 64 and its
primative parallel port and a board with transistors doing relays. I even made a terminate and stay resident programme for a Commodore, and could
use the computer AND control Christmas lights.

A new problem now is many computers no longer have serial fittings. Easy, use a USB to serial thing and a BASIC Stamp. Write the firmware, then a
QBASIC programme to send the control signals to the stamp and solid state relays. You run the programme in the background with a minimised
window... or use Linux if you can write serial comms in GNU C. That way, you can surf the web (or this site!) as your automation thing does its thing.

WilderLust says: Oct 31, 2007. 9:24 PM REPLY


Very well done! now you need to do more PIC or AVR instructables!! Great practical information and sources... thank you very much :-)

WL

http://www.instructables.com/id/Control-real-world-devices-with-your-PC/
BiGs says: Oct 27, 2007. 4:42 AM REPLY
Great instructible here. Thought I might tell everyone there is also a product like this comercially available as a kit, with software pre made and programable.
Cheers.
http://www.fusioncontrolcentre.com/

tyeo098 says: Oct 24, 2007. 8:17 AM REPLY


Can a regular pic be turned into a PICAXE with a firmware flash or something?

And i have a couple pics and lots of AVR's...

dmcole says: Oct 24, 2007. 1:08 PM REPLY


Tyeo098:

No, the Rev-Ed people have kept the Picaxe software internals proprietary. But a Picaxe only costs $US3.50, so it's really not that big of a deal.

\dmc

Dr_Acula says: Oct 24, 2007. 4:04 PM REPLY


The picaxe firmware is proprietary but I think it works out less than $1 extra compared with a blank pic. But for that $1 you get free software and an
easy to use language and the chips are only $3.50 each. I've found myself using a picaxe $3.50 instead of a $1 555 simply because it was quicker to
build and more accurate to program. Having designed and built microcontroller boards in the 1980's that cost $300 just in parts and were about as
clever as a picaxe, I have no problem paying Rev Ed their $1.

sira says: Oct 26, 2007. 5:01 AM REPLY


Dear Dr.Acula,
PICAXE devices are truly powerful. You have made available an useful project.
I am much impressed by your work and want to try it out. But when I tried to download the VB.Net at <http://msdn2.microsoft.com/en-
us/express/aa7>
I received a message "its not available" and instead was directed to the link below:
<http://msdn2.microsoft.com/en-us/express/ms123402.aspx>
Would you please give the correct URL for VB.Net (Visual Basic Express)
I am available at <sathkoml@yahoo.com>
Thanks.
Sira.

Dr_Acula says: Oct 26, 2007. 3:46 PM REPLY


The link is http://msdn2.microsoft.com/en-us/express/aa718406.aspx and the link you have above seems to be truncated for some reason.
Anyway if that fails then try searching Google for: visual basic express download

dmcole says: Oct 24, 2007. 4:10 PM REPLY


That's what I was trying to say, but wasn't being nearly so articulate.

sdedalus2000 says: Oct 26, 2007. 10:27 AM REPLY


a good alternative to vb.net express is installing the .net framework sdk and downloading SharpDevelop

thadrien says: Oct 26, 2007. 1:26 AM REPLY


Awesome!

Very useful and well documented.

NPN says: Oct 25, 2007. 5:04 PM REPLY


Thanks, it works!

I made it even simpler (just deleted a bunch of stuff lol)


One text box and one button. Heres the code:

Public Class Form1


Dim WithEvents serialPort As New IO.Ports.SerialPort ' serial port declare
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim LabelString As String = "" ' string to display byte values


Dim DataPacket(0 To 17) As Byte ' entire data packet "Data"+14 bytes
If serialPort.IsOpen Then
serialPort.Close() ' just in case already opened
End If
Try
With serialPort
.PortName = "COM1" ' Most new computers default to com1 but any pre 1999 computer with a serial mouse will probably default to com2
.BaudRate = 2400 ' 2400 is the maxiumum speed for small picaxes
http://www.instructables.com/id/Control-real-world-devices-with-your-PC/
.Parity = IO.Ports.Parity.None ' no parity
.DataBits = 8 ' 8 bits
.StopBits = IO.Ports.StopBits.One ' one stop bit
.ReadTimeout = 1000 ' milliseconds so times out in 1 second if no response
.Open() ' open the serial port
.DiscardInBuffer() ' clear the input buffer
.Write(TextBox1.Text) ' send the datapacket array
.Read(DataPacket, 0, 18) ' read back in the data packet array
.Close() ' close the serial port
End With
Catch ex As Exception
End Try
End Sub
End Class

Dr_Acula says: Oct 25, 2007. 5:48 PM REPLY


You can also delete the .Read as well if you are only writing. Then it won't wait 1 second for the timeout to happen and will run faster.

NPN says: Oct 25, 2007. 11:39 AM REPLY


I'm just starting to learn VB, and I was wondering if you could give a simple example of serial communication.
Example:
One button and one text box, when you click the button it sends out what ever is in the text box.
Thank you :-)

Dr_Acula says: Oct 25, 2007. 4:48 PM REPLY


Ok, use the code that is already there and add your text box eg textbox1
In the serial TxRx subroutine is a line .Write(DataPacket, 0, 18)
Change this to .write(textbox1.text)
Delete the sleep and the .read underneath as we are not reading anything back
Add a new button - on this program there are already two buttons so it will be called button3. Double click on that button and in the subroutine that will be
created add call serialtxrx()
The only catch is this will only send ascii text. It won't send binary numbers with ascii values from 127 to 255. These characters won't display properly in
a textbox anyway. Use a byte array to send bytes. But this should work fine for sending "Hello world"

Mexicoman says: Oct 25, 2007. 3:51 PM REPLY


Thanks, One of the nicest and most completely commented instructables. It has hit my --save-- file. Good show! Appreciado mucho

v With stupid v says: Oct 23, 2007. 7:48 AM REPLY


This is so useful, just what I've been looking for.
Can't wait to experiment, until then I’ve got to study for exams.

Thanks!

whatsisface says: Oct 23, 2007. 4:37 AM REPLY


This is great, I know how to program PIC's but I never learn how to build the VB form for it. Thanks!

http://www.instructables.com/id/Control-real-world-devices-with-your-PC/

You might also like