// Pin Definitions
const int tempSensorPin = A0; // Analog pin for temperature sensor (e.g., LM35)
const int pirSensorPin = 2; // Digital pin for PIR motion sensor
const int relayPin = 8; // Digital pin for relay control (bulb ON/OFF)
// Variables
float temperature = 0.0; // To store temperature value
bool motionDetected = false; // To store PIR motion status
void setup() {
pinMode(pirSensorPin, INPUT); // PIR sensor input
pinMode(relayPin, OUTPUT); // Relay output control
Serial.begin(9600); // Start serial monitor
}
void loop() {
// Read Temperature Sensor (e.g., LM35 gives 10mV/°C)
int tempSensorValue = analogRead(tempSensorPin);
temperature = (tempSensorValue * 5.0 / 1023.0) * 100.0; // Convert analog value to °C
// Read PIR Motion Sensor
motionDetected = digitalRead(pirSensorPin);
// Print values to Serial Monitor
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" °C | Motion Detected: ");
Serial.println(motionDetected ? "YES" : "NO");
// Logic to Control the Bulb
if (temperature > 25 && motionDetected) {
digitalWrite(relayPin, HIGH); // Turn ON the bulb
Serial.println("Bulb ON");
} else {
digitalWrite(relayPin, LOW); // Turn OFF the bulb
Serial.println("Bulb OFF");
}
delay(500); // Small delay for stability
}