Hi guys,
I am using and Arudino Nano a With chc430 chip I strongly guess.
It's for an aquaponic system,
The system is suppose to manage pumps, get temperature, humidity, (and later PH, and water temperature, etc).
No String in my code btw.
Every second I increment a counter,
every counter == 0, I open the pump,
every counter == 30, I close the pump,
every counter == 300; I reset the counter and add 1 cycle!
Sometime when the counter == 267 the system stop, it doesn't seems to be connected to cycles since the value is different every time witch is weird
![]()
Can someone help to debug please?
Here is the code:
#include <Wire.h>
// oustside temp
#include "DHT.h"
#define DHTPIN 4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
//screen
#include "rgb_lcd.h"
rgb_lcd lcd;
// master code
const int pinPump=6;
bool pumpIsOpen=false;
unsigned int counter=0;
unsigned int cycleNumber=0;
void loopScreen(unsigned int timeLeft, unsigned int cycleNumber, float humidity, float temperature){
char discplayString[16];
char discplayString2[16];
lcd.clear();
lcd.setCursor(0, 0);
sprintf(discplayString, "H: %d ,T: %d*C", (int)humidity, (int)temperature);
lcd.print(discplayString);
lcd.setCursor(0, 1);
sprintf(discplayString2, "T:%d s,C: %d c", timeLeft, cycleNumber);
lcd.print(discplayString2);
}
void check()
{
const unsigned int timeLeftOpen=32;
const unsigned int cycleTime=300;
if(counter == 0)
{
if(!pumpIsOpen){
digitalWrite(pinPump, LOW);
Serial.println("pump open");
pumpIsOpen = true;
}
}
if(counter >timeLeftOpen)
{
if(pumpIsOpen){
digitalWrite(pinPump, HIGH);
Serial.println("pump stoped");
pumpIsOpen = false;
}
}
float temp_hum_val[2] = {0};
if (!dht.readTempAndHumidity(temp_hum_val))
{
// Humidity
Serial.println(temp_hum_val[0]);
// Temperature
Serial.println(temp_hum_val[1]);
} else {
Serial.println("Failed to get temprature and humidity value.");
}
counter ++;
if(counter>cycleTime)
{
cycleNumber ++;
counter=0;
Serial.println("cycle finished");
}
unsigned int timeLeft = cycleTime - counter;
loopScreen(timeLeft, cycleNumber, temp_hum_val[0], temp_hum_val[1]);
Serial.print("ctn: ");
Serial.print(counter);
Serial.print(",pump: ");
Serial.print(pumpIsOpen);
Serial.print(",humi: ");
Serial.print(temp_hum_val[0]);
Serial.print(",temp: ");
Serial.print(temp_hum_val[1]);
Serial.print(",cyclnb: ");
Serial.print(cycleNumber);
Serial.print("\n");
delay(1000);
}
void setupPump(){
pinMode(pinPump, OUTPUT);
}
void setupScreen(){
const int colorR = 255;
const int colorG = 0;
const int colorB = 0;
lcd.begin(16, 2);
lcd.setRGB(colorR, colorG, colorB);
// Print a message to the LCD.
}
void setupTemp(){
dht.begin();
}
void setup() {
Wire.begin();
Serial.begin(115200);
setupPump();
setupTemp();
setupScreen();
}
void loop()
{
check();
}
Thanks guys for your help


