PROJECT Nº 3: Color thermometer

Learn to build and program a color thermometer using the components of the Maker Control Kit and Maker Kit 2.

Use the temperature sensor and the RGB LED to set it up. See how the LED changes color depending on the ambient temperature, according to the colors that the thermometer shows.

DIFFICULTY LEVEL: Beginner.

DURATION OF THE EXERCISE: 45 min.

MATERIALS:

  • 1 RGB LED
  • 1 Temperature sensor
  • 1 4in1 Build&Code circuit
  • 1 USB – Micro USB cable
  • Computer
  • Thermometer stencil
  • Adhesive

What is a temperature sensor?

A temperature sensor is an electronic component that returns a tension value proportional to the temperature to which it is exposed.

In this case, the sensor returns an analog signal with a temperature range from -40ºC to +125ºC and a difference of +/-2ºC.

CONNECTIONS:

  1. Connect the temperature sensor to analog port A0 on the 4in1 Build&Code circuit.
  2. Connect the RGB LED to digital port 6 on the 4in1 Build&Code circuit.

Look at the colors of the cables and the colors of the terminals on the 4in1 Build&Code circuit to guide you. Each cable should be connected to its color:

BUILDING THE STRUCTURE:

Download the thermometer stencil and glue on the various electronic components. Use this image as a reference:

PROGRAMMING CODE:

The program consists of measuring the temperature registered by the temperature sensor and activating the color that corresponds to that value.

We have selected a temperature range that goes from 0ºC to 41ºC, and a variety of 11 colors. To correlate each color with the temperature range to which it corresponds, make the following division:

41ºC (Maximum temperature) / 11 (number of colors) = 3.72ºC degrees between each color

You can do this activity by using Arduino and Bitbloq software, as well as other compatible block programming software. Below you will find the programming code needed for each software.

Arduino Code

  1. Download the Arduino software and go through the installation process.
  2. Add the library for the RGB LED to the Arduino software, following the instructions in the guide “How to add a library to program your RGB LED.”
  3. Open the Arduino program, and once in, copy the following program:
    /*
    R   G   B   TEMP ºC
    255 0   0   41
    244 80  43  37.27
    244 102 26  33.54
    248 147 31  29.81
    243 223 6   26.09
    147 198 45  22.36
    23  173 66  18.63
    40  209 188 14.90
    48  59  175 11.18
    58  33  117 7.45
    105 46  152 3.72
    155 36  152 0
    
    Scale (41ºC max / 11 colors = 3.72)
     */
    int PortTemp = A0; // Temperature sensor -> digital port A0
    float VoltTemp, Temp, ValueTemp; // Temperature sensor voltage, Temperature in ºC, temperature sensor value
    #include <Adafruit_NeoPixel.h>  //LIBRARY RGB LED
    #define PIXEL_PIN 6    //PIN OF THE RGB LED
    #define PIXEL_COUNT 1    // NUMBER OF RGB LEDS
    Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800); // CONFIGURATION OF THE RGB LED
    
    void setup() {
      // put your setup code here, to run once:
      Serial.begin(9600);
      //CONFIGURATION OF THE RGB LED
      strip.begin();
      strip.show(); 
    }
    
    void loop() {
      // Put your main code here, to run repeatedly:
      Temperature();  // Call the function to calculate the temperature in ºC
      Serial.println (Temp); // Show the temperature value in ºC 
       
       if (Temp>41)colorWipe(strip.Color(255,0,0),0); // Temperature greater than 41ºC
    
      if ((Temp>37)&&(Temp<41))colorWipe(strip.Color(244,80,43),0); // Temperature between 41ºC and 37ºC
    
      if ((Temp>34)&&(Temp<37))colorWipe(strip.Color(244,102,26),0); // Temperature between 37ºC and 34ºC
    
      if ((Temp>30)&&(Temp<34))colorWipe(strip.Color(248,147,31),0); // Temperature between 34ºC and 30ºC
    
      if ((Temp>27)&&(Temp<30))colorWipe(strip.Color(243,223,6),0); // Temperature between 30ºC and 27ºC
    
      if ((Temp>23)&&(Temp<27))colorWipe(strip.Color(147,198,45),0); // Temperature between 27ºC and 23ºC
    
      if ((Temp>20)&&(Temp<23))colorWipe(strip.Color(23,173,66),0); // Temperature between 23ºC and 20ºC
    
      if ((Temp>17)&&(Temp<20))colorWipe(strip.Color(40,209,188),0); // Temperature between 20ºC and 17ºC
     
      if ((Temp>13)&&(Temp<17))colorWipe(strip.Color(48,59,175),0); // Temperature between 17ºC and 13ºC
      
      if ((Temp>10)&&(Temp<13))colorWipe(strip.Color(58,33,117),0); // Temperature between 13ºC and 10ºC
     
      if ((Temp>6)&&(Temp<10))colorWipe(strip.Color(105,46,152),0); // Temperature between 10ºC and 6ºC
    
      if ((Temp>0)&&(Temp<6))colorWipe(strip.Color(155,36,152),0); // Temperature between 6ºC and 0ºC  
    }
    
    // FUNCTION FOR THE COLOR OF THE RGB LED
    void colorWipe(uint32_t c, uint8_t wait) {
      for(uint16_t i=0; i<strip.numPixels(); i++) {
        strip.setPixelColor(i, c);
        strip.show();
        delay(wait);
      }
    }
    
    void Temperature() // Calculate Temperature in ºC
    {
      ValueTemp = analogRead (PortTemp); // ValueTemp = Save the analog value of the temperature sensor
      VoltTemp = 5.0/1024*ValueTemp; // 
      Temp = VoltTemp * 100-50; // Temp is the value of the temperature in ºC
      delay(1000);
    }
    
  4. Configure and load the code, following the instructions given in the document First Steps for the 4in1 Build&Code board.

Code for compatible block programming software

  1. Download the software and go through the installation process.
  2. Add the extension to program the RGB LED following the instructions in the guide “How to add a library to program your RGB LED.”
  3. Open the program, and once in, copy the following code:
  4. Configure and load the code, following the instructions given in the document First Steps for the 4in1 Build&Code board.

BitBloq Code

  1. Get the BitBloq software.
  2. Open the BitBloq program, and once in, copy the following code:
    • Hardware
    • Software
  3. Configure and load the code, following the instructions given in the document First Steps for the 4in1 Build&Code board.

RESULT OF THE EXERCISE:

As a result of this exercise, the thermometer will show the ambient temperature with a color code. You have programmed your own color thermometer!

1 0

0