This is a continuation from Part 1. If you haven’t read it yet you canĀ here.
Now, I had to figure out how to control a motor from the Arduino. If you look at an Arduino, it has a bunch of pins (or holes) sticking out of it. These are the GPIO (General Purpose Input/Output) pins. To interact with the outside world, the Arduino can send varying amounts of current to each pin, and hence, anything you have connected to it.
To begin testing the pins, I got out an electronics kit I had gotten for Christmas and hooked up a motor to one of the pins and to the ground. After fiddling around with he code for awhile, and looking up online how to use the pins, I was able to get the motor to run at varying speeds. Great! Now I knew how to send electricity to the pins! But there was another problem. The Arduino can send a maximum of 5 volts to each pin, but the motors on the electric car require 12 volts, which means that I would need a motor controller.
A Motor Controller is simply a device that receives data from the Arduino to tell it how fast to run the motors, and then sends a corresponding amount of current to the motor(s) it’s connected to. So, if I could hook the Arduino up to a 12 volt motor controller, I could run the motors. The leaders of the Robotics team knew that I would need a motor controller, and so they already had one for me to use. However, it was a digital motor controller, which threw everything off.
This is the difference between a digital and analog signal:
An analog signal is the one I was using before. It is very straightforward, and means that you have a constant current being applied to your device. In my case I was sending anywhere from 0-5 volts to my motor from the Arduino, so that the motor would move faster as I gave it more current.
A digital signal is very different. Digital signals also use electricity, but they are Pulse-Width-Modulated. What this means is that instead of being a constant varying voltage, the signal is sending a pulse of 5 volts and then going back to 0 volts. The pulse is also width modulated, which means that the duration of time between each pulse is very carefully controlled.
The way the motor controller I was given worked was it would receive a PWM signal every 1000-2000 milliseconds to control the speed and direction the motor would run. If I made the Arduino send a pulse every 1500 milliseconds, the motor controller would send no power to the motor it was connected to. If I made the Arduino send a pulse every 1000 milliseconds, the motor controller would run the motor at full speed reverse, and if I made the Arduino send a pulse every 2000 milliseconds, the motor controller would run the motor at full speed forward. If the Arduino sent a pulse at any number in between, the motor controller would just run the motor slower or faster in that direction.
It took a very long time to find out how PWM worked, and even longer to learn how to use it. Luckily, after searching online, I found some example code I could download that would run the motors at whatever speed I entered (-100% – 100%). I was able to use that code to figure out how to program the Arduino to use PWM.
Now I had two programs: one that could receive data from the controller, and one that could send that data to the motor controllers. Now, I just had to figure out to combine them so that they would work together.
Continue reading in part 3 here.
0 thoughts on “Remote Control Jeep Community Service Project – Part 2”