I will look at the H bridge set ups. Right now i am using a 8 modue realy analog read function of the Arduino (PWM), 5K pot, I am not needing speed in the motors, and have considered servos instead. However... I am using a 12v dc motor connected to a gear to move my spray nozzel LEFT/RIGHT. And the actuator to move the same nozzel UP/DOWN. I thought making a Joystick configuration would be best then the switches i have been using. And the Arduino seemed to be a good platform to build/control with. This is the code i am working with right now.
/*
Joystick Model OM400B-M2 www.omter.com
Joystick control with Arduino Uno and 8 channel relay Module Controller
Motor A 12v DC controlong LEFT/RIGHT relay channels 1&2 (need to be able to set 90degree rotation limit both ways and speed),
Motor B 12v dc Actuator OPEN/ClOSE relay channels 3&4,
Motor C 12v DC pump ON/OFF via switch realy channel 5,
Motor D 12v DC controling Valve OPEN/ClOSE realy channels 6&7 (set limits of motor rotation and speed to control valve/ i.e. how long motor runs and how fast)
*/
// Motor A LEFT/RIGHT
int in1 = 9;
int in2 = 8;
// Motor B actuator OPEN/CLOSE
int in3 = 3;
int in4 = 4;
// Motor C momentary button
int in5 = 2;
// Motor D valve motor
int in6 = 6;
int in7 = 7;
// Joystick Input
int joyVert = A0; // Vertical
int joyHorz = A1; // Horizontal
int pot1 = A3; // Motor D
// Motor Speed Values - Start at zero
int MotorSpeed1 = 0;
int MotorSpeed2 = 0;
int MotorSpeed3 = 100;
int MotorSpeed4 = 0
int MotorSpeed5 = 0
// Joystick Values - Start at 512 (middle position)
int joyposVert = 512;
int joyposHorz = 512;
void setup()
{
// Set all the motor control pins to outputs
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
pinMode(in5, OUTPUT);
pinMode(in6, OUTPUT);
pinMode(in7, OUTPUT);
// Start with motors disabled and direction forward
// Motor A
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
// Motor B
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
// Motor C
digitalWrite(in5, HIGH);
//Motor D
digitalWrite(in6, HIGH);
digitalWrite(in7, LOW);
}
void loop() {
// Read the Joystick X and Y positions
joyposVert = analogRead(joyVert);
joyposHorz = analogRead(joyHorz);
// 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 < 460)
{
// This is Backward
// Set Motor A backward
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
// Set Motor B backward
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
// Set Motor D backwards
digitalWrite(in6, LOW);
digitalWrite(in7, HIGH);
//Determine Motor Speeds
// As we are going backwards we need to reverse readings
joyposVert = joyposVert - 460; // This produces a negative number
joyposVert = joyposVert * -1; // Make the number positive
MotorSpeed1 = map(joyposVert, 0, 460, 0, 255);
MotorSpeed2 = map(joyposVert, 0, 460, 0, 255);
}
else if (joyposVert > 564)
{
// This is Forward
// Set Motor A forward
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
// Set Motor B forward
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
// Set Motor D forward
digitalWrite(in6, LOW);
digitalWrite(in7, HIGH);
//Determine Motor Speeds
MotorSpeed1 = map(joyposVert, 564, 1023, 0, 255);
MotorSpeed2 = map(joyposVert, 564, 1023, 0, 255);
}
else
{
// This is Stopped
MotorSpeed1 = 0;
MotorSpeed2 = 0;
}
// The Horizontal position will "weigh" the motor speed
// Values for each motor
if (joyposHorz < 460)
{
// Move Left
// As we are going left we need to reverse readings
joyposHorz = joyposHorz - 460; // This produces a negative number
joyposHorz = joyposHorz * -1; // Make the number positive
// Map the number to a value of 255 maximum
joyposHorz = map(joyposHorz, 0, 460, 0, 255);
MotorSpeed1 = MotorSpeed1 - joyposHorz;
MotorSpeed2 = MotorSpeed2 + joyposHorz;
// Don't exceed range of 0-255 for motor speeds
if (MotorSpeed1 < 0)MotorSpeed1 = 0;
if (MotorSpeed2 > 255)MotorSpeed2 = 255;
}
else if (joyposHorz > 564)
{
// Move Right
// Map the number to a value of 255 maximum
joyposHorz = map(joyposHorz, 564, 1023, 0, 255);
MotorSpeed1 = MotorSpeed1 + joyposHorz;
MotorSpeed2 = MotorSpeed2 - joyposHorz;
// Don't exceed range of 0-255 for motor speeds
if (MotorSpeed1 > 255)MotorSpeed1 = 255;
if (MotorSpeed2 < 0)MotorSpeed2 = 0;
}
// Adjust to prevent "buzzing" at very low speed
if (MotorSpeed1 < 10)MotorSpeed1 = 0;
if (MotorSpeed2 < 10)MotorSpeed2 = 0;
// Set the motor speeds
analogWrite(in1, MotorSpeed1);
analogWrite(in3, MotorSpeed2);
analogWrite(in5, MotorSpeed3);
analogWrite(in6, MotorSpeed4);
analogWrite(in7, MotorSpeed5);
}