Somewhat debugged Sumobot Code
Debugging Log:
Bugs fixed in the original code:
Buttons
Buttons wired for internal Pull Up but programmed for external Pull Down, leading to floating pins, error was fixed in the code.
The mode code didn’t always read correctly on restart – this was fixed by moving the code after the push start routine.
Interrupts
The Interrupt library wasn’t compatible with the Arduino mega
Fixed by using external interrupts 2-5 instead.
Had to attach interrupts after the push start code to avoid conflicts.
Ultrasonic Code:
Put in range code for reactions.
Moved the reaction code to a separate routine after each scan cycle.
Made the scan cycle a separate function to be called.
Electromechanical
PWM and DIR inputs were wired back to front on the motor control
When using the disposable 9VDC batteries after the LiPo’s I’d ordered online were faulty, the motors would draw too much current and reset the Arduino. A separate battery was used for the Arduino, rather than capacitors. Would work better with better batteries.
Tyres are too stretchy and prone to stripping off and jamming the gears – would have to cast new tyres encasing the wheels to fix.
Embed This Sketch
Use the following HTML code to embed the sketch code above in your blog or website.
<iframe style="height: 510px; width: 100%; margin: 10px 0 10px;" allowTransparency="true" src="https://codebender.cc/embed/sketch:358786" frameborder="0"></iframe>
Embed The Serial Monitor
You can also embed the Serial Monitor section! Just use this HTML code.
<iframe style="height: 510px; width: 100%; margin: 10px 0 10px;" allowTransparency="true" src="https://codebender.cc/embed/serialmonitor" frameborder="0"></iframe>