//#define POT_PIN A0 // Pin where the potentiometer is connected (for simulation)
#define RELAY_IN1_PIN 5 // Pin to control Relay IN1 (Red LED)
#define RELAY_IN2_PIN 6 // Pin to control Relay IN2 (Green LED)
void setup() {
Serial.begin(115200); // Initialize serial communication
pinMode(RELAY_IN1_PIN, OUTPUT);
pinMode(RELAY_IN2_PIN, OUTPUT);
Serial.println("Poultry Farm Temperature Control System");
}
void loop() {
// Simulate temperature reading using a potentiometer or random value
float temperature = simulateTemperature();
// Print temperature to Serial Monitor
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
// Control logic
if (temperature > 35) {
digitalWrite(RELAY_IN1_PIN, HIGH); // Turn on Red LED (Relay IN1)
digitalWrite(RELAY_IN2_PIN, LOW); // Turn off Green LED (Relay IN2)
Serial.println("Temperature is too high! Cooling system would be activated.");
} else {
digitalWrite(RELAY_IN1_PIN, LOW); // Turn off Red LED (Relay IN1)
digitalWrite(RELAY_IN2_PIN, HIGH); // Turn on Green LED (Relay IN2)
Serial.println("Temperature is optimal. Cooling system would be deactivated.");
}
delay(2000); // Wait 2 seconds before next reading
}
// Function to simulate temperature reading
float simulateTemperature() {
// Option 1: Use a potentiometer to simulate temperature
int potValue = analogRead(POT_PIN); // Read potentiometer value (0 to 1023)
float temperature = map(potValue, 0, 1023, 20, 40); // Map to temperature range (20°C to 40°C)
// Option 2: Use a random value to simulate temperature
// float temperature = random(20, 40); // Random temperature between 20°C and 40°C
return temperature;
}