Introduction: Arduino Temperature Sensor Code

// All Rights reserved :) Kiduino

const int sensorPin = A0; const float baselineTemp = 28.0;

void setup() { Serial.begin(9600); for (int pinNumber = 2; pinNumber < 12; pinNumber++) { pinMode(pinNumber, OUTPUT); digitalWrite(pinNumber, LOW); } }

void loop() { int sensorVal = analogRead(sensorPin);

Serial.print("sensor Value: "); Serial.print(sensorVal); // convert the ADC reading to voltage float voltage = (sensorVal / 1024.0) * 5.0;

Serial.print(", Volts: "); Serial.print(voltage); Serial.print(", degrees C: "); float temperature = (voltage - .5) * 100; Serial.println(temperature);

if (temperature < baselineTemp + 0.5) { digitalWrite(2, LOW); digitalWrite(3, LOW); digitalWrite(5, LOW); digitalWrite(8, LOW); digitalWrite(12, LOW); } else if (temperature >= baselineTemp + 0.5 && temperature < baselineTemp + 1) { digitalWrite(2, HIGH); digitalWrite(3, LOW); digitalWrite(4, LOW); digitalWrite(5, LOW); digitalWrite(8, LOW); digitalWrite(12, LOW); } else if (temperature >= baselineTemp + 1 && temperature < baselineTemp + 1.5) { digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(5, LOW); digitalWrite(8, LOW); digitalWrite(12, LOW); } else if (temperature >= baselineTemp + 1.5 && temperature < baselineTemp + 2) { digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(5, HIGH); digitalWrite(8, LOW); digitalWrite(12, LOW); } else if (temperature >= baselineTemp + 2 && temperature < baselineTemp + 2.25) { digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(5, HIGH); digitalWrite(8, LOW); digitalWrite(12, LOW); } else if (temperature >= baselineTemp + 2.25 && temperature < baselineTemp + 2.50) { digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(5, HIGH); digitalWrite(8, HIGH); digitalWrite(12, LOW); } else if (temperature >= baselineTemp + 2.50 && temperature < baselineTemp + 2.80) { digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(5, HIGH); digitalWrite(8, HIGH); digitalWrite(12, HIGH); } delay(1); }

Step 1: Instructions

For the instructions watch the video :)

Comments

author
imaginamerica (author)2017-05-25

Hello, Would this code work in an Arduino Nano?

author
DIY Hacks and How Tos (author)2015-08-07

Interesting project. You can actually embed youtube videos in you instructable using the embed video tool when editing a step.

author

Thanks, im all new to this!

About This Instructable

633views

13favorites

License:

Bio: I LOVE ELECTRONICS AND ROCKETS!
More by officialKiduino:Control a LCD with ArduinoArduino Temperature Sensor Code
Add instructable to: