Arduino R/C Lawnmower (painted)

 by johndavid400
FeaturedContest Winner

Step 10: The Code

code.jpg
I changed the code so that the Interrupt Service Routines (ISR) would run more quickly and the sketch would spend less time in the ISR. This means less overhead which means more signals are processed and smoother operation of the bot.

I also added a 2nd sketch for the 2nd microcontroller to process 2 signals (you can add as many more as you want) using the pulseIn method instead of using interrupts. This only processes about 1/5th of the available signals from the R/C Receiver, but also severely decreases the chance of receiving a "BAD" signal. Also, since the power relay is setup to only be ON if the signal is "GOOD", when you go out of range, it automatically shuts off the power to the motors only.

The 2nd Atmega by default should have digital pin 4 used as the R/C servo signal input from the R/C receiver, digital pin 6 should control a 5v relay or N-channel mosfet that is used to switch the 60amp power relay ON/OFF. That is all that is needed, you can also use an LED on pins 12 and 13 to indicate whether the relay is ON or OFF.

You can also add 2 12v running lights from Walmart for a car... I use an N-channel mosfet directly tied to pin 9 of the 2nd Arduino to control the brightness of the lights using a hacked channel on my transmitter. This input from the receiver would go to digital pin 2. Check the code.

Download the .zip file on this page and upload the sketches. If you don't plan on adding the 2nd Atmega with the failsafe and killswitch, that is fine. You can still update the new code for just the main Atmega and it should run more smoothly.

 
Remove these adsRemove these ads by Signing Up
tma73 says: May 12, 2012. 11:35 AM
Excellent job on your Lawnbot! :D
Thanks for also posting the code you used. I'm putting together a bot using parts from a wheelchair.
Also using a Spektrum Tx & Rx to drive it for now (using a Sabertooth2X25 motor driver).
I noticed in your code you have it setup for independent steering. Was wondering by ommitting the 'b' in motor 1 & 2 I could run it using differential steering.
Thanks,
Thomas
nathanielg in reply to tma73May 26, 2012. 9:01 PM
the sabertooth can work directly from the signals coming from the rc reciever so unless you want a remote kill switch or accessories on the mower you will not even need the arduino
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!