autohelm
Published © GPL3+

Tiller Pilot for Yacht

Project using Arduino to steer a full-size boat on a compass heading.

AdvancedWork in progress7,063
Tiller Pilot for Yacht

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
LSM303 Compass Board
×1
Relay (generic)
Share To DC5V 2 Way 2CH Channel Relay Module
×1
Button
Provided with Arduino Starter Kit
×3
Resistor 221 ohm
Resistor 221 ohm
Provided with Arduino Starter Kit
×1
Resistor 220 ohm
Resistor 220 ohm
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Story

Read more

Custom parts and enclosures

Tiller Pilot Schematic

Schematics

Tiller Pilot Schematic

Code

TillerPilot_V05

Arduino
//TillerPilot 04/05/2019
//Buttons wired to A8 A9 and A10
//LED wired D5
//Relay wired from IN1 to A0 and IN2 to A1
//Compass SDA to A4 & SCL to A5
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
Adafruit_LSM303_Mag_Unified mag = Adafruit_LSM303_Mag_Unified(12345);
const int B_Port = 8;
const int B_Lock = 9;
const int B_Star = 10;
int Heading;
int Course;
int Val_01 = 0;
int Val_02 = 0;
int Tillerpilot_off = 0;
int B_State = 0;
int R_Port = A0;
int R_Star = A1;
int LED_Port = 13;
int LED_Lock = 5;
int LED_Star = 12;
void setup() 
{
Serial.begin(9600);
if(!mag.begin()) 
 {
 while(1); 
 }
  pinMode(B_Port, INPUT_PULLUP);
  pinMode(B_Lock, INPUT_PULLUP);
  pinMode(B_Star, INPUT_PULLUP);
  pinMode(LED_Port, OUTPUT);
  pinMode(LED_Lock, OUTPUT);
  pinMode(LED_Star, OUTPUT);
  pinMode(R_Port, OUTPUT);
  pinMode(R_Star, OUTPUT);
  digitalWrite(R_Port, HIGH);
  digitalWrite(R_Star, HIGH);
  digitalWrite(LED_Port, HIGH);
  digitalWrite(LED_Lock, HIGH);
  digitalWrite(LED_Star, HIGH);
}
void loop() 
{
//Tillerpilot in standby mode
Val_01 = digitalRead(B_Lock);
if(Val_01 == HIGH && Tillerpilot_off == LOW)
 {
 B_State = 1-B_State; // Debound Button
 delay(1);
 }    
Tillerpilot_off = Val_01;
if(B_State == HIGH)
  {
  //Flash ON/OFF Lock LED
  digitalWrite(LED_Lock, HIGH);
  delay(250);
  digitalWrite(LED_Lock, LOW);
  delay(250);
   {
   if (digitalRead(B_Port) == LOW)
   digitalWrite(R_Port, LOW);
   digitalWrite(LED_Port, HIGH);
   }
    {
    if (digitalRead(B_Star) == LOW)
    digitalWrite(R_Star, LOW);
    digitalWrite(LED_Star, HIGH);
    }
  delay (250);
  digitalWrite(R_Port, HIGH);
  digitalWrite(LED_Port, LOW);
  digitalWrite(R_Star, HIGH);
  digitalWrite(LED_Star, LOW);
  Val_02 = 0;
  }
else
  {
  //Tillerpilot in steering mode
  //Lock LED continuous ON
  digitalWrite(LED_Lock, HIGH);
  delay(1); 
  Serial.print("Course: ");Serial.print(Course);Serial.print("   ");
  sensors_event_t event; 
  mag.getEvent(&event);
  float Pi = 3.14159;
  int Heading = (atan2(event.magnetic.y,event.magnetic.x) * 180) / Pi;
   {
   if (Heading < 0)
   Heading = 360 + Heading;
   }
  Serial.print("Heading: "); Serial.println(Heading);
  if (Course +3 <= Heading)digitalWrite(R_Port, LOW); digitalWrite(LED_Port, HIGH);
  if (Course -3 >= Heading)digitalWrite(R_Star, LOW); digitalWrite(LED_Star, HIGH);
   {
   if (Val_02 == 0) 
   Course = Heading;  
   Val_02 = (Val_02 +1);
   }
    {
    if (digitalRead(B_Port) == LOW)
    Course = (Course - 1);
    }
     {
     if (Course < 0)
     Course = 360 + Course;
     }
    {
    if (Course > 360)
    Course = Course - 360;
    }
   {
   if (digitalRead(B_Star) == LOW)
   Course = (Course + 1);
   }
  delay (250);
  digitalWrite(R_Port, HIGH);
  digitalWrite(LED_Port, LOW);
  digitalWrite(R_Star, HIGH);
  digitalWrite(LED_Star, LOW);
  }
}

Credits

autohelm

autohelm

0 projects • 9 followers

Comments