joergpauly
Published © Apache-2.0

Sea Vessel Switch Board

An instrument board to control six relays on a sea vessel.

BeginnerProtip1,461
Sea Vessel Switch Board

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Push Buttons with LED
×6
Sunfounder Relay Breakout board
×1
Sunfounder Relay (4 channels)
×1

Software apps and online services

Visual Studio 2017
Microsoft Visual Studio 2017

Story

Read more

Schematics

Schematics of the Switch Board

This schematics show the main board carrying the Arduino Nano and the push buttons with LED. The relay breakboards (ie. Sundfounder) are connected via pins

Code

Sketch to control 6 relays

Arduino
The project uses to OneButton Library.
The code makes sure that anchor and running light can never be both switched on. Either you're anchored or you're sailing. Both at a time is impossible...:-)
The will be an update to the code to stop the wipers only at an end position using current measuring.
/*
 Name:		FS_Panel.ino

 Panel with 6 Buttons with LEDs to control lights, pumps and wipers.
 Internal pullup reistors are used so we have to connect the buttons to a sink.

 Created:	03.07.2019 08:23:01
 Author:	Joerg Pauly
*/

// Get the OneButton Library and all the other stuff working
#include <EEPROM.h>
#include <OneButton.h>

// As the relays close on LOW we need inverted triggers: switching a relay to ON means pull it's pin to GND
#define ON LOW
#define OFF HIGH

// define the Button's pins
int pinAnchor = A0;
int pinRunning = A1;
int pinBilge = A2;
int pinWater = A3;
int pinWiperL = A4;
int pinWiperR = A5;

// define pins for LEDs and relais
int relAnchor = 12;		// D12
int relRunning = 11;	// D11
int relBilge = 9;		// D9
int relWater = 8;		// D8
int relWiperL = 7;		// D7
int relWiperR = 6;		// D6

// define pins for feedback from the wipers
int febWiperL = A6;
int febWiperR = A7;

// define BOOLs to state if a wiper is to be switched off
bool flWiperL;
bool flWiperR;

// Create Button Objects 
OneButton btnAnchor(pinAnchor, true);
OneButton btnRunning(pinRunning, true);
OneButton btnBilge(pinBilge, true);
OneButton btnWater(pinWater, true);
OneButton btnWiperL(pinWiperL, true);
OneButton btnWiperR(pinWiperR, true);

// Prepare the pins an attach the Buttons
void setup() 
{
	// Make the buttons INPUT
	pinMode(pinAnchor, INPUT_PULLUP);
	pinMode(pinRunning, INPUT_PULLUP);
	pinMode(pinBilge, INPUT_PULLUP);
	pinMode(pinWater, INPUT_PULLUP);
	pinMode(pinWiperL, INPUT_PULLUP);
	pinMode(pinWiperL, INPUT_PULLUP);

	// Make relais and LEDs OUTPUT
	pinMode(relAnchor, OUTPUT);
	pinMode(relRunning, OUTPUT);
	pinMode(relBilge, OUTPUT);
	pinMode(relWater, OUTPUT);
	pinMode(relWiperL, OUTPUT);
	pinMode(relWiperR, OUTPUT);

	// Set them all to OFF
	digitalWrite(relAnchor, OFF);
	digitalWrite(relRunning, OFF);
	digitalWrite(relBilge, OFF);
	digitalWrite(relWater, OFF);
	digitalWrite(relWiperL, OFF);
	digitalWrite(relWiperR, OFF);

	// attach buttons to callbacks
	btnAnchor.attachClick(OnAnchorPressed);
	btnRunning.attachClick(OnRunningPressed);
	btnBilge.attachClick(OnBilgePressed);
	btnWater.attachClick(OnWaterPressed);
	btnWiperL.attachClick(OnWiperLPressed);
	btnWiperR.attachClick(OnWiperRPressed);
	btnWiperL.attachDuringLongPress(OnWiperLongPressed);
	btnWiperR.attachDuringLongPress(OnWiperLongPressed);

	if (EEPROM.read(0) == 1)
	{
		digitalWrite(relWater, ON);
	}
	else
	{
		digitalWrite(relWater, OFF);
	}

	flWiperL = false;
	flWiperR = false;	
}

// the endless work of the MCU
void loop() 
{
	// check the buttons
	btnAnchor.tick();
	btnRunning.tick();
	btnBilge.tick();
	btnWater.tick();
	btnWiperL.tick();
	btnWiperR.tick();
	
	// check if a wiper is to be switched off
	// TODO: change to tendence current measuring
	if (flWiperL)
	{
		//int res = analogRead(febWiperL);		
		//if (res > 950)
		//{
			digitalWrite(relWiperL, OFF);
			flWiperL = false;
		//}
	}

	if (flWiperR)
	{
		//int res = analogRead(febWiperR);
		//if (res > 950)
		//{
			digitalWrite(relWiperR, OFF);
			flWiperR = false;
		//}
	}


}

// Here are the callback functions for the buttons

void OnAnchorPressed()
{	
	if (digitalRead(relAnchor) == OFF)
	{
		digitalWrite(relAnchor, ON);
		digitalWrite(relRunning, OFF);	
	}
	else
	{
		digitalWrite(relAnchor, OFF);
	}
}

void OnRunningPressed()
{
	if (digitalRead(relRunning) == OFF)
	{
		digitalWrite(relRunning, ON);
		digitalWrite(relAnchor, OFF);
	}
	else
	{
		digitalWrite(relRunning, OFF);
	}
}

void OnBilgePressed()
{
	if (digitalRead(relBilge) == OFF)
	{
		digitalWrite(relBilge, ON);
	}
	else
	{		
		digitalWrite(relBilge, OFF);
	}
}

void OnWaterPressed()
{
	// "Water" is the only channel that is switched on in normal condition.
	// As we want to have the relays in rest position on normal we have to invert it by using the LOW/HIGH system.	

	if (digitalRead(relWater) == LOW)
	{
		digitalWrite(relWater, HIGH);
		EEPROM.update(0, 1);		
	}
	else
	{
		digitalWrite(relWater, LOW);
		EEPROM.update(0, 0);		
	}
}

void OnWiperLPressed()
{	
	if (digitalRead(relWiperL) == OFF)
	{	
		digitalWrite(relWiperL, ON);
	}
	else
	{		
		flWiperL = true;		
	}
}

void OnWiperRPressed()
{	
	if (digitalRead(relWiperR) == OFF)
	{
		digitalWrite(relWiperR, ON);
	}
	else
	{
		flWiperR = true;
	}
}

void OnWiperLongPressed()
{
	digitalWrite(relWiperL, ON);
	digitalWrite(relWiperR, ON);
}

Credits

joergpauly
0 projects • 0 followers

Comments