0% found this document useful (0 votes)
5 views13 pages

The Final Pressure Controled Pump Control PLC

The document is a complete code for a pressure-controlled pump system using an Arduino with a LiquidCrystal display. It includes functionalities for monitoring pressure, controlling multiple pumps, and managing LED indicators based on pressure thresholds. The system allows for user interaction through mode switching and pressure readings, ensuring efficient pump operation and real-time display updates.

Uploaded by

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

The Final Pressure Controled Pump Control PLC

The document is a complete code for a pressure-controlled pump system using an Arduino with a LiquidCrystal display. It includes functionalities for monitoring pressure, controlling multiple pumps, and managing LED indicators based on pressure thresholds. The system allows for user interaction through mode switching and pressure readings, ensuring efficient pump operation and real-time display updates.

Uploaded by

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

THE FINAL PRESSURE CONTROLED PUMP CONTROL PLC

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const int inputPin = 6;


const int pump1Pin = 8;
const int pump2Pin = 9;
const int pump3Pin = 10;
const int controlLedPin = 7;
const int pushToReadPin = 13;
const int modeSwitchPin = A2;
const int lowPressureLedPin = A5;
const int vfdLedPin = A1;

const int highThresholdPin = A3;


const int lowThresholdPin = A4;

const unsigned long delayDuration = 10000; // 10 seconds


const unsigned int closeDelay = 3500; // 3.5 seconds delay during shutdown
const unsigned long debounceDelay = 200; // 200ms debounce for mode switch

unsigned long startTime;


bool pump1On = false;
bool pump2On = false;
bool pump3On = false;

unsigned long controlLedTimer = 0;


bool controlLedActive = false;
bool controlLedTurnedOff = false;

unsigned long vfdLedTimer = 0;


bool vfdLedActive = false;

unsigned long lastLcdUpdate = 0;


const unsigned long lcdUpdateInterval = 200;
int cycleCount = 0;

unsigned long lastDebounceTime = 0;


int lastModeSwitchState = HIGH;
bool modeSwitchPressed = false;
bool isInThresholdMode = false;

float highThreshold = 3.0;


float lowThreshold = 1.0;
bool lowPressureLedOn = false;
bool displayPressureScreen = false;

float pressureReadings[10]; // Array for moving average filter


int pressureIndex = 0;
float smoothedPressure = 0;

void setup() {
pinMode(inputPin, INPUT);
pinMode(pump1Pin, OUTPUT);
pinMode(pump2Pin, OUTPUT);
pinMode(pump3Pin, OUTPUT);
pinMode(controlLedPin, OUTPUT);
pinMode(pushToReadPin, INPUT_PULLUP);
pinMode(modeSwitchPin, INPUT_PULLUP);
pinMode(lowPressureLedPin, OUTPUT);
pinMode(vfdLedPin, OUTPUT);

lcd.begin(20, 4);

byte clockIcon[8] = {
B11111, B01110, B01110, B00100,
B01110, B01110, B11111, B11111
};
lcd.createChar(0, clockIcon);

byte newIcon[8] = {
B11111, B11111, B01110, B00100,
B01110, B11111, B11111, B01110
};
lcd.createChar(1, newIcon);

digitalWrite(pump1Pin, LOW);
digitalWrite(pump2Pin, LOW);
digitalWrite(pump3Pin, LOW);
digitalWrite(controlLedPin, LOW);
digitalWrite(lowPressureLedPin, LOW);
digitalWrite(vfdLedPin, LOW);

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


pressureReadings[i] = 0;
}

Serial.begin(9600);
}

void loop() {
unsigned long currentTime = millis();

handlePressureLogic();
handleScreenLogic();
handleControlLedLogic(currentTime);
handleVfdLedLogic(currentTime);
handleOriginalPumpLogic();

if (currentTime - lastLcdUpdate >= lcdUpdateInterval) {


lastLcdUpdate = currentTime;
updateLCD();
}
}

// Function to handle pressure threshold and LED logic on A5


