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

by jbrandonms in Circuits > Arduino

411 Views, 0 Favorites, 0 Comments

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

cover JOY.png
cover.png
IMG_9286.JPG
IMG_9278.JPG

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

The Code

IMG_9288.JPG

#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);

 }

}


Downloads

The Wiring

IMG_9291.JPG
IMG_9254.JPG
IMG_9258.JPG
IMG_9276.JPG
IMG_9260.JPG
IMG_9261.JPG
IMG_9262.JPG
IMG_9263.JPG
IMG_9266.JPG
IMG_9272.JPG
IMG_9274.JPG
IMG_9245.JPG
IMG_9227.JPG

The Box

IMG_9247.JPG
IMG_9248.JPG
IMG_9249.JPG
IMG_9250.JPG
IMG_9246.JPG
IMG_9298.JPG
IMG_9299.JPG

Test

IMG_9297.JPG
IMG_9283.JPG
IMG_9287.JPG
IMG_9292.JPG
IMG_9293.JPG
E-Boat Controller Lite