For this homework, I decided to make a circuit connected with temperature sensor(TMP36).
I set the code to make the raw value of the analog sensor, voltage, temperature in C, and temperature in F be printed in serial monitor.
Also I connected RGB led to the circuit in order to turn the red-light when the temperature C is over 26, blue-light when the temperature C is under 24,
and green-light in between.
int i;
void setup() {
Serial.begin(9600);
for ( i = 5 ; i <= 7 ; i++) {
pinMode(i, OUTPUT);
}
}
float rawValue, voltage, tempC, tempF;
void loop() {
rawValue = analogRead(A0);
voltage = (rawValue / 1023.0) * 5000;
tempC = (voltage - 500) * 0.1;
tempF = (tempC * 1.8) + 32;
Serial.print("RawValue : ");
Serial.print(rawValue);
Serial.print("\t milli volts : ");
Serial.print(voltage);
Serial.print("\t Temperature in C : ");
Serial.print(tempC);
Serial.print(" C");
Serial.print("\t Temperature in F : ");
Serial.print(tempF);
Serial.print(" F");
Serial.println();
if (tempC > 26.00) {
digitalWrite(7, HIGH);
delay(1000);
digitalWrite(7, LOW);
}
else if (tempC < 24.00) {
digitalWrite(5, HIGH);
delay(1000);
digitalWrite(5, LOW);
}
else {
digitalWrite(6, HIGH);
delay(1000);
digitalWrite(6, LOW);
}
delay(1);
}