void handlePressureLogic() {
// Corrected multiplier for accurate pressure reading (0-6 BAR sensor)
float currentPressure = (analogRead(A0) * (6.0 / 1023.0)); // Corrected pressure
conversion for 0-6 BAR

// Use moving average filter for smoothing


pressureReadings[pressureIndex] = currentPressure;
pressureIndex = (pressureIndex + 1) % 10;

float pressureSum = 0;
for (int i = 0; i < 10; i++) {
pressureSum += pressureReadings[i];
}

smoothedPressure = pressureSum / 10; // Moving average

// Ignore pressure reading while pumps are running (interference avoidance)


if (digitalRead(inputPin) == HIGH) {
smoothedPressure = smoothedPressure * 0.8; // Adjust based on feedback
}

// Control Low Pressure LED (A5) based on thresholds


if (smoothedPressure < lowThreshold && !lowPressureLedOn) {
digitalWrite(lowPressureLedPin, HIGH); // Turn on the low-pressure LED
lowPressureLedOn = true;
} else if (smoothedPressure > highThreshold && lowPressureLedOn) {
digitalWrite(lowPressureLedPin, LOW); // Turn off the low-pressure LED
lowPressureLedOn = false;
}
}

// Function to handle Control LED (Pin 7) logic


void handleControlLedLogic(unsigned long currentTime) {
int inputState = digitalRead(inputPin);

if (inputState == HIGH && !controlLedActive) {


controlLedTimer = currentTime + 3000;
controlLedActive = true;
}

if (inputState == LOW && controlLedActive && !controlLedTurnedOff) {


controlLedTurnedOff = true;
controlLedTimer = currentTime;
}
if (controlLedTurnedOff && currentTime - controlLedTimer >= 3000) {
digitalWrite(controlLedPin, LOW);
controlLedTurnedOff = false;
controlLedActive = false;
}

if (controlLedActive && currentTime >= controlLedTimer && inputState == HIGH) {


digitalWrite(controlLedPin, HIGH);
}
}

// Function to handle VFD LED (Pin A1) logic


void handleVfdLedLogic(unsigned long currentTime) {
if ((pump1On || pump2On || pump3On) && !vfdLedActive) {
vfdLedTimer = currentTime + 5000;
vfdLedActive = true;
}

if (!pump1On && !pump2On && !pump3On && vfdLedActive) {


if (currentTime - vfdLedTimer >= 5000) {
digitalWrite(vfdLedPin, LOW);
vfdLedActive = false;
}
}
if (vfdLedActive && currentTime >= vfdLedTimer) {
digitalWrite(vfdLedPin, HIGH);
}
}

// Function to handle the screen logic (mode switch and push-to-read switch)
void handleScreenLogic() {
int pushToReadState = digitalRead(pushToReadPin);
int modeSwitchState = digitalRead(modeSwitchPin);

unsigned long currentTime = millis();

if (modeSwitchState != lastModeSwitchState) {
lastDebounceTime = currentTime;
}

if ((currentTime - lastDebounceTime) > debounceDelay && modeSwitchState == LOW &&


!modeSwitchPressed) {
modeSwitchPressed = true;
isInThresholdMode = !isInThresholdMode;
delay(300);
} else if (modeSwitchState == HIGH) {
modeSwitchPressed = false;
}

lastModeSwitchState = modeSwitchState;

if (pushToReadState == LOW) {
displayPressureScreen = true;
} else {
displayPressureScreen = false;
}

if (isInThresholdMode) {
highThreshold = (analogRead(highThresholdPin) * (6.0 / 1023.0));
lowThreshold = (analogRead(lowThresholdPin) * (6.0 / 1023.0));
}
}

