// Arduino Temperature Gauge // Written by Josh Leyte-Jammu // Written on 2015 02 19 // Declare program variables const int tempSensorPin = A0; // Declare the analog pin that reads the temperature sensor // Declare program constants const float setTempC = 21.0; // Degrees Celsius set to 21 (general room temperature) void setup() { // put your setup code here, to run once: Serial.begin(9600); // Open a serial port at 9600 bits per second. for(int pinNumber = 2; pinNumber<5; pinNumber++){ // Run through digital pins 2, 3, and 4 sequentially. pinMode(pinNumber,OUTPUT); digitalWrite(pinNumber,LOW); } } void loop() { // put your main code here, to run repeatedly: int tempSensorVal = analogRead(tempSensorPin); float voltage = (tempSensorVal/1024.0)*5.0; // Convert the ADC reading into voltage. Voltage on the pin will be between 0 and 5 Volts. Serial.print("The temperature in degrees Celcius is "); float tempC = (voltage - 0.5)*100; // Convert the calculated voltage into degrees Celsius. Serial.println(tempC); // Print the temperature in degrees Celsius. Create a new line after. if(tempC < setTempC-1.5){ digitalWrite(2,HIGH); // Blue LED ON digitalWrite(3,LOW); // Green LED OFF digitalWrite(4,LOW); // Red LED OFF }else if(tempC >= setTempC-1.5 && tempC < setTempC-0.5){ digitalWrite(2,HIGH); // Blue LED ON digitalWrite(3,HIGH); // Green LED ON digitalWrite(4,LOW); // Red LED OFF }else if(tempC >= setTempC-0.5 && tempC < setTempC+0.5){ digitalWrite(2,LOW); // Blue LED OFF digitalWrite(3,HIGH); // Green LED ON digitalWrite(4,LOW); // Red LED OFF }else if(tempC >= setTempC+0.5 && tempC < setTempC+1.5){ digitalWrite(2,LOW); // Blue LED OFF digitalWrite(3,HIGH); // Green LED ON digitalWrite(4,HIGH); // Red LED ON }else if(tempC > setTempC+1.5){ digitalWrite(2,LOW); // Blue LED OFF digitalWrite(3,LOW); // Green LED OFF digitalWrite(4,HIGH); // Red LED ON } delay(1000); // Delay by one second. }