Post on 24-Apr-2015
Build Your Own Simple and Easy PICAXE Microcontroller Based Photovore Robot
Building a simple and easy microcontroller based robot is always a fascinating topic to be discussed,
especially for the robotics newbie enthusiast. On this tutorial I will show you how to build your own
microcontroller based robot which known as a photovore or you could call it as the light chaser robot
using the simplest possible circuit for the microcontroller based robot brain, locomotion motor and the
sensor.
One of the most frustrating parts when building your first microcontroller based robot is to program it
and to download it into the microcontroller flash ram. On this tutorial this kind of “trouble maker” is
being reduced as we will use the PICAXE programming editor from the Revolution Education Ltd
(http://www.rev-ed.co.uk/picaxe) as our Integrated Development Environment (IDE) to program our
robot brain using the BASIC (Beginners All Purpose Symbolic Instruction Code) language and to
download the program into the PICAXE 28X1 microcontroller.
The PICAXE 28X1 microcontrollers actually is based on the popular Microchip 8-bit 28 pins PIC16F886
microcontroller that have a preload PICAXE BASIC interpreter firmware inside, in fact when you buy it
its looks the same as the usual Microchip PIC16F886 microcontroller. Together with the free PICAXE
Programming Editor and simple serial cable connector for the program downloader makes this PICAXE
framework suitable for beginners and even for the professional.
You could read more information about the PICAXE microcontroller on my previous posted blog
“Introduction to the Embedded system with PICAXE Microcontroller“.
On this tutorial I will refer this photovore robot as the BRAM-AXE as this is a simplify version of the
more advanced version of its big brother BRAM (Beginners Robot Autonomous Mobile) which you could
read more information about it on my previous posted blog “Building BRAM your first Autonomous
Mobile Robot using Microchip PIC Microcontroller – Part 1” and “Behavior Based Artificial Intelligent
Mobile Robot with Sharp GP2D120 Distance Measuring Sensor – BRAM Part 2“.
The BRAM-AXE robot simply use its light sensitive sensor to navigate to the light source, when it being
placed in the dark environment it will automatically switch to the light search mode and try to find the
light source, when it encounter the light source it will navigate to the light source and when the light
source intensity is bright enough it will stop and enjoying the light. You could see all this behavior on
the video at the end of this tutorial. Ok now let’s list down all the electronics parts, robot chassis
materials and software needed to build this interesting robot.
BRAM-AXE board: based on the PICAXE 28X1 microcontrollers together with the PICAXE serial
downloader cable which you could easily build from my previous posted blog “Make your own
Microcontroller Printed Circuit Board (PCB) using the Toner Transfer Method“.
Two LDR and Two 1K Ohm 0.25 watt resistor
Two Continues Servo (on this tutorial I use the Parallax Continues Servo)
Two toys tire to be attached to the servo’s arms
Enough cables and Tubing (1mm and 3mm)
3 x AA battery holder with 3 x AA alkaline battery
1 CD or DVD
A good double tape or epoxy glue for the permanent robot
One paper clips and neck less beads for the robot caster (the robot’s third wheel)
Enough bolts and nuts for the caster
PICAXE Programming Editor from Revolution Education Ltd which you could download from
their website
The BRAM-AXE Chassis Assembly
The BRAM-AXE main chassis is made from the CD/DVD which you could find easily at home or just use
the blank one as I did if you don’t have any discarding CD/DVD at home. For the wheel you could use
any toy’s wheel or you could use anything that has a circle form as long as the diameter is greater or
equal to the servo’s arms.
The assembly of BRAM-AXE chassis is straight forward; you just need to drill two holes for placing the
caster. Attached the two continues servo on the button of the CD/DVD with the double tapes and
attached the wheel to the servo’s arms with the double tape or you could use the epoxy for permanent
one. You could see the whole process on these following pictures:
Now attached the 3 x AA battery holder and BRAM-AXE board on top of the CD; again using our flexible
friend the double tape as shown on these following pictures.
Connect the power socket to the BRAM-AXE polarized power pin and the servo’s socket to the BRAM-
AXE board output 0 and output 1 three pins socket respectively as shown on this following servo’s
circuit diagram.
The BRAM-AXE board output pins is design to be attached directly with the servo, every output pins
provide both power and ground needed to power the servo. Connect the left servo connector to the
BRAM-AXE output 0 and the right servo connector to the BRAM-AXE output 1. After finishing all this
steps now it’s the time to test the robot steering mechanism.
The BRAM-AXE Steering Method
The BRAM-AXE steering use the simple method called the “differential drive“; when the two servos
rotate on the same direction the robot will move forward or backward, and when they rotate on
different direction (counter rotation to each other) the robot will rotate to left or right.
Servo basically is a high quality geared DC motor with electronic circuit for controlling the DC motor
rotation direction and position; its being used widely in model hobbyist such as car R/C model for
steering and acceleration control or airplane R/C model for moving the rudder, ailerons, elevators and
acceleration control. Typically there are two type of servo available on the market the first one is
“standard” servo which could rotate between 120 to 180 degree and the second one is “continues”
servo which could rotate 360 degree.
By using the continues servo, the locomotion circuit become very simple as we only connect the servo
directly to the BRAM-AXE board and supply the correct PWM (Pulse Width Modulation) signal in order to
make it rotate. The PICAXE BASIC language has a build in servo commands that we could use to make
the servo rotate.servo output_pin, nservopos output_pin, n
The servo command will initial the PICAXE 28X1 (Microchip PIC16F886) internal TIMER which is used to
generate the PWM signal to the servo and after initialization you have to use the servopos command
in order to control the servo. The n is the number between 75 and 255, where this number will
determine the servo rotation direction (clock wise or counter clock wise). The output_pin is the
PICAXE 28X1 output pin which range from 0 to 7.
Now connect the serial programming cable from the BRAM-AXE board to your computer COM/RS232
port or you could use the USB to RS232 adapter as I did and download this following servo testing
program using the PICAXE Programming Editor:'***************************************************************************' File Name : bram-axe_servo_test.bas' Version : 1.0' Description : BRAM-AXE Photovore Servo Testing' Author : RWB' Target : BRAM-AXE Learning Board - PICAXE 28x1' Intepreter : PICAXE Firmware version A.6' IDE : PICAXE Programming Editor Version 5.2.6' Programmer : PICAXE Programming Editor Version 5.2.6' Last Updated : 03 January 2010'***************************************************************************' Use PICAXE 28x1 with 4 MHz Internal Clock#picaxe 28x1SetFreq m4' Assigned Variablessymbol cnt_val = b0symbol move_mode = b1let pins = %00000000 ' Reset all the Output Pins' Initial the Servogosub BRAM_ServoInitmove_mode=1cnt_val=1main: select move_mode case 1 gosub BRAM_MoveForward case 2
gosub BRAM_MoveBackward case 3 gosub BRAM_RotateRight case 4 gosub BRAM_RotateLeft case 5 gosub BRAM_Stop case 6 gosub BRAM_ServoInit end select
pause 10 ' Pause 10 Second cnt_val=cnt_val + 1 if cnt_val > 150 then move_mode=move_mode + 1 if move_mode > 6 then move_mode=1 endif cnt_val=1 endif
goto main ' Back to main loop end' BRAM Steering SubroutinesBRAM_ServoInit: servo 0,125 ' Left Servo servo 1,200 ' Right ServoreturnBRAM_MoveForward: servopos 0,125 ' Left Servo Forward servopos 1,200 ' Right Servo BackwardreturnBRAM_MoveBackward: servopos 0,200 ' Left Servo Backward servopos 1,125 ' Right Servo ForwardreturnBRAM_RotateRight: servopos 0,125 ' Left Servo Forward servopos 1,125 ' Right Servo ForwardreturnBRAM_RotateLeft: servopos 0,200 ' Left Servo Backward servopos 1,200 ' Right Servo BackwardreturnBRAM_Stop: settimer off ' TIMER Offreturn' EOF: bram-axe_servo_test.bas
Usually the servo is designed to have a wide tolerance on the incoming PWM signal, but if your servo
doesn’t work with the above value (125 and 200) try to experiment with other value as long as the
value range is between 75 and 255. For more information about controlling the servo you could read
my previous posted blog “Basic Servo Motor Controlling with Microchip PIC Microcontroller“.
The BRAM-AXE Sensors
In order to make the complete photovore robot, we need to use the light sensitive sensor; the simple
and cheapest one is to use a special made resistor (made from Cadmium Sulfide) called Light
Dependent Resistor or LDR for short. The LDR will vary its resistance according to the light intensity
fall on its surface; the bright light intensity will make its resistance decrease significantly (about 1K
Ohm to 5 K Ohm) while on the completely dark its resistance will increase as high as 100 K Ohm.
By connecting the LDR in series with 1 K Ohm resistor, we could get the simplest possible light sensor
circuit that will give us the variable voltage output according to the light intensity as shown on this
following picture.
This simple circuit is known as the voltage divider circuit, you could read more information about the
voltage divider circuit on my previous posted blog “Basic Resistor Circuit“.
Connect the sensor circuit output directly to the PICAXE 28X1 microcontroller analog to digital
conversion (ADC) input port (ADC 0 and ADC 1) and use the power taken from the BRAM-AXE board
output pin as shown on these following pictures:
With the PICAXE ADC feature, now we could easily read the numeric representation of the light
intensity on each sensor (left LDR and right LDR) using this following PICAXE BASIC commands:readadc adc_channel, variable
The readadc command will read the ADC input port (0 to 3 on PICAXE 28X1 microcontroller) and
assigned the 8-bit data value to the variable. By examining the ADC value we could command our
robot to follow the light as shown on this following BRAM-AXE_photovore.bas program:'***************************************************************************' File Name : bram-axe_photovore.bas' Version : 1.0' Description : BRAM-AXE Photovore' Author : RWB' Target : BRAM-AXE Learning Board - PICAXE 28x1' Intepreter : PICAXE Firmware version A.6' IDE : PICAXE Programming Editor Version 5.2.6' Programmer : PICAXE Programming Editor Version 5.2.6' Last Updated : 03 January 2010'***************************************************************************' Use PICAXE 28x1 with 4 Mhz Internal Clock#picaxe 28x1SetFreq m4' Assigned Variablesymbol ldr_left = b0symbol ldr_right = b1symbol diff_value = b2symbol mode = b3symbol cnt = b4symbol stop_stat = b5let pins = %00000000 ' Reset all Output Pins' Initial variable usedmode=0cnt=0stop_stat=0main: ' Read the LDR ADC Value readadc 0,ldr_left readadc 1,ldr_right ' For Debugging the ADC Value ' sertxd("LDR Left: ",#ldr_left,13,10)
' sertxd("LDR Right: ",#ldr_right,13,10) ' pause 100
' Searching Mode if both LDR less or equal to 5 if ldr_left <= 5 and ldr_right <= 5 then cnt=cnt + 1 if cnt > 80 then cnt=0 mode=mode + 1 if mode > 5 then mode = 0 endif endif
select mode case 1 gosub BRAM_Stop case 2 gosub BRAM_RotateRight case 3 gosub BRAM_MoveBackward case 4 gosub BRAM_RotateLeft case 5 gosub BRAM_MoveForward end select
pause 10 goto main endif ' STOP both LDR greater or equal to 90 if ldr_left >= 90 and ldr_right >= 90 then gosub BRAM_Stop pause 10 goto main endif
' BRAM-AXE Bang-Bang steer control if ldr_left > ldr_right then diffvalue=ldr_left - ldr_right if diff_value >= 20 then gosub BRAM_RotateRight else gosub BRAM_MoveForward endif endif
if ldr_right > ldr_left then diffvalue=ldr_right - ldr_left if diff_value >= 20 then gosub BRAM_RotateLeft else gosub BRAM_MoveForward endif endif
pause 10 ' Pause 10 seconds
goto main ' Back to main loop end' BRAM Steering SubroutinesBRAM_MoveForward: if stop_stat = 1 then
servo 0,125 ' Init Left Servo Forward servo 1,200 ' Init Right Servo Backward stop_stat=0 else servopos 0,125 ' Left Servo Forward servopos 1,200 ' Right Servo Backward endifreturnBRAM_MoveBackward: if stop_stat = 1 then servo 0,200 ' Init Left Servo Backward servo 1,125 ' Init Right Servo Forward stop_stat=0 else servopos 0,200 ' Left Servo Backward servopos 1,125 ' Right Servo Forward endifreturnBRAM_RotateRight: if stop_stat = 1 then servo 0,125 ' Init Left Servo Forward servo 1,125 ' Init Right Servo Forward stop_stat=0 else servopos 0,125 ' Left Servo Forward servopos 1,125 ' Right Servo Forward endifreturnBRAM_RotateLeft: if stop_stat = 1 then servo 0,200 ' Init Left Servo Backward servo 1,200 ' Init Right Servo Backward stop_stat=0 else servopos 0,200 ' Left Servo Backward servopos 1,200 ' Right Servo Backward endifreturnBRAM_Stop: stop_stat=1 settimer offreturn' EOF: bram-axe_photovore.bas
The key for this photovore program to work properly is to place the two LDR sensors about 45 degree
from the center of the robot chassis as shown on these following pictures:
When the two LDR sensors get an equal light intensity than we command the BRAM-AXE to move
forward, when the light intensity is bright enough than we make it stop as shown on this PICAXE BASIC
code:' STOP both LDR greater or equal to 90if ldr_left >= 90 and ldr_right >= 90 then gosub BRAM_Stop pause 10 goto mainendif
When one of the LDR sensors is brighter then the other than we command the BRAM-AXE to rotate
right or rotate left:' BRAM-AXE Bang-Bang steer controlif ldr_left > ldr_right then diffvalue=ldr_left - ldr_right if diff_value >= 20 then gosub BRAM_RotateRight else gosub BRAM_MoveForward endifendif
if ldr_right > ldr_left then diffvalue=ldr_right - ldr_left if diff_value >= 20 then gosub BRAM_RotateLeft else gosub BRAM_MoveForward endifendif
When both LDR sensors is quite dark than we command the BRAM-AXE to enter the light search mode,
this light search program algorithm will keep the BRAM-AXE to move forward, backward, rotate left and
right until it locate the light source.
The BRAM-AXE photovore program algorithm use the simplest steering method control called the
bang-bang control or on/off control which is the simplest closed loops control method usually used in
the embedded system. For more information about the bang-bang control method you could read my
previous posted blog “Basic Servo Motor Controlling with Microchip PIC Microcontroller“.
You could adjust all the bang-bang control numeric values to suite your need, in order to do that you
have to know the ADC value before making your adjustment. This could be done by opening the
commented PICAXE BASIC serial data transmit and pause command on these following lines:' For Debugging the ADC Valuesertxd("LDR Left: ",#ldr_left,13,10)sertxd("LDR Right: ",#ldr_right,13,10)pause 100
You could display these value directly to the PICAXE Programming Editor build in serial terminal, which
you could access from menu PICAXE -> Terminal or you could press the F8 key, re-down load the
code again to run this monitor. Do not disconnect the serial programmer cable from the BRAM-AXE
board as the PICAXE BASIC sertxd command use this serial connection to transmit the data and make
sure you set the baud rate to 4800 as shown on this following picture: