0% found this document useful (0 votes)
4 views3 pages

Arduino LCD Control System Code

This document is an Arduino sketch that controls a system using a LiquidCrystal display and relay outputs. It tracks the runtime of the system and provides service reminders after a specified interval, while also allowing remote control to toggle contact, start, and load states. The code includes debounce handling for button presses and updates the display accordingly based on the system's state.

Uploaded by

ahmedodha663
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Arduino LCD Control System Code

This document is an Arduino sketch that controls a system using a LiquidCrystal display and relay outputs. It tracks the runtime of the system and provides service reminders after a specified interval, while also allowing remote control to toggle contact, start, and load states. The code includes debounce handling for button presses and updates the display accordingly based on the system's state.

Uploaded by

ahmedodha663
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

#include <Wire.

h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

const int RELAY_CONTACT = 3;


const int RELAY_START = 4;
const int RELAY_LOAD = 5;
const int REMOTE_PIN = 2;

bool contactOn = false;


bool startOn = false;
bool loadOn = false;

int startCount = 0;
int loadCount = 0;

unsigned long contactStartTime = 0;


unsigned long totalRunTimeSeconds = 0;
const unsigned long serviceIntervalHours = 200;
bool serviceShown = false;

unsigned long lastPress = 0;


const unsigned long debounce = 250;

void setup() {
[Link]();
[Link]();

[Link](0,0);
[Link]("Ahmed Hamza Ouda");
[Link](0,1);
[Link]("Tel: 01111126163");

pinMode(RELAY_CONTACT, OUTPUT);
pinMode(RELAY_START, OUTPUT);
pinMode(RELAY_LOAD, OUTPUT);
pinMode(REMOTE_PIN, INPUT);

digitalWrite(RELAY_CONTACT, LOW);
digitalWrite(RELAY_START, LOW);
digitalWrite(RELAY_LOAD, LOW);

delay(2000);
[Link]();
[Link](0,0);
[Link]("System Ready");
}

void loop() {
if(contactOn){
totalRunTimeSeconds = (millis() - contactStartTime) / 1000;
unsigned long totalHours = totalRunTimeSeconds / 3600;
unsigned long totalMinutes = (totalRunTimeSeconds % 3600) / 60;

if(totalHours > 0 && totalHours % serviceIntervalHours == 0 && !serviceShown){


[Link]();
[Link](0,0);
[Link]("Service Reminder");
[Link](0,1);
[Link]("Oil Service");
serviceShown = true;
delay(5000);
[Link]();
[Link](0,0);
[Link]("System Ready");
}
else if(totalHours % serviceIntervalHours != 0){
serviceShown = false;
}

[Link](0,0);
[Link]("Run Time: ");
[Link](totalHours);
[Link]("h ");
[Link](totalMinutes);
[Link]("m");
}

if(digitalRead(REMOTE_PIN) == HIGH){
if(millis() - lastPress > debounce){
if(!contactOn){
contactOn = true;
digitalWrite(RELAY_CONTACT, HIGH);
contactStartTime = millis();
[Link]();
[Link]("Contact: ON");
}
else if(!startOn){
startOn = true;
startCount++;
[Link]();
[Link]("Start: Pulse");
digitalWrite(RELAY_START, HIGH);
delay(700);
digitalWrite(RELAY_START, LOW);
[Link](0,1);
[Link]("Start Count:");
[Link](startCount);
}
else{
loadOn = !loadOn;
if(loadOn) loadCount++;
digitalWrite(RELAY_LOAD, loadOn ? HIGH : LOW);
[Link]();
[Link](0,0);
[Link]("Load: ");
[Link](loadOn ? "ON" : "OFF");
[Link](0,1);
[Link]("Load Count:");
[Link](loadCount);
}
lastPress = millis();
}
while(digitalRead(REMOTE_PIN) == HIGH);
}
}

You might also like