Hi all.
I'm a teacher learning to program I have watched some great videos on Youtube and done a few projects involving LEDs and small motors.
Last week my son challenged me to use and arduino to get his old radio shack RC truck going again.
I plan to use an HC-06 bluetooth adapter for now. Probably it will have a shorter range than is desirable, but it will work for the purpose.
I have been able to use the HC-06 to control the car using relays for controlling forward and backward motion, but with the power and speed this thing has On/Off control is not good enough.
I replaced the six wire servo with a regular servo and I think I have figured out how to do the steering but haven't put that into the sketch yet.
I found a brushed motor controller TA8428K.
I have done a lot of reading and watching motor control videos but can't find instructions for this particular controller. It it is missing the "enable" pin that every other one has.
I used instructions from this lesson and this lesson to try and patch together a sketch that would work.
I thought I was doing ok editing the code until I got to the very last row. This row says I have to use the enable pin to control motor speeds. I was hoping to use an analog input on pins 1&2 to control speed and rotation of the motor, pretty much like a transistor would.
Can anybody tell me if I'm on the right track with this or if I'm completely out of it here. I'm here to learn so anything goes.
I took out all reference to motor B and to the enable pins because my controller does not have them. I got hung up on the last one on the last sentence. Don't know what to do with it.
/*
DroneBot Workshop 2017
http://dronebotworkshop.com
*/
// Edited by Jonathan Waldner on Nov.2017 for a relay and a TA8428 Motor driver.
// Motor A
int in1 = 8;
int in2 = 7;
char BluetoothData; // the Bluetooth data received
// Joystick Input
int joyVert = A0; // Vertical
// Motor Speed Values - Start at zero
int MotorSpeed1 = 0;
// Joystick Values - Start at 512 (middle position)
int joyposVert = 50;
void setup()
{
Serial.begin(9600); // Start Serial Monitor
// Set all the motor control pins to outputs
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
// Start with motors disabled and direction forward
// Motor A
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
}
void loop() {
if (Serial.available()){
{
BluetoothData=Serial.read(joyVert); //Get Joystick Vertical position from bluetooth
}
// Determine if this is a forward or backward motion
// Do this by reading the Verticle Value
// Apply results to MotorSpeed and to Direction
if (joyposVert < 50)
{
// This is Backward
// Set Motor A backward
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
//Determine Motor Speeds
// As we are going backwards we need to reverse readings
joyposVert = joyposVert - 50; // This produces a negative number
joyposVert = joyposVert * -1; // Make the number positive
MotorSpeed1 = map(joyposVert, 0, 50, 0, 100);
}
else if (joyposVert > 50)
{
// This is Forward
// Set Motor A forward
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
//Determine Motor Speed
MotorSpeed1 = map(joyposVert, 52, 100, 0, 48);
}
else
{
// This is Stopped
MotorSpeed1 = 0;
}
// Adjust to prevent "buzzing" at very low speed
{
if (MotorSpeed1 < 8)MotorSpeed1 = 0;
// Set the motor speeds
analogWrite(enA, MotorSpeed1);
}[code]
[/code]