Arduino Temperature Sensor Code

About: I LOVE ELECTRONICS AND ROCKETS!

// 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 :)

Share

    Recommendations

    • Optics Contest

      Optics Contest
    • Make it Glow Contest 2018

      Make it Glow Contest 2018
    • Plastics Contest

      Plastics Contest

    3 Discussions

    0
    None
    imaginamerica

    1 year ago

    Hello, Would this code work in an Arduino Nano?