// Function to handle the original pump logic (correct pump cycling and stop order)
void handleOriginalPumpLogic() {
int currentInputState = digitalRead(inputPin);
unsigned long currentTime = millis();

if (currentInputState == HIGH && !pump1On && !pump2On && !pump3On) {


startTime = currentTime;
pump1On = true;
Serial.println("Pump sequence started.");
}

// Correct pump sequence logic restored


int pumpOrder[3];
switch (cycleCount % 3) {
case 0:
pumpOrder[0] = pump1Pin; // Cycle 1: Pump 1 → Pump 2 → Pump 3
pumpOrder[1] = pump2Pin;
pumpOrder[2] = pump3Pin;
break;
case 1:
pumpOrder[0] = pump2Pin; // Cycle 2: Pump 2 → Pump 3 → Pump 1 (Corrected)
pumpOrder[1] = pump3Pin;
pumpOrder[2] = pump1Pin;
break;
case 2:
pumpOrder[0] = pump3Pin; // Cycle 3: Pump 3 → Pump 1 → Pump 2
pumpOrder[1] = pump1Pin;
pumpOrder[2] = pump2Pin;
break;
}

// Pump ON logic
if (pump1On && (currentTime - startTime >= delayDuration)) {
digitalWrite(pumpOrder[0], HIGH); // Turn ON the first pump in the order
Serial.println("First Pump ON");
}

if (pump1On && !pump2On && (currentTime - startTime >= delayDuration * 2)) {


digitalWrite(pumpOrder[1], HIGH); // Turn ON the second pump in the order
pump2On = true;
Serial.println("Second Pump ON");
}

if (pump2On && !pump3On && (currentTime - startTime >= delayDuration * 3)) {


digitalWrite(pumpOrder[2], HIGH); // Turn ON the third pump in the order
pump3On = true;
Serial.println("Third Pump ON");
}

// Correct pump OFF logic: pumps stop in the same order they started
if (currentInputState == LOW && (pump1On || pump2On || pump3On)) {
if (pump1On) {
digitalWrite(pumpOrder[0], LOW); // Turn OFF the first pump in the order
pump1On = false;
Serial.println("First Pump OFF");
updateLCD(); // Update LCD in real-time
delay(closeDelay);
}

if (pump2On) {
digitalWrite(pumpOrder[1], LOW); // Turn OFF the second pump in the order
pump2On = false;
Serial.println("Second Pump OFF");
updateLCD(); // Update LCD in real-time
delay(closeDelay);
}

if (pump3On) {
digitalWrite(pumpOrder[2], LOW); // Turn OFF the third pump in the order
pump3On = false;
Serial.println("Third Pump OFF");
updateLCD(); // Update LCD in real-time
delay(closeDelay);
}

cycleCount = (cycleCount + 1) % 3; // Increment cycleCount for the next cycle


startTime = currentTime;
}
}
// Function to update the LCD display based on mode and screen toggling
void updateLCD() {
lcd.clear();

if (isInThresholdMode) {
lcd.setCursor(0, 0);
lcd.print("Set Pressure Limits");

lcd.setCursor(0, 1);
lcd.print("High Threshold: ");
lcd.print(highThreshold, 2);

lcd.setCursor(0, 2);
lcd.print("Low Threshold: ");
lcd.print(lowThreshold, 2);

lcd.setCursor(0, 3);
lcd.print("Press Mode to Exit");
} else if (displayPressureScreen) {
lcd.setCursor(0, 0);
lcd.print("PRESSURE: ");
lcd.print(smoothedPressure, 2);

lcd.setCursor(0, 1);
lcd.print("PUMP1=");
lcd.print(digitalRead(pump1Pin) == HIGH ? "ON " : "OFF");

lcd.setCursor(10, 1);
lcd.print("PUMP2=");
lcd.print(digitalRead(pump2Pin) == HIGH ? "ON " : "OFF");

lcd.setCursor(0, 2);
lcd.print("PUMP3=");
lcd.print(digitalRead(pump3Pin) == HIGH ? "ON " : "OFF");

lcd.setCursor(10, 3);
lcd.write(byte(1));
lcd.setCursor(11, 3);
lcd.print("RIK & SUBHRO");
} else {
lcd.setCursor(0, 0);
lcd.print("*******COSMOS*******");

lcd.setCursor(0, 1);
lcd.print("PUMP PLC T5 ROSEDALE");

lcd.setCursor(0, 2);
lcd.print("PUMP1=");
lcd.print(digitalRead(pump1Pin) == HIGH ? "ON " : "OFF");

lcd.setCursor(10, 2);
lcd.print("PUMP2=");
lcd.print(digitalRead(pump2Pin) == HIGH ? "ON " : "OFF");

lcd.setCursor(0, 3);
lcd.print("PUMP3=");
lcd.print(digitalRead(pump3Pin) == HIGH ? "ON " : "OFF");
lcd.setCursor(10, 3);
lcd.write(byte(0));
lcd.setCursor(11, 3);

unsigned long elapsedSeconds = (millis() - startTime) / 1000;


unsigned int hours = elapsedSeconds / 3600;
unsigned int minutes = (elapsedSeconds % 3600) / 60;
unsigned int seconds = elapsedSeconds % 60;
char timeBuffer[9];
snprintf(timeBuffer, sizeof(timeBuffer), "%02u:%02u:%02u", hours, minutes,
seconds);
lcd.print(timeBuffer);
}
}

