finish it

This commit is contained in:
kicap 2024-09-05 12:57:49 +08:00
parent 52b858fdc3
commit 943529058b
1 changed files with 31 additions and 8 deletions

View File

@ -21,11 +21,16 @@ float calibration_value1 = 21.34 + 2.5; // Calibration value for Sensor 1
float calibration_value2 = 21.34 + 3.1; // Calibration value for Sensor 2 float calibration_value2 = 21.34 + 3.1; // Calibration value for Sensor 2
float calibration_value3 = 21.34 + 3.8; // Calibration value for Sensor 3 float calibration_value3 = 21.34 + 3.8; // Calibration value for Sensor 3
#define analogInPinTDS A3 // Analog input pin untuk tds #define analogInPinTDS1 A3 // Analog input pin untuk tds 1
#define analogInPinTDS2 A2 // Analog input pin untuk tds 2
#define analogInPinTDS3 A4 // Analog input pin untuk tds 3
// variable // variable
int sensorValue0; // adc value // int sensorValue0; // adc value
float calibration_value0 = 1203.08; float tds_calibration_value0 = 1203.08;
float tds_calibration_value1 = 1203.08;
float tds_calibration_value2 = 1203.08;
SoftwareSerial mySerial(2, 3); // RX, TX , Software serial from ESP-01 to Arduino SoftwareSerial mySerial(2, 3); // RX, TX , Software serial from ESP-01 to Arduino
@ -179,8 +184,11 @@ void loop()
if (bukaGerbang == true) { if (bukaGerbang == true) {
if (detikGerbang < 2) { // Open for 5 seconds if (detikGerbang < 2) { // Open for 5 seconds
detikGerbang++; detikGerbang++;
digitalWrite(RELAY_PIN_1, HIGH); // Open the gate // digitalWrite(RELAY_PIN_1, LOW); // Ensure both relays are off
digitalWrite(RELAY_PIN_2, LOW); // Ensure the other relay is off // digitalWrite(RELAY_PIN_2, HIGH);
delay(2500);
digitalWrite(RELAY_PIN_1, LOW); // Open the gate
digitalWrite(RELAY_PIN_2, HIGH); // Ensure the other relay is off
} else { // After 5 seconds } else { // After 5 seconds
bukaGerbang = false; bukaGerbang = false;
statusGerbang = "buka"; // Update the status statusGerbang = "buka"; // Update the status
@ -194,8 +202,11 @@ void loop()
if (tutupGerbang == true) { if (tutupGerbang == true) {
if (detikGerbang < 2) { // Close for 5 seconds if (detikGerbang < 2) { // Close for 5 seconds
detikGerbang++; detikGerbang++;
digitalWrite(RELAY_PIN_1, LOW); // Ensure the other relay is off // digitalWrite(RELAY_PIN_1, HIGH); // Ensure both relays are off
digitalWrite(RELAY_PIN_2, HIGH); // Close the gate // digitalWrite(RELAY_PIN_2, HIGH);
delay(2500);
digitalWrite(RELAY_PIN_1, HIGH); // Ensure the other relay is off
digitalWrite(RELAY_PIN_2, LOW); // Close the gate
} else { // After 5 seconds } else { // After 5 seconds
tutupGerbang = false; tutupGerbang = false;
statusGerbang = "tutup"; // Update the status statusGerbang = "tutup"; // Update the status
@ -223,7 +234,9 @@ void loop()
// float phValue2 = processPHsensor(SensorPin2, calibration_value2); // float phValue2 = processPHsensor(SensorPin2, calibration_value2);
// //
float tdsValue1 = tdsReading(analogInPinTDS, calibration_value0); float tdsValue1 = tdsReading(analogInPinTDS1, tds_calibration_value0);
float tdsValue2 = tdsReading(analogInPinTDS2, tds_calibration_value1);
float tdsValue3 = tdsReading(analogInPinTDS3, tds_calibration_value2);
// Print the pH values to the serial monitor // Print the pH values to the serial monitor
@ -245,6 +258,12 @@ void loop()
Serial.print("TDS Value 1: "); Serial.print("TDS Value 1: ");
Serial.println(tdsValue1); Serial.println(tdsValue1);
Serial.print("TDS Value 2: ");
Serial.println(tdsValue2);
Serial.print("TDS Value 3: ");
Serial.println(tdsValue3);
// if (distance1 <= 30) // if (distance1 <= 30)
// { // {
// digitalWrite(RELAY_PIN_1, HIGH); // digitalWrite(RELAY_PIN_1, HIGH);
@ -274,6 +293,10 @@ void loop()
mySerial.print(phValue3); mySerial.print(phValue3);
mySerial.print(","); mySerial.print(",");
mySerial.print(tdsValue1); mySerial.print(tdsValue1);
mySerial.print(",");
mySerial.print(tdsValue2);
mySerial.print(",");
mySerial.print(tdsValue3);
mySerial.print("\n"); mySerial.print("\n");
delay(2000); delay(2000);