Hello guys! I want to start off by saying my Arduino programming skills leave much to be desired! Here's what I need help with:
I have a 1-Man Pontoon boat (about 8' long) that has a 12V Marine Deep Cycle battery and a 30lb. thrust Minn Kota Endura C30 electric trolling motor on it. I removed the head of the motor and relocated it to the right of the seat so I can control forward and reverse speeds. Initially, I was using the swivel seat to steer the motor (turn left in seat, go left, etc.) and this was accomplished via 2 stainless steel 1/16" cables in a X fashion attached to the back top Left and Right of my seat with 2 Eyebolts (port and starboard) attached to a clamp on the motor shaft. This worked okay, but I found I couldn't go in a straight line to save my life!
Hence, my new project!! Here's what I have so far:
1 60kg waterproof servo motor (3 wire)
1 Arduino Nano
1 DC to DC Converter (12V to 6V) (servo is rated for 6-8.4VDC)
1 Joystick Module
The servo motor is connected as follows:
Red +6VDC
Black Ground
White Pin D3 on Nano
The joystick is connected as follows:
GND Ground on DC to DC Converter and Nano
+5V 5V Pin Nano
VRX Pin A1 Nano
VRY Pin A0 Nano
SW Pin D4 Nano
The sketch I have now currently works fine for turning servo motor left or right.
What I would like to accomplish is that when I click down on the joystick, the motor goes back to center.
This will allow me to go in a straight line instantly whenever I click the button!
Currently, once I move the joystick Left or Right, the servo stays in that position until I change it.
Here's my code:
#include <Servo.h>
//const int ledPin = 13;
const int xPin = A1;
const int yPin = A0;
const int switchPin = 4;
const int servoxPin = 3;
const int servoyPin = 11;
int xValue;
int yValue;
int X_pos = 90;
int Y_pos = 90;
volatile int switchState = 0;
Servo servox;
Servo servoy;
void setup()
{
pinMode (xPin, INPUT) ;
pinMode (yPin, INPUT) ;
// pinMode(ledPin, OUTPUT);
pinMode(switchPin, INPUT_PULLUP);
servox.attach(servoxPin );
servoy.attach(servoyPin);
servox.write(X_pos);
servoy.write(Y_pos);
attachInterrupt(digitalPinToInterrupt(switchPin), switchISR, CHANGE);
}
void loop()
{
xValue = analogRead(xPin);
yValue = analogRead(yPin);
// For X-Axis Servo
if (xValue < 300)
{
if (X_pos < 10)
{
// Do Nothing
}
else
{
X_pos = X_pos - 5;
servox.write(X_pos);
delay(100);
}
}
if (xValue > 700)
{
if (X_pos > 160)
{
// Do Nothing
}
else
{
X_pos = X_pos + 5;
servox.write(X_pos);
delay(100);
}
}
// For Y-Axis Servo
if (yValue < 300)
{
if (Y_pos < 10)
{
// Do Nothing
}
else
{
Y_pos = Y_pos - 5;
servoy.write(Y_pos);
delay(100);
}
}
if (yValue > 700)
{
if (Y_pos > 160)
{
// Do Nothing
}
else
{
Y_pos = Y_pos + 5;
servoy.write(Y_pos);
delay(100);
}
}
}
void switchISR()
{
switchState = digitalRead(switchPin);
digitalWrite(HIGH, switchState);
}
Thanks in advance for the direction I am sure you guys can provide me!!
P.S. I did try searching around the internet for a few hours and tried a few things, but nothing seemed to work. I realized I was in over my head and here I am!!