Temperature Changing Color Cube

13,739

198

19

Introduction: Temperature Changing Color Cube

About: Hi! I make stuff. Sometimes I write instructions about them.

Recently I made a camera stand so I can film my hands while soldering and assembling my project (Instructable of this is coming soon). This is a kick-off project to test the equipment! (And I made it a gift for Henk Rijckaert)

It's a 6cm x 6cm x 6cm cube that changes colors based on the temperature!

Step 1: Parts Needed

You'll need the following:
- TMP36 temperature sensor
- RGB led, I used common anode, but can common cathode can be used with a small change
- ATTiny85
- 8 pin DIP socket
- LM1117t 3.3V linear voltage regulator
- 2x 50 ohm resistors
- 10 µF capacitor
- Perfboard
- 4xAAA battery holder (not in the picture)

To assemble the case I've used a laser cutter with one sheet of 30x60cm 3mm MDF and one sheet of 30x60cm 3mm plexi. You don't need the whole sheet, but I had it lying around. Some plexi cement is also needed for making the cube.

For programming the ATTiny85 you either need an Arduino, which is what I used, or a specific ATTiny85 programmer board.

To assemble the electronics you'll need a soldering iron and I've used a glue gun to afix the perfboard to the MDF.

Step 2: Making the Cube

The base is a simple vector graphic that can be cut using a laser cutter or be made by hand. It is slightly elevated to fit the battery holder. The perfboard is later hot glued to the rails.

The plexi planes are also cut with the laser cutter, but at the same time made diffuse by making tiny scratches with the laser. You can also buy diffused plexi, but that wasn't available to me.

The laser cutter uses a value between black (0) and white (255) to denote the intensity of the scratching. In order to see which value fitted best with the project I printed a test plane with every value.

Plexi cement was then used to fit the pieces together. To make it easier, I made a small mould from some scrap wood to hold it together.

Step 3: Soldering the Board

The wiring is quite straightforward, there's a picture of the scematic and of the layout on the perfboard. When you're done, you can attach the perfboard to the base with some hot glue.

Some handy pinout diagrams:

- ATtiny85
- TMP36
- LM1117t
- RGB LED

Step 4: Coding

I've used my Arduino nano to flash the ATtiny85 chip. This guide helped in creating the board. You can also use a specific ATtiny85 programmer board.

The temperature isn't sensed continuously in order to save battery life. The sleep mode on the ATtiny85 is used to minimize its power consumption. The code is based on the work by Matthew Little on the website re-innovation.co.uk. Source

The temperature can be set to your liking, default it is set to switch at 18°C

The code is listed below or it can be downloaded in attachment.

#include <avr/sleep.h>;
#include <avr/wdt.h>;
// Routines to set and clear bits (used in the sleep code)
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
volatile boolean f_wdt = 1;
const int redPin = 1;
const int bluePin = 0;
const int sensorPin = 2;
const int fadeTime = 10;
// blue = 0, red = 1
int currentColor = 0;

