The Goldylock’s Thermometer

The ‘Goldylock’s’ thermometer uses a traffic light system to monitor the temperature. It is a simple program that uses the Jaycar XC4520 module to track the temperature in Celsius. Conditional statements output the three LED’s depending on the sensor reading. The serial monitor prints the data and includes a statement from Goldie. Another aspect of this code is that it doesn’t need a library and believe me that’s a good thing.

SHOPPING LIST

1 x Arduino Uno or equivalent

1 x XC4520 temperature module (Keyes K853518)

3 x LED’s (I used 5mm)

3 x 220 ohm resistors (or there abouts)

9 x jumper leads

THE PINOUT

THE CODE

// Goldylocks Thermometer Jaycar XC4494 temperature module

#define sensorPin  A0

#define greenLED 2

#define yellowLED 3

#define redLED 4

void setup()

{

  pinMode(greenLED, OUTPUT);

  pinMode(yellowLED, OUTPUT);

  pinMode(redLED, OUTPUT);

  Serial.begin(9600);

}

void loop()

{

  int reading = analogRead(sensorPin);

  float voltage = reading * 5.0;

  voltage /= 1023.0;

  float temperatureC = (voltage – 0.5) * 10 ;

  Serial.print(temperatureC); Serial.print(“° C “);

  if (temperatureC >= 26) {

    digitalWrite(greenLED, LOW);

    digitalWrite(yellowLED, LOW);

    digitalWrite(redLED, HIGH);

    Serial.println(” Goldylocks says ‘It’s Too Hot’.”);

  }

  else if (temperatureC >= 20 && temperatureC < 26) {

    digitalWrite(greenLED, LOW);

    digitalWrite(yellowLED, HIGH);

    digitalWrite(redLED, LOW);

    Serial.println(” Goldylocks says ‘It’s Just Right’.”);

  }

  else {

    digitalWrite(greenLED, HIGH);

    digitalWrite(yellowLED, LOW);

    digitalWrite(redLED, LOW);

    Serial.println(” Goldylocks says ‘It’s Too Cold’.”);

  }

  delay(1000);

}

NOTES

The parameters can be changed in the code to anything you want, I just thought that this was ‘just right’.

Have fun….

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: