Introduction: Valentine Robot Dispenses Candy Kisses Using Picaxe

About: Retired Math teacher who needs a hobby! So I tinker with stuff: Arduino, welding, my 1958 TR-3 , my tennis serve
I had a Picaxe  18m2 project board and wanted to learn more about this microprocessor.  So I created this robot which is programmed to drop candy kisses , stored in a Valentine candy box ,  in  the pattern of a valentine heart.  


Below is a video of it working with the cover on the candy box off so as to better see the candy movement.   I still need to do some tweeking of the code to get a better looking heart but it is not too bad now




Also follows a better video showing the servos processing the candy.

Step 1: Get Stuff

The components I used are:

- Picaxe  18M2 Project board - from Sparkfun - about 23.00
- 2 motors wheel combination -  GM2 motor with wheel - Solarbotics sells for about 10.00 for each wheel/.motor
- a swivel castor wheel from Home Depot - 2.00
- a piece of 8 inch shelf board for the platform - 
- 2 servos - Hextronic - Hxt900 - I had but I would say they cost about 5.00 each  
- a box of Valentine Candy - 10.00
- a SN75441 motor control IC - I had but about 2.00
- misc wires . PCB, small pieces of scrap wood , hot glue, headers , zip ties
- 7 double A batteries 
- a DPDT switch - Radio Shack
- battery holders - from Radio Shack 
- most importantly - a bag of Hersey Candy Kisses.



Step 2: Create the Platform

I cut a 12 inch piece of 8 inch shelf board. Then cut the sides as shown . Each corner of the triangle shape is about 2 inches long.

Step 3: Prepare the Motors and Attach to the Platform - Also Attach the Swivel Castor

I soldered small lenghts of wire to the terminals on each motor and the used wire ties to attach to each front corner. 

The smallest castor that I could fine was this one at Home Depot - it is 1 3/4 inches square.

Step 4: Prepare the Candy Box and Mount to the Platform

The arrangement of wood p[pieces and the placement of the servos was arrived at after a great deal of trial and error. Several other arrangements were tried but this is what I ended up with.  It works pretty good but it does mess up once in awhile 

A big problem was keeping the candies from jamming up in the box.  Placing them in the box in single file solved this largely. And a great deal of code work was done to get the servos to be open long enough but not too long.  

Hot glue was used to hold everything in place 

I am sure there are better designs 


The video in step one shows the candy being processed.   The code for the servos follows.

Step 5: Add the Picaxe and the Motor Controller

I wanted this project to help me learn more about the Picaxe and motor controllers  

So a lot of the code(especially for the motor controller)  is from examples found at the LMR site  http://letsmakerobots.com/  and various Instructables and other google searches.


To make wire connections easier, I soldered headers to the project board and to the PCB where I installed the SN7441 chip.



Step 6: The Connections and Power Sources

Here is what I did but not necessarily the best idea because I am pretty new to this stuff.

- I used two power sources.  the 4.5 volts powers the Picaxe and the 6.0 volts  powers the motors(2 servos and 2 wheels) .  This done by attaching the the red and black wires from the battery holder to the appropriate inputs on the Picaxe board.  The Picaxe documentation says the resistor must be cut if using separate power sources(see photo).


For each motor/servo there is a power and ground wire .S each pair is attached to the project board to the output pins that are used in the code.  The control wires still need to be attached to the Picaxe pins.  

The Picaxe site has pdf for the manuals . Manual number 3 has a good description of how to hook up servos and motor controllers.


I am only controlling on of the motors thru the SN75441 as I find I can control the robot pretty well that way.    

The motor controller chip allows for speed control and forward reverse command.  So I can do that with one motor. the other is just on or off.   This works for me as the robot only makes left hand turns.  A great deal more control would be had if I controlled both motors thru the SN75441. 

Step 7: The Code

The Picaxe code I used is follows with comments thru out


v1 - 2/18 attempt to put all the code together
init:
servo 7,91
servo 5,50
high b.2

main: ' the main loop
'drive forward short distance with no drop'

' drive forward and drop 3 pieces of candy
do
gosub straight
inc b2
loop while b2 <3
' left turn and drop 4 candy
' and then continue with turn for one cycle without dropping candy
do
gosub firstleftturn
inc b3
loop while b3 <5

'do
' gosub leftturnnocandy
' inc b12
'loop while b12 < 1


' now at middle
' figure this out later
gosub nopower
' turn it around
gosub turnaround


gosub nopower

'  left turn and drop 5 candy
do
gosub secondleftturn
inc b4
loop while b4 <4

' drive forward and drop 3 pieces of candy
do
gosub laststraight
inc b5
loop while b5<5

' turn wide
gosub lastleftturn
'
gosub nopower

  stop

goto main ' this ends the loop, the rest are only sub-routines



' subroutines
' --------------------------------------------
straight:
' one motor is on all the time
high B.1
' other is 100% during straight
' pwmout B.3, 99, 400 :low 4
PWMOUT B.3, OFF
high b.3 :low b.4
' go forwaed 1 secs and then drop candy
pause 2000
gosub dropcandy
return


laststraight:
' one motor is on all the time
high B.1
' other is 100% during straight
' pwmout B.3, 99, 400 :low 4
PWMOUT B.3, OFF
high b.3 :low b.4
' go forwaed 1 secs and then drop candy
pause 2000
gosub dropcandy
return


straightnocandy:
' one motor is on all the time
high B.1
' other is 100% during straight
PWMOUT B.3, OFF
high b.3 :low b.4
'pwmout B.3, 99, 400 :low 4
' go forwaed 
pause 460

return



firstleftturn:
' one motor is on all the time
high B.1
  ' 50 %
'pwmout B.3, 99, 200 :low 4
' 70%
pwmout B.3, 99, 280 : low 4
pause 2500
gosub dropcandy
return

secondleftturn:
' one motor is on all the time
high B.1
  ' 50 %
'pwmout B.3, 99, 200 :low 4
' 75
pwmout B.3, 99, 245 : low 4
pause 1775
gosub dropcandy
return

leftturnnocandy:
' one motor is on all the time
high B.1
  ' 50 %
'pwmout B.3, 99, 200 :low 4
' 70%
pwmout B.3, 99, 280 : low 4
pause 2500

return


dropcandy:
' first stop all
' turn off pwm
PWMOUT B.3, OFF
low B.1 : low B.3 : low B.4
pause 500
' open the shute gate and allow one to drop
servo 5, 93
pause 260
' close gate
servo 5, 60
' candy drops
pause 500
' move insides
'open
servo 7,50
pause 350
'closed
servo 7,91
pause 1000
return


nopower:
PWMOUT B.3, OFF
low B.1 : low B.3 : low B.4
pause 1000
return

turnaround:
PWMOUT B.3, OFF
high B.1 : low B.3 : low B.4
pause 12950

do
gosub straightnocandy
inc b11
loop while b11 < 6
return


lastleftturn:
' one motor is on all the time
high B.1

'70%
pwmout B.3, 99, 310
pause  10000

return

Valentine's Day Contest

Participated in the
Valentine's Day Contest