THIS IS FULLY FINAL VERSION WITH PRESSURE CORRECTION.

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const int inputPin = 6;


const int pump1Pin = 8;
const int pump2Pin = 9;
const int pump3Pin = 10;
const int controlLedPin = 7;
const int pushToReadPin = 13;
const int modeSwitchPin = A2;
const int lowPressureLedPin = A5;
const int vfdLedPin = A1;

const int highThresholdPin = A3;


const int lowThresholdPin = A4;

const unsigned long delayDuration = 10000; // 10 seconds


const unsigned int closeDelay = 3500; // 3.5 seconds delay during shutdown
const unsigned long debounceDelay = 200; // 200ms debounce for mode switch

unsigned long startTime;


bool pump1On = false;
bool pump2On = false;
bool pump3On = false;

unsigned long controlLedTimer = 0;


bool controlLedActive = false;
bool controlLedTurnedOff = false;

unsigned long vfdLedTimer = 0;


bool vfdLedActive = false;

unsigned long lastLcdUpdate = 0;


const unsigned long lcdUpdateInterval = 200;
int cycleCount = 0;

unsigned long lastDebounceTime = 0;


int lastModeSwitchState = HIGH;
bool modeSwitchPressed = false;
bool isInThresholdMode = false;

float highThreshold = 3.0;


float lowThreshold = 1.0;
bool lowPressureLedOn = false;
bool displayPressureScreen = false;

float pressureReadings[10]; // Array for moving average filter


int pressureIndex = 0;
float smoothedPressure = 0;

void setup() {
pinMode(inputPin, INPUT);
pinMode(pump1Pin, OUTPUT);
pinMode(pump2Pin, OUTPUT);
pinMode(pump3Pin, OUTPUT);
pinMode(controlLedPin, OUTPUT);
pinMode(pushToReadPin, INPUT_PULLUP);
pinMode(modeSwitchPin, INPUT_PULLUP);
pinMode(lowPressureLedPin, OUTPUT);
pinMode(vfdLedPin, OUTPUT);

lcd.begin(20, 4);

byte clockIcon[8] = {
B11111, B01110, B01110, B00100,
B01110, B01110, B11111, B11111
};
lcd.createChar(0, clockIcon);

byte newIcon[8] = {
B11111, B11111, B01110, B00100,
B01110, B11111, B11111, B01110
};
lcd.createChar(1, newIcon);

digitalWrite(pump1Pin, LOW);
digitalWrite(pump2Pin, LOW);
digitalWrite(pump3Pin, LOW);
digitalWrite(controlLedPin, LOW);
digitalWrite(lowPressureLedPin, LOW);
digitalWrite(vfdLedPin, LOW);

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


pressureReadings[i] = 0;
}

Serial.begin(9600);
}

void loop() {
unsigned long currentTime = millis();

handlePressureLogic();
handleScreenLogic();
handleControlLedLogic(currentTime);
handleVfdLedLogic(currentTime);
handleOriginalPumpLogic();

if (currentTime - lastLcdUpdate >= lcdUpdateInterval) {


lastLcdUpdate = currentTime;
updateLCD();
}
}

// Function to handle pressure threshold and LED logic on A5


void handlePressureLogic() {
// Corrected multiplier for accurate pressure reading (0-6 BAR sensor)
float currentPressure = (analogRead(A0) * (6.0 / 1023.0)); // Corrected pressure
conversion for 0-6 BAR

// Use moving average filter for smoothing


pressureReadings[pressureIndex] = currentPressure;
pressureIndex = (pressureIndex + 1) % 10;

float pressureSum = 0;
for (int i = 0; i < 10; i++) {
pressureSum += pressureReadings[i];
}

smoothedPressure = pressureSum / 10; // Moving average

// If pumps are running, apply additional filtering to stabilize pressure


readings
if (digitalRead(inputPin) == HIGH) {
smoothedPressure = smoothedPressure * 0.95; // Apply extra filtering when
pumps are running
}

// Control Low Pressure LED (A5) based on thresholds


if (smoothedPressure < lowThreshold && !lowPressureLedOn) {
digitalWrite(lowPressureLedPin, HIGH); // Turn on the low-pressure LED
lowPressureLedOn = true;
} else if (smoothedPressure > highThreshold && lowPressureLedOn) {
digitalWrite(lowPressureLedPin, LOW); // Turn off the low-pressure LED
lowPressureLedOn = false;
}
}

