Picture of 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

Picture of 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.
1-40 of 103Next »
bro123453 years ago
Will this work with a PICAXE 28x1 chip and using Visual Basic 2010?
1st of all:
thanks for this interesting tutorial !

unfortunately (on this tutorial's behalf)
i am a macintosh user ....
i managed to rebuild the visual basic part via word
(via "tool/macro/visual basic editor")
receive the message "invalid outside procedure"
when running the script.

dioes anyone know how to translate
the visual basic part into "mac-able" code
use an alternative way to handle the
internet connection?
3dotter5 years ago
Why is no rs232 level converter necessary here?
Almost all computers now support TTL. The adapter sold by rev-ed does as far as I'm aware.
tanntraad4 years ago
Hi! Great info here! I wonder if you know the answer to my question; How do you avoid a common source when using multiple mosfet's on a picaxe? We have a good discussion here down in the comments; http://www.instructables.com/id/Make-a-remote-controlled-camera-from-a-cellphone!/

The problem is interfacing them with a matrix..
Any help is welcome :)

Thanks for the info Dr_Acula. I'm looking at the mosfet control circuit at the end of the article - am I correct in assuming that you need NO other components to drive a mosfet? I'm working on a picaxe-based home-brew heater and need to switch a 2A resistive heater at 12V. I'm not doing anything fancy like PWM control, just a simple thermostat. Thanks for your help! Nick
Yes, no extra components required for a mosfet, but you do need to pick the right mosfet. You need one with a gate drive of 5V. Some need 10V and will partially turn on at 5V but get very hot. The picaxe manual has some more "up to date" ones than the BUK555. I do kind of like the BUK555 though - it can switch a car headlamp 60W and only get slightly warm.
Wow, thanks for the really quick reply! I'm guessing that's the "gate threshold voltage" in the datasheets? I'm looking at the BUZ-71 from Jaycar at http://www.jaycar.com.au/products_uploaded/BUZ71.pdf This has a gate threshold voltage of 2.1 to 4V, which sounds like it'll be just right for a picaxe driven from a 7805 regulator. The picaxe manual suggests an IRF530 but none of the big .au retailers seem to carry this part. Thanks, Nick
That looks ok - give it a try.
stevehutton5 years ago
Hi this looks really useful stuff. I'm trying to control a cdrom stepper motor using a L293 d driver and picaxe. i've downloaded some code that includes "sending a serial input to input 0 (pin 17) in the form of three bytes: The first is a qualifier – 85 uniquely identifies this stepper motor – the second is the number of steps – 0-255, and the third is the speed – 0-127 is backwards, 128-255 is forwards". Can you tell me how to use the serout command to do this please. Thanks loads
Where is the code going from and to? If it is from the PC to the picaxe then to the stepper motor, then it will be Serin on the picaxe. The syntax will be very similar to that posted here, but I just want to check first where the data is going from and where to.
Thanks for early reply James. All the code will sit in a picaxe 28 and outputs will be sent to the L293D. Here’s the full comment attached to the code I’ve downloaded ( and successfully loaded): “Note that this program is designed to wait until it detects a serial input on input 0 (pin 17) in the form of three bytes: The first is a qualifier – 85 uniquely identifies this stepper motor – the second is the number of steps – 0-255, and the third is the speed – 0-127 is backwards, 128-255 is forwards” So it seems straightforward(ish) I have one pin say pinX that sends this output (presumably as a serout command) to pin 17 and another pin say pin y that tells pin x when to send that command (i.e when it goes high) . Its just that the forums and picaxe manual I’ve looked out seem to assume I know what the syntax and overall meaning of the instructions is all about. The code comes from this page; http://dmt195.wordpress.com./ Thanks again for helping. Steve
Take a look at step 5 - for serin the bracket goes round the "data" and then the variables are outside the bracked. But for serout the bracket goes round the whole set of variables. Just one of those programming quirks I guess.
Sounds a pretty standard picaxe circuit. The picaxe forum has got rather prickly lately. You don't need a flameproof suit but you might need a flame retardant one. Serin and serout need the commas and the quotes in the right place.
ThomasH955 years ago
BTW is there any simular mosfets to the BUK555 because you can't get them here in the UK.
Dr_Acula (author)  ThomasH955 years ago
Looking at the picaxe circuits, they use the IRF530 and picaxe is from the UK so see if that one is available?

