is there any something wrong with the code?
#include <LiquidCrystal.h>
// Constants
const int LM35_PIN = A0; // Analog pin for LM35 temperature sensor
const int MQ2_PIN = A1; // Analog pin for MQ2 smoke sensor
const int RELAY_PIN = 9; // Digital pin for relay module
// Variables
float temperature = 0.0; // Temperature in degrees Celsius
int smokeValue = 0; // Smoke value from 0 to 1023
float fanSpeed = 0.0; // Fan speed adjustment (0.0 to 1.0)
// Initialize LCD
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
void setup() {
// Initialize Serial communication
Serial.begin(9600);
// Initialize LCD
lcd.begin(16, 2);
lcd.print("Temp: Smoke:");
// Set fan and water pump pins as output
pinMode(fanPin, OUTPUT);
pinMode(waterPumpPin, OUTPUT);
// Turn off the fan and water pump initially
analogWrite(fanPin, 0);
digitalWrite(waterPumpPin, LOW);
}
void loop() {
// Read temperature from LM35 sensor
int lm35Value = analogRead(lm35Pin);
temperature = (lm35Value * 5.0 / 1023.0) * 100.0;
// Read smoke sensor value
int smokeValue = analogRead(smokePin);
// Display temperature and smoke sensor values on LCD
lcd.setCursor(5, 0);
lcd.print(temperature);
lcd.print("C");
lcd.setCursor(12, 0);
lcd.print(smokeValue);
// Check smoke threshold
if (smokeValue > 50) {
digitalWrite(RELAY_PIN, HIGH); // Turn on the relay
// Code to control water pump goes here
} else {
digitalWrite(RELAY_PIN, LOW); // Turn off the relay
// Code to control water pump goes here
}
// Check if temperature exceeds 50 degrees Celsius
if (temperature > 50 ) {
// Start the fan with the specified speed
analogWrite(fanPin, fanSpeed / 100.0 * 255);
}
// Print temperature and smoke sensor values to Serial Monitor
Serial.print("Temp: ");
Serial.print(temperature);
Serial.print("C Smoke: ");
Serial.println(smokeValue);
// Delay between readings
delay(1000);
}