make a flow chart of this program:
#include <SPI.h>
#include <SD.h>
#include <LiquidCrystal_I2C.h>
#define MOISTURE_PIN A0
#define SOLENOID_PIN 9
// Define the moisture threshold values
const int MOISTURE_THRESHOLD_LOW = 30; // Adjust this value as needed
const int MOISTURE_THRESHOLD_HIGH = 70; // Adjust this value as needed
// Define the LCD connections
#define I2C_ADDR 0x27 // I2C address of the LCD module
#define LCD_COLS 16 // Number of columns in the LCD
#define LCD_ROWS 2 // Number of rows in the LCD
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLS, LCD_ROWS);
const int chipSelect = 10;
unsigned long previousMillis = 0;
const long interval = 1000; // Log interval in milliseconds
void setup() {
Serial.begin(9600);
lcd.begin(LCD_COLS, LCD_ROWS);
lcd.backlight();
pinMode(SOLENOID_PIN, OUTPUT);
digitalWrite(SOLENOID_PIN, HIGH); // Turn off the solenoid valve initially
if (!SD.begin(chipSelect)) {
Serial.println("SD card initialization failed!");
lcd.print("SD Card Error");
while (1);
}
lcd.print("SD Card OK");
delay(2000);
lcd.clear();
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
int moistureValue = analogRead(MOISTURE_PIN);
float moisturePercentage = map(moistureValue, 0, 1023, 0, 100);
String logData = "Moisture: " + String(moisturePercentage, 2) + "%";
Serial.println(logData);
lcd.clear();
lcd.print(logData);
if (moisturePercentage < MOISTURE_THRESHOLD_LOW) {
digitalWrite(SOLENOID_PIN, LOW); // Open the solenoid valve
} else if (moisturePercentage > MOISTURE_THRESHOLD_HIGH) {
digitalWrite(SOLENOID_PIN, HIGH); // Close the solenoid valve
}
File dataFile = SD.open("moisture_log.txt", FILE_WRITE);
if (dataFile) {
dataFile.println(logData);
dataFile.close();
} else {
Serial.println("Error opening data file!");
}
}
}
#include <SPI.h>
#include <SD.h>
#include <LiquidCrystal_I2C.h>
#define MOISTURE_PIN A0
#define SOLENOID_PIN 9
// Define the moisture threshold values
const int MOISTURE_THRESHOLD_LOW = 30; // Adjust this value as needed
const int MOISTURE_THRESHOLD_HIGH = 70; // Adjust this value as needed
// Define the LCD connections
#define I2C_ADDR 0x27 // I2C address of the LCD module
#define LCD_COLS 16 // Number of columns in the LCD
#define LCD_ROWS 2 // Number of rows in the LCD
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLS, LCD_ROWS);
const int chipSelect = 10;
unsigned long previousMillis = 0;
const long interval = 1000; // Log interval in milliseconds
void setup() {
Serial.begin(9600);
lcd.begin(LCD_COLS, LCD_ROWS);
lcd.backlight();
pinMode(SOLENOID_PIN, OUTPUT);
digitalWrite(SOLENOID_PIN, HIGH); // Turn off the solenoid valve initially
if (!SD.begin(chipSelect)) {
Serial.println("SD card initialization failed!");
lcd.print("SD Card Error");
while (1);
}
lcd.print("SD Card OK");
delay(2000);
lcd.clear();
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
int moistureValue = analogRead(MOISTURE_PIN);
float moisturePercentage = map(moistureValue, 0, 1023, 0, 100);
String logData = "Moisture: " + String(moisturePercentage, 2) + "%";
Serial.println(logData);
lcd.clear();
lcd.print(logData);
if (moisturePercentage < MOISTURE_THRESHOLD_LOW) {
digitalWrite(SOLENOID_PIN, LOW); // Open the solenoid valve
} else if (moisturePercentage > MOISTURE_THRESHOLD_HIGH) {
digitalWrite(SOLENOID_PIN, HIGH); // Close the solenoid valve
}
File dataFile = SD.open("moisture_log.txt", FILE_WRITE);
if (dataFile) {
dataFile.println(logData);
dataFile.close();
} else {
Serial.println("Error opening data file!");
}
}
}