// Function to handle Control LED (Pin 7) logic


void handleControlLedLogic(unsigned long currentTime) {
int inputState = digitalRead(inputPin);

if (inputState == HIGH && !controlLedActive) {


controlLedTimer = currentTime + 3000;
controlLedActive = true;
}

if (inputState == LOW && controlLedActive && !controlLedTurnedOff) {


controlLedTurnedOff = true;
controlLedTimer = currentTime;
}
if (controlLedTurnedOff && currentTime - controlLedTimer >= 3000) {
digitalWrite(controlLedPin, LOW);
controlLedTurnedOff = false;
controlLedActive = false;
}

if (controlLedActive && currentTime >= controlLedTimer && inputState == HIGH) {


digitalWrite(controlLedPin, HIGH);
}
}

// Function to handle VFD LED (Pin A1) logic


void handleVfdLedLogic(unsigned long currentTime) {
if ((pump1On || pump2On || pump3On) && !vfdLedActive) {
vfdLedTimer = currentTime + 5000;
vfdLedActive = true;
}

if (!pump1On && !pump2On && !pump3On && vfdLedActive) {


if (currentTime - vfdLedTimer >= 5000) {
digitalWrite(vfdLedPin, LOW);
vfdLedActive = false;
}
}

if (vfdLedActive && currentTime >= vfdLedTimer) {


digitalWrite(vfdLedPin, HIGH);
}
}

// Function to handle the screen logic (mode switch and push-to-read switch)
void handleScreenLogic() {
int pushToReadState = digitalRead(pushToReadPin);
int modeSwitchState = digitalRead(modeSwitchPin);

unsigned long currentTime = millis();

if (modeSwitchState != lastModeSwitchState) {
lastDebounceTime = currentTime;
}

if ((currentTime - lastDebounceTime) > debounceDelay && modeSwitchState == LOW &&


!modeSwitchPressed) {
modeSwitchPressed = true;
isInThresholdMode = !isInThresholdMode;
delay(300);
} else if (modeSwitchState == HIGH) {
modeSwitchPressed = false;
}

lastModeSwitchState = modeSwitchState;

if (pushToReadState == LOW) {
displayPressureScreen = true;
} else {
displayPressureScreen = false;
}

if (isInThresholdMode) {
highThreshold = (analogRead(highThresholdPin) * (6.0 / 1023.0));
lowThreshold = (analogRead(lowThresholdPin) * (6.0 / 1023.0));
}
}
// Function to handle the original pump logic (correct pump cycling and stop order)
void handleOriginalPumpLogic() {
int currentInputState = digitalRead(inputPin);
unsigned long currentTime = millis();

if (currentInputState == HIGH && !pump1On && !pump2On && !pump3On) {


startTime = currentTime;
pump1On = true;
Serial.println("Pump sequence started.");
}

// Correct pump sequence logic restored


int pumpOrder[3];
switch (cycleCount % 3) {
case 0:
pumpOrder[0] = pump1Pin; // Cycle 1: Pump 1 → Pump 2 → Pump 3
pumpOrder[1] = pump2Pin;
pumpOrder[2] = pump3Pin;
break;
case 1:
pumpOrder[0] = pump2Pin; // Cycle 2: Pump 2 → Pump 3 → Pump 1
pumpOrder[1] = pump3Pin;
pumpOrder[2] = pump1Pin;
break;
case 2:
pumpOrder[0] = pump3Pin; // Cycle 3: Pump 3 → Pump 1 → Pump 2
pumpOrder[1] = pump1Pin;
pumpOrder[2] = pump2Pin;
break;
}

// Pump ON logic
if (pump1On && (currentTime - startTime >= delayDuration)) {
digitalWrite(pumpOrder[0], HIGH); // Turn ON the first pump in the order
Serial.println("First Pump ON");
}

if (pump1On && !pump2On && (currentTime - startTime >= delayDuration * 2)) {


digitalWrite(pumpOrder[1], HIGH); // Turn ON the second pump in the order
pump2On = true;
Serial.println("Second Pump ON");
}

if (pump2On && !pump3On && (currentTime - startTime >= delayDuration * 3)) {


digitalWrite(pumpOrder[2], HIGH); // Turn ON the third pump in the order
pump3On = true;
Serial.println("Third Pump ON");
}

// Correct pump OFF logic: pumps stop in the same order they started
if (currentInputState == LOW && (pump1On || pump2On || pump3On)) {
if (pump1On) {
digitalWrite(pumpOrder[0], LOW); // Turn OFF the first pump in the order
pump1On = false;
Serial.println("First Pump OFF");
updateLCD(); // Update LCD in real-time
delay(closeDelay);
}
if (pump2On) {
digitalWrite(pumpOrder[1], LOW); // Turn OFF the second pump in the order
pump2On = false;
Serial.println("Second Pump OFF");
updateLCD(); // Update LCD in real-time
delay(closeDelay);
}

if (pump3On) {
digitalWrite(pumpOrder[2], LOW); // Turn OFF the third pump in the order
pump3On = false;
Serial.println("Third Pump OFF");
updateLCD(); // Update LCD in real-time
delay(closeDelay);
}

cycleCount = (cycleCount + 1) % 3; // Increment cycleCount for the next cycle


startTime = currentTime;
}
}