69p from Radio Spares. Threshold voltage for the gate of about 3V. http://docs-europe.origin.electrocomponents.com/webdocs/0791/0900766b807910f8.pdf   Looks like an even better substitute as it is much cheaper than the BUK555.
ThomasH955 years ago
Is there any way of separating out the pot readings from the line and put it in a seprate label by itself ?
p.s.Great project !!!!!!!
bigchicken5 years ago

current squared x resistance = volts x amps

 - Because volts = amps x resistance.
Therefore watts = amps x resistance x amps
                             = amps squared x resistance

reaver265 years ago
hello, can i integrate it on mplab IDE compiler? using your codes?
sciguy775 years ago
 Um, blue arrow? Where?
Dr_Acula (author)  sciguy775 years ago
Yes, the latest version of the picaxe software has changed the screen layout. There is still a download button but the screen looks different. Or select download from the program menus. 
3dotter5 years ago
Hi Dr_Acula (Shark in Russian?), I am new to Picaxe. I like to start a GSM modem (old, but very good Siemens M20 terminal) with a mosfet when the PICAXE senses that a magnetic reed switch has been activated. Then the PICAXE should give Hayes AT commands over the serial line to the modem (through a MAX232 level converter) to 1. register the modem on the GSM network, 2. to give the right SIM card's PIN code and 3. finally to start a phone call to 3 phone numbers listed on the number 1 - 3 positions of the SIM card's phonebook. Such AT command is simple: AT>n, where n is the position of the phone number in this phonebook. Please help me with setting up this PICAXE code. Thanks in advance!
Dr_Acula (author)  3dotter5 years ago
I don't know anything about AT commands. But the picaxe can certainly send simple strings of serial data with the SEROUT command. Baud rate up to 2400 baud. If you can supply the serial strings you want, I can translate that into SEROUT code that the picaxe uses.
Great! Thanks.

Here they are. In front of the relevant AT commands I have typed here serout -> or serin -> to show you what goes out and comes in as answer from the modem

serout -> AT+CREG=2
serin -> OK
serout -> AT+CREG?
serin-> +CREG: 2,0

serout ->AT+CPIN=2004
serin -> OK

serin -> +CREG: 2

serin -> +CREG: 5

serin -> +CREG: 5,"11BA","2F00"

Above were relevant AT commands to register the modem to the GSM network. Below are 2 types of sending an alarm phone call:

1. with number:

serout -> ATD 0592170185
serin -> NO CARRIER

2. with number from first postion of SIM's phonebook:

serout -> ATD>1
serin -> NO CARRIER

The 'NO CARRIER' is good here, because it shows that the person who was called did not pick up the phone.
Dr_Acula (author)  3dotter5 years ago
Well, for serout you need either True or Inverted polarity. If you are driving a max232 for proper RS232 output (ie idle is minus 12V and active is +12V) then use T polarity. Then choose a picaxe pin. Let's say pin 1. And a baud rate, say 1200.

serout 1,T1200,("AT+CREG=2")
serin 1, T1200,("OK")
serout 1,T1200,("AT+CREG?")

Only catch is that the exact data has to be received by serin. If it isn't the expected bytes, then it just hangs till the right bytes come through. Unless you use one of the newer picaxes (20x2) that have a timeout on serin.

