Week 10 Production Assignment – Tea Temperature

For this week’s production assignment I wanted to experiment with a component that I have not yet used. The one component I had in mind for this was the temperature sensor. As I enjoy drinking tea, I decided to implement a circuit which gauges the presence and temperature of a liquid.

In order to do this, I created a series of if statements that test the temperature read by the sensor. While the technical aspect of this was manageable, the practical side was challenging. This was due to the unreliability of the sensor as it would read fluctuating and incorrect temperatures. Despite this, I was able to get some successful examples by restarting the circuit (and therefore restarting the sensor’s input). This is seen in the example below. The if statements are included below as well.

const int rgbRED_PIN = 9;//the digital pin for red pin
const int rgbGREEN_PIN = 10;//the digital pin for green pin
const int rgbBLUE_PIN = 11;//the digital pin for blue pin
const int temperaturePin = 0;//the analog read pin that is used to reat the temperature 
const int waterPin = 12;  
const int greenLED_Pin = 13;
 
void setup()
{
 
  pinMode(rgbRED_PIN, OUTPUT);
  pinMode(rgbGREEN_PIN, OUTPUT);
  pinMode(rgbBLUE_PIN, OUTPUT);
  pinMode(waterPin, INPUT);
  pinMode(greenLED_Pin, OUTPUT);
  Serial.begin(9600);//the bound rate for serial monitor 
  
}
 
 
void loop()
{
 
   int waterDetected = digitalRead(waterPin);
     if (waterDetected == HIGH) {
    digitalWrite(greenLED_Pin, HIGH);
  } else {
    digitalWrite(greenLED_Pin, LOW);
  }

  float voltage, degreesC, degreesF;//get numbers with decimals 
 
  voltage = getVoltage(temperaturePin);//get voltage from the temperature pin
  degreesC = (voltage - 0.5) * 100.0;//calculate the celcius degree
  degreesF = degreesC * (9.0/5.0) + 32.0;// calculate the Fahrenheit degree
 
  Serial.print("voltage: ");//print volrage in serial monitor
  Serial.print(voltage);
  Serial.print("  deg C: ");//print the celcious degree in serial monitor
  Serial.println(degreesC);
 
 
  if (degreesC < 23) //if the temperature is less than 23 degrees C turn off RGB
  {
  // Off (all LEDs off):
    digitalWrite(rgbRED_PIN, LOW);
    digitalWrite(rgbGREEN_PIN, LOW);
    digitalWrite(rgbBLUE_PIN, LOW);
  }
 
  
if (degreesC >= 24)//if the temperature is larger than 24 degrees C show purple
  {
  digitalWrite(rgbRED_PIN, HIGH);
  digitalWrite(rgbGREEN_PIN, LOW);
  digitalWrite(rgbBLUE_PIN, HIGH);
  }
}
 
 
 
float getVoltage(int pin)//get voltage 
 
 {
  return (analogRead(pin) * 0.004882814);// conver 0 to 1023 value to 0 to 5 value (the true voltage)
 }

 

One point that I could not manage was the water detection aspect which I wanted to incorporate into this circuit. I attempted to do so by connecting alligator clips into a cup of water in order to complete the circuit. The LED would flicker occasionally but would not stay on consistently. I am unsure whether this is due to the connection of the alligator clips (other examples I have seen use regular wires) or because of the way I had wired the circuit itself.

Leave a Reply