// Function to update the LCD display based on mode and screen toggling
void updateLCD() {
lcd.clear();

if (isInThresholdMode) {
lcd.setCursor(0, 0);
lcd.print("Set Pressure Limits");

lcd.setCursor(0, 1);
lcd.print("High Threshold: ");
lcd.print(highThreshold, 2);

lcd.setCursor(0, 2);
lcd.print("Low Threshold: ");
lcd.print(lowThreshold, 2);

lcd.setCursor(0, 3);
lcd.print("Press Mode to Exit");
} else if (displayPressureScreen) {
lcd.setCursor(0, 0);
lcd.print("PRESSURE: ");
lcd.print(smoothedPressure, 2);

lcd.setCursor(0, 1);
lcd.print("PUMP1=");
lcd.print(digitalRead(pump1Pin) == HIGH ? "ON " : "OFF");

lcd.setCursor(10, 1);
lcd.print("PUMP2=");
lcd.print(digitalRead(pump2Pin) == HIGH ? "ON " : "OFF");

lcd.setCursor(0, 2);
lcd.print("PUMP3=");
lcd.print(digitalRead(pump3Pin) == HIGH ? "ON " : "OFF");

lcd.setCursor(10, 3);
lcd.write(byte(1));
lcd.setCursor(11, 3);
lcd.print("RIK & SUBHRO");
} else {
lcd.setCursor(0, 0);
lcd.print("*******COSMOS*******");

lcd.setCursor(0, 1);
lcd.print("PUMP PLC T5 ROSEDALE");

lcd.setCursor(0, 2);
lcd.print("PUMP1=");
lcd.print(digitalRead(pump1Pin) == HIGH ? "ON " : "OFF");

lcd.setCursor(10, 2);
lcd.print("PUMP2=");
lcd.print(digitalRead(pump2Pin) == HIGH ? "ON " : "OFF");

lcd.setCursor(0, 3);
lcd.print("PUMP3=");
lcd.print(digitalRead(pump3Pin) == HIGH ? "ON " : "OFF");

lcd.setCursor(10, 3);
lcd.write(byte(0));
lcd.setCursor(11, 3);

unsigned long elapsedSeconds = (millis() - startTime) / 1000;


unsigned int hours = elapsedSeconds / 3600;
unsigned int minutes = (elapsedSeconds % 3600) / 60;
unsigned int seconds = elapsedSeconds % 60;
char timeBuffer[9];
snprintf(timeBuffer, sizeof(timeBuffer), "%02u:%02u:%02u", hours, minutes,
seconds);
lcd.print(timeBuffer);
}
}

You might also like