and to read in,
Hi Dr_Acula, Few more questions. To which pins of the PICAXE can the serin and serout commands be given? Is there a need to use the same pins which are used for programming the picaxe or not? Can I show to you my eagle PCB design files for review? That would be great. :)
Dr_Acula (author)  3dotter5 years ago
You can choose any pins for serin or serout. The only exception is some pins on the smaller picaxes, like the 08M, where ones like pin 3 are input only. Yes, send me any eagle files moxhamj at internode.on.net
Thanks! That is very helpful :)
pjason6 years ago
does anyone know how to interface this thing with matlab?
vincent hua6 years ago
You can send the pot status to Twitter by adding this vb.net function(see below). Just call this function and key in your username, password and your wanted message. (Message = Pot Status)

I have no idea how to use Twitter to send output to PICAXE yet...

Public Sub PostonTwitter(ByVal userName As String, ByVal password As String, ByVal updateMessage As String)
Dim wc As Net.WebClient = New Net.WebClient()
wc.Credentials = New Net.NetworkCredential(userName, password)
Net.ServicePointManager.Expect100Continue = False
Dim updateMessageBytes As Byte() = System.Text.Encoding.UTF8.GetBytes("status=" + updateMessage)
'Use UTF8 to get it properly encoded if you use characters like ç ã etc...
wc.UploadData("http://twitter.com/statuses/update.xml", updateMessageBytes)
End Sub
wee_man6 years ago
Hi every1 and Dr Aucla i am going to write up a way to this this but insteed of using windows it will be for linux.
wee_man6 years ago
hi everyone i recently posted a instructable on how to program a picaxe automaticly from a bas file on an ftp server heres a link if your interested
wee_man6 years ago
ok im having problems i have the chip its all on but it just keeps timing out. i stright copy and pasted both codes i don't have anything to give the pixaxe a reading like a pot but im sure that shouldnt matter. how i have it set up is that i've put leads into the proto broad pin soctets to bring it all onto my bread board. please help me
Dr_Acula (author)  wee_man6 years ago
If it doesn't work, break it down into component parts and test each part. First little test, can you program a picaxe to flash a led?
Ohh i should of included this in the first post yea i got it to blink i auctlly made it blink 3 legs in a squence.
Dr_Acula (author)  wee_man6 years ago
Ok, the tricky bit is programming the picaxe then changing the circuit as per step 6. Essentially, the wire that went to physical leg 2 now goes to physical leg 4. But first, a very simple program main:serin 3,N2400,("Data"),b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13 high 1 pause 100 low 1 serout 0,N2400,("Data", b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13) goto main Try downloading this. You will need the circuit as per step 3. Put a led on physical pin 6 (pin1 in code). Now reconfigure as per step 6, ie you are now talking to the chip. Send it a packet and see if the led flashes.
ok i will try this later but i think this is the smoking gun p.s have to go down and get some resistors then.
wee_man wee_man6 years ago
hey thanks it worked. This is how i have it setup just for anyone who wants to know i have a devlopment/proto board i don't wanna solder on it so i put breadboard jumper leads into the slots of the proto board were the pic pins would normally go then i trafer them onto the breadboard. so i can save the proto broad for a more periment thing
Dr_Acula (author)  wee_man6 years ago
Great! I see on this reply panel there is a "add images" option. If you could take a photo of your setup that would be fantastic.
Hahah sorry for taking so long to respond the curcuit stoped working reread the instructable. I noticed that when the cucuit is used as a serial interface make sure that physical leg 2 is grounded or else it won't work as wanted here is the pics of my setup. I took away the unneeded wires just to show how the serial connects and its its not the best quatly but just a proof of concecpt you dont need to add any resisitors to the serial line as their imbedded in the photo board. If anyone has questions to this i will be glad to answer i got the stuff from surpluseletronics in new zealand i got the photoboard(with microcontroller) but without the software) , another micro a big jumper lead package 10x led all for $35. A word of advise if you are buying a phroto board ask if you can get a discount if they don't include the software cd. i got $13.30 off the price and funny thing is the software is a free download off the internet. (yea my spelling sucks)
1-40 of 103Next »