Introduction: Arduino NANO Simple E-boat Controller (Forward, Neutral, Reverse)

About: //<3 Machines

Simple controller for Brushless Motor with ESC and Arduino for docking a Sail Boat.

Switch to control Forward/Neutral/Reverse

Joystick to control the throttle

Ignition Key Switch to turn on the controller.


Supplies

Arduino Nano x1

1P2T Paddle switch x1

Arduino joystick x1

1KOhm Resistor x2

ESC Acording to the motor size that you will use.

Brushless Motor

Ignition Key Switch

WaterProof Connectors

Heat Shrink Tubing

Controller Box

48V Li-ion Battery

5VDC Regulator (48VDC to 5VDC)

Wires ESC to Motor

Wires ESC to Battery

Step 1: The Code

#include <Servo.h>

#include <Wire.h>


int ESCPin = D3; // signal pin for the ESC.

int killPin = D4; // analog input pin for the kill switch.

int MaxDialPin = A0; // analog input pin for the max speed dial pot.(not being used so just use the same input as the throttle)

int switchPin = D6; // analog input pin for the FWD/REV switch.

int potPin = A0; // analog input pin for the throttle (joystick throttle in this case).

float potVal;

float MaxDialVal;

float pwmVal;

float MaxpwmVal;

Servo servo;

int nIts = 20;


int LowVolt = 227 + 180;

int HiVolt = 929 - 180;


void setup() {

 Serial.begin(9600);


 servo.attach(ESCPin);

 pinMode(killPin, INPUT_PULLUP);

 pinMode(MaxDialPin, INPUT);

 pinMode(switchPin, INPUT_PULLUP);

 servo.writeMicroseconds(1500); // send "stop" signal to ESC. Also necessary to arm the ESC.

}

void loop() {


 /*potVal = analogRead(potPin); // read input from potentiometer.*/

 if (digitalRead(killPin) == LOW) { // If kill switch not activated, then proceed in Run mode


   for (int i = 0; i < nIts; i++) {

     potVal = potVal + analogRead(potPin);

     /*delay(1);*/

     MaxDialVal = MaxDialVal + analogRead(MaxDialPin);

   }

 potVal = potVal / nIts;

   MaxDialVal = MaxDialVal / nIts;

   //Serial.print("potVal value is: ");

   //Serial.println(potVal);

   //Serial.print("MaxDialVal value is: ");

   //Serial.println(MaxDialVal);


   if (digitalRead(switchPin) == HIGH) {


     pwmVal = map(potVal, LowVolt, HiVolt, 1100, 2000); // maps potentiometer values to PWM value.

     MaxpwmVal = 1500 + (500 * (MaxDialVal / 1058));

     //Serial.print("MaxpwmVal value is: ");

     //Serial.println(MaxpwmVal);

     if (pwmVal > MaxpwmVal) {

       pwmVal = MaxpwmVal;

     }

     //Serial.print("Max-adjusted pwmVal value is: ");

     //Serial.println(pwmVal);

     if (pwmVal <= 1505) {

       pwmVal = 1500;

     }

 servo.writeMicroseconds(pwmVal); // Send signal to ESC.

     /*servo.writeMicroseconds(1500); // Send signal to ESC.*/

     Serial.print("Forward: potVal value is: ");

     Serial.println(potVal);

     Serial.print("Forward: PWM value is: ");

     Serial.println(pwmVal);

   }

   else {

     /*if (digitalRead(switchPin) == LOW) {*/


      pwmVal = 1500 ;

   servo.writeMicroseconds(pwmVal); // Send signal to ESC.

   Serial.print("Kill switch activated, ESC in neutral");

   Serial.println(pwmVal);

 }

}


 else

 {

   for (int i = 0; i < nIts; i++) {

     potVal = potVal + analogRead(potPin);

     /*delay(1);*/

     MaxDialVal = MaxDialVal + analogRead(MaxDialPin);


   }


   potVal = potVal / nIts;

   MaxDialVal = MaxDialVal / nIts;

   //Serial.print("potVal value is: ");

   //Serial.println(potVal);

   //Serial.print("MaxDialVal value is: ");

   //Serial.println(MaxDialVal);



pwmVal = map(potVal, 0, 1023, 1100, 2000); // maps potentiometer values to PWM value.


     MaxpwmVal = 1490 ;

   if (pwmVal > MaxpwmVal) {

    pwmVal = MaxpwmVal;    

}


     if (pwmVal >= 1500) {

       pwmVal = 1500;

     }

servo.writeMicroseconds(pwmVal); // Send signal to ESC.

     Serial.print("Reverse: potVal value is: ");

     Serial.println(potVal);

     Serial.print("Reverse: PWM value is: ");

     Serial.println(pwmVal);

 }

}


Step 2: The Wiring

Step 3: The Box

Step 4: Test