#include <SoftwareSerial.h>
const int Tempsensor = A0; // connect output pin of Im35 to A0 pin of Arduino
const int bluetoothTx = 10; // connect TX of Bluetooth to 10th pin
const int bluetoothRx = 11; // connect RX of Bluetooth to 11th pin
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup() {
pinMode(Tempsensor, INPUT);
pinMode(3, OUTPUT); // blue pin of RGB LED
pinMode(4, OUTPUT); // green pin of RGB LED
pinMode(5, OUTPUT); // red pin of RGB LED
Serial.begin(9600); // serial communication begins
bluetooth.begin(9600); // Bluetooth communication begins
}
void loop() {
float temp = analogRead(Tempsensor); // read temperature sensor voltage
temp = temp * 0.48828125; // (5 * 1000) / 1024 = 0.48828125 from sensor data sheet
Serial.println(" ");
Serial.println(temp); // watch the current temperature in serial monitor
bluetooth.print(" ");
bluetooth.println(temp); // send temperature to Bluetooth device
delay(200);
if (temp <= 30) { // if temperature is below or equal to 30, turn on blue light
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
}
else if (temp > 30 && temp <= 34) { // if temp is above 30 and below or equal to 34, turn on green light
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
}
else if (temp > 36) { // if temperature is above 34, turn on red light
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
}
}