Page 156 - Robots Androids and Animatrons : 12 Incredible Projects You Can Build
P. 156

Diodes
                                       Because the PIC is sensitive to electrical spikes (may cause a reset
                                       or lock-up), we place diodes across the collector-emitter junction
                                       of each transistor (Q1 to Q4). These diodes snub any electrical
                                       spikes caused by switching the motor windings on and off.
                                       The PICBASIC compiler program is as follows:
                                       ‘Fuzzy Logic Light Tracker Program
                                       start:
                                       low 0   ‘Pin 0 low
                                       low 1   ‘Pin 1 low
                                       pot 2,255,b0  ‘Read first CdS sensor
                                       pot 3,255,b1  ‘Read second CdS sensor
                                       if b0   b1 then start  ‘If equal, do nothing
                                       if b0 > b1 then greater  ‘If greater, check how much greater
                                       if b0 < b1 then lesser  ‘If lesser, check how much lesser
                                       greater:   ‘Greater routine
                                       b2 = b0 — b1  ‘Find the difference
                                       if b2 > 10 then cw  ‘Is it within range? If not, go to CW
                                       goto start  ‘In range, do again
                                       lesser:   ‘Lesser routine                                          135
                                       b2 = b1 — b0  ‘Find the difference
                                       if b2 > 10 then ccw  ‘Is it within range? If not, go to CCW
                                       goto start  ‘Do again
                                       cw:   ‘Turn the sensor array CW
                                       high 0   ‘Turn on H-bridge
                                       pause 100   ‘Let it turn for a moment
                                       goto start  ‘Check again
                                       ccw:   ‘Turn the sensor array CCW
                                       high 1   ‘Turn on H-bridge
                                       pause 100   ‘Let it turn a moment
                                       goto start  ‘Check again
                                       Operation
                                       When running, the light tracker will follow a light source. If both
                                       CdS cells are approximately evenly illuminated, the tracker does
                                       nothing. To test the light tracker, cover one CdS sensor with your
                                       finger.  This  should  activate  the  gearbox  motor  and  the  shaft
                                       should begin to rotate.
                                       If the shaft rotates in the opposite direction of the light source,
                                       reverse either the sensor input pins or the output pins to the H-
                                       bridge, but not both.

                                                       Team LRN                                      Intelligence
   151   152   153   154   155   156   157   158   159   160   161