Solenoid Pressure Controller LCD Cycle Counter

I seem to be encountering an interesting issue with using an LCD to display the cycle count in a pressure cycle controller. I am using an arduino UNO, a solenoid, a relay, and a pressure transducer to pressure cycle some parts. Parts pressurize to a high setpoint and then the solenoid is triggered and the parts vent to a low setpoint. For every pressure cycle a variable called cycleCount is increased by one. The issue I am running into is with displaying the cycle count on the LCD. The issue seems to be random, but after 30,000+ cycles the LCD goes blank. The screen is still backlit but nothing is being displayed. The solenoid is still opening and closing and the code seems to still be working as it should but the cycle count display disappears. I've tried unplugging the LCD and plugging it in again but still nothing shows up. When I reset the Arduino the cycle count properly displays again and everything runs fine. This has happened twice when the cycle count got above 30,0000-40,0000 cycles. Any ideas?

#include "rgb_lcd.h"  // Include the LiquidCrystal library

rgb_lcd lcd;

const int solenoidPin = 7;   // Initialize the solenoid relay trigger on pin 2
const int pressurePin = A0;  //Initialize the pressure sensor input on pin A0
int setpointLow = 260.00;   // ~13 psi setpoint
int setpointHigh = 900.00;  // ~90 psi setpoint
long unsigned int cycleCount = 0;         //initialize cycle counter to zero

void setup() {
  pinMode(solenoidPin, OUTPUT);  //pin 7 is an output
  pinMode(pressurePin, INPUT);   //pin A0 is an input
  Serial.begin(9600);
  lcd.begin(16, 2);            // Initialize the LCD with 16 columns and 2 rows
  lcd.print("Cycles: ");  // Display "Cycle Count" on the first row of the LCD
  lcd.setCursor(8, 0);    // Set the cursor to the first row, eighth column of the LCD
  lcd.print(cycleCount);  // Display the cycle count 
}

void loop() {
  float pressure = (analogRead(pressurePin));
  Serial.print(pressure);
  Serial.println(" mV");
  

  if (pressure < setpointLow && cycleCount < 50000) {       // Check if pressure is below 13 psi
    digitalWrite(solenoidPin, HIGH);  //open solenoid if less than 13 psi to pressurize unit

  } else if (pressure > setpointHigh && cycleCount < 50000) {    // Check if pressure is above 90 psi
    if (digitalRead(solenoidPin) == HIGH) { //Open the solenoiss
      cycleCount++;  //add one to the cycle count
      lcd.setCursor(8, 0);    // Set the cursor to the eighth column of the LCD
      lcd.print(cycleCount);  // Display the cycle count on the LCD
    }
    digitalWrite(solenoidPin, LOW);

  } else if (cycleCount >= 50000) {
    digitalWrite(solenoidPin, LOW);
  }
}

presumably you know that the range of an in is -32768-32767 and is why you made cycleCount an unsigned long.

wonder if your lcd library is handling it properly

why don't you try some simple experiments and just try displaying values in that range from setup()

I tried counting up to 100000 with the LCD_I2C library using an unsigned long and it works OK.
So it must be an rgb_lcd library problem.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.