void setup()
{
  pinMode(redPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  setup_watchdog(8);
  digitalWrite(bluePin, HIGH);
  digitalWrite(redPin, LOW);
}
 
void loop()
{
  if (f_wdt==1) {  // wait for timed out watchdog / flag is set when a watchdog timeout occurs
    f_wdt=0;       // reset flag
    checkTemp();
    system_sleep();  // Send the unit to sleep
  }
}

void checkTemp()
{
    int reading = analogRead(sensorPin);  
    float voltage = reading * 3.3;
    voltage /= 1024.0;
    float temperatureC = (voltage - 0.5) * 100 ;
    if(temperatureC > 18) {
        if(currentColor != 1) {
        currentColor = 1;
        fadeToRed();
        }
    } else if(currentColor != 0) {
        currentColor = 0;
        fadeToBlue();
    }
}

void fadeToRed(){
  int redVal = 255;
  int blueVal = 0;
  for( int i = 0 ; i < 255 ; i += 1 ){
    blueVal += 1;
    redVal -= 1;
    analogWrite( bluePin, 255 - blueVal );
    analogWrite( redPin, 255 - redVal );
    
    delay( fadeTime );
  }
}

void fadeToBlue(){
  int redVal = 0;
  int blueVal = 255;
  for( int i = 0 ; i < 255 ; i += 1 ){
    blueVal -= 1;
    redVal += 1;
    analogWrite( bluePin, 255 - blueVal );
    analogWrite( redPin, 255 - redVal );
    
    delay( fadeTime );
  }
}

// set system into the sleep state 
// system wakes up when watchdog is timed out
void system_sleep() {
  
  cbi(ADCSRA,ADEN);                    // switch Analog to Digitalconverter OFF</p><p>  set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
  sleep_enable();</p><p>  sleep_mode();                        // System actually sleeps here</p><p>  sleep_disable();                     // System continues execution here when watchdog timed out 
  
  sbi(ADCSRA,ADEN);                    // switch Analog to Digitalconverter ON
  
}

// <a href="http://www.re-innovation.co.uk/web12/index.php/en/blog-75/306-sleep-modes-on-attiny85" rel="nofollow"> http://www.re-innovation.co.uk/web12/index.php/en...</a>
// 0=16ms, 1=32ms,2=64ms,3=128ms,4=250ms,5=500ms
// 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec
void setup_watchdog(int ii) {
  byte bb;
  int ww;
  if (ii > 9 ) ii=9;
  bb=ii & 7;
  if (ii > 7) bb|= (1<<5);
  bb|= (1<<wdce);
  ww=bbl;
  MCUSR &= ~(1<<wdrf);

  // start timed sequence
  wdtcr |= (1<<WDCE) | (1<<WDE);
  // set a new watchdog timeout value
  WDTCR = bb;
  WDTCR |= _BV(WDIE);
}

Step 5: Enjoy!

If you followed every step correctly, then you should now have a cube in your possession that can sens the temperature!

Now what are the usecases?

One I found is that you now have indisputable proof for your girlfriend to say that the room is hot enough.

Ok, maybe there are no usecases. Still fun to make though!

Sensors Contest 2017

Runner Up in the
Sensors Contest 2017

Microcontroller Contest 2017

Participated in the
Microcontroller Contest 2017

Be the First to Share

    Recommendations

    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge
    • Make It Bridge

      Make It Bridge
    • Big and Small Contest

      Big and Small Contest

    19 Comments

    0
    DottieB2
    DottieB2

    4 years ago on Step 4

    How do you load the temp sensing code to the Attiny from the arduino? What are the pin connections?

    0
    DottieB2
    DottieB2

    Reply 4 years ago

    Thank you. The RGB cycles slowly through the colors (not green) but is not sensing the temperature. Any suggestions?

    0
    SebastiaanJansen
    SebastiaanJansen

    Reply 4 years ago

    Hmm, there's probably an error in the code, but I don't have this cube or an attiny85 anymore.

    0
    raspberrycoulis
    raspberrycoulis

    5 years ago

    I have a few questions, mainly regarding the components you used really as I'd love to give this build a go myself.

    I'm having issues finding 10µF capacitors - when I look for these online, I can only seem to find 10pF or 10nF capacitors that look like the ones you used. The 10µF ones seem to be a lot larger so I wanted to know if this was correct (sorry if this is a noob question)? Or would something like this be ok: http://uk.rs-online.com/web/p/aluminium-capacitors/6842068/

    The same applies to the resistors - I can only seem to find 47 or 56 ohm resistors. I would opt for the 47 ohm resistors myself, but I just wanted to check.

    Hope you can help.

    0
    SebastiaanJansen
    SebastiaanJansen

    Reply 5 years ago

    Sure! I'd love to help.
    First off, the capacitor. The voltage of AAA batteries changes depending how much it is drained. These are each roughly 1.5V and connected in series. When they are full they roughly give 4x1.5= 6V. When completely drained, it can even drop to 1V each, so it only delivers 4x1=4V.

    The ATtiny85 operates between 2.7 V and 5.5 V according to its specs. Here I use the LM1117t 3.3V linear voltage regulator to give a stable 3.3V output, which is in the operating voltage of the ATtiny. In the datasheet of the LM1117t they say this:

    "A minimum of 10-μF tantalum capacitor is required at the output to improve the transient response and stability"

    I looked around on your website and if you go into the "tantalum capacitor" category, you can filter on 10-μF. Then select one whose maximum voltage is higher than 3.3V.

    A resistor is needed for the LED to ensure that slight differences in voltage have only a minor effect on the LED's current. If you use higher values, then the LED will only shine a tiny tad dimmer. If you want to calculate the exact resistance, you can use Ohm's law. That is V = I x R. Here V is our supply voltage minus the drop voltage of the led (probably 2.2V), so V = 1.1V.

    I is how much the LED consumes, which is typically 20mA. In our formula you can bring over the I to the other side to make V / I = R.

    When you then plug in the numbers, 1.1 / 0.020 = 55, you get 55 ohms. Anything close to that number is good enough, so either the 47 or 56 ohm resistor is good.

    I hope that helps!

    0
    raspberrycoulis
    raspberrycoulis

    Reply 5 years ago

    Ok, so I have all the parts and I have assembled it. However, my LED stays blue no matter what, so I'm a little confused. I don't suppose you have a clearer fritzing diagram at all by any chance?

    0
    SebastiaanJansen
    SebastiaanJansen

    Reply 5 years ago

    Sorry, I was away for a while.

    The code can be buggy. I suggest that you try to pinpoint the problem by individually trying the outputs of the attiny.

    Something like this:
    const int redPin = 1;

    const int bluePin = 0;

    void setup()

    {

    pinMode(redPin, OUTPUT);

    pinMode(bluePin, OUTPUT);

    }

    void loop()

    {

    digitalWrite(bluePin, HIGH);

    digitalWrite(redPin, LOW);

    delay( 500 );

    digitalWrite(bluePin, HIGH);

    digitalWrite(redPin, LOW);

    }

    0
    raspberrycoulis
    raspberrycoulis

    Reply 5 years ago

    Fantastic! This is exactly the answer I needed, and I really appreciate you taking the time doing just this.

    That really helps me - I now thing I have everything I need to attempt it myself.

    Cheers!

    0
    deluges
    deluges

    5 years ago

    Neat! all you need is a fridge with a transparent door now :)

    0
    raspberrycoulis
    raspberrycoulis

    5 years ago

    Love this. I can already see a use case that is ideal for my situation - telling colleagues whether it is warm enough in the office and to avoid the air-conditioning wars that inevtiably happen!

    0
    Dr H
    Dr H

    5 years ago

    Simple and effective! I love it.


    Would there be an option to add two potentiometers, to simplify the setting of the upper and lower thresholds of the moderate range?

    I may try to implement something like that in my own thermometer constructs.
    Have a look.

    0
    SebastiaanJansen
    SebastiaanJansen

    Reply 5 years ago

    Yes, there are enough inputs left on the attiny. Here I did it with code so I can define an exact temperature in degrees .

    0
    Maker BR
    Maker BR

    5 years ago

    Great instructable.
    We can use it to test whether it is safe to touch or not for those things that get hot.
    Also for the heatsinks that we use in our circuits.

    0
    SebastiaanJansen
    SebastiaanJansen

    Reply 5 years ago

    Thanks!
    It's also relatively inexpensive to make, the total components price was only a few euros.

    0
    diy_bloke
    diy_bloke

    6 years ago

    I love Attiny85 projects.
    smart looking cube

    0
    jimminycricket33
    jimminycricket33

    6 years ago

    What a cool project. One use case I can think of is for my daughter, she is a little over a year and doesn't quite understand how a radiator heats up and cools down. Maybe something like this would be an obvious indicator... red is hot: do not touch. blue is cool: it's ok to touch. Lots of slay applications for this, thanks and well done!

    0
    SebastiaanJansen
    SebastiaanJansen

    Reply 6 years ago

    Huh, I didn't think about that, and thanks!