• If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Finally, you can manage your Google Docs, uploads, and email attachments (plus Dropbox and Slack files) in one convenient place. Claim a free account, and in less than 2 minutes, Dokkio (from the makers of PBworks) can automatically organize your content for you.


The Temperature Clock

Page history last edited by malcolm.knapp@... 9 years, 4 months ago

Hello all and Welcome to the Temperature Clock Project.


To do this project you will need the following equipment


Bill of Materials

1) Arduino software. This allows us to program and communicate with the boards. Download Arduino Software and install along with the FTDI serial driver.

2) Processing software. This program allows us to make the visuals for the clock. Download Processing Software and install.

3) An Arduino board that is USB programmable and has at least one analog input. I use a Arduino Mega for this example but others will work just as well. 

4) A USB cable (A to B, square to flat) 

5) A LM35 Temperature Sensor. Here is the datasheet

6) A computer that has at least one USB port. It can be either Mac or PC.

7) Ardn_Temperature_Sensor_Simple_StartCode.pde

8) Proc_Temperature_Clock_StartCode.pde



     This tutorial introduces the Arduino and Processing programming environments. Arduino is a programming frame work for microcontrollers designed for easy debugging and programming of boards. The FTDI serial driver is a program that allows the PC to communicate with an Ardunio Board. Processing is a programming environment that produces programs that run only on a PC and is for graphical displays and animation. Both Ardunio and Processing are derived in Wiring so their are a large number of similarities between them. 

     This tutorial uses the LM35 Temperature sensor. It is a simple sensor that produces an analog voltage that is proportional to the ambient temperature. The Ardn_Temperature_Sensor_Simple is used to read the temperature sensor and converting the raw data into Celisus. Then it transmits the temperature data over the USB cable to the Proc_Temperature_Clock which takes the that data and converts it into a graphical clock where the color and length of the hands is proportional the temperature.  



!!This project assumes that Arduino, Processing and the FTDI Driver are already installed on the computer!! If you do not have them installed please install them first before continuing with the tutorial. 

This tutorial gives you incomplete start code that you have to modify to create the Temperature Clock. 


If at any time you want to learn more about a command you can look at the Arduino Reference or the Processing Reference



First lets download the files and extract them

0.0) To get started download Ardn_Temperature_Sensor_Simple_StartCode.pde and Proc_Temperature_Clock_StartCode.pde

0.1) Extract both files and put them where you want them. 


Then lets connect the temperature sensor

1.1) The pinout is quite simple but it important to remember that the pins are seen from the BOTTOM. This means the side the pins come out of the package. If you get this backwards, you will destroy the sensor. 


1.2) Connect Vs+ to 5V on the board, GND to GND on the board, and Vout to Analog 0 pin on the board. There are a number of ways to do this. You can use a white breadboard or solder some longer leads to the sensor. Use whatever method works best for your Arduino board. In the Mega the pins I needed were close enough together that I was able to stick the sensor into the board after some creative bending. 



1.3) Connect the Arduino board to the computer using the USB cable and touch the sensor with your finger. If it starts getting hot immediately disconnect the power!! You probably had the leads in backwards and fried the sensor. Look at the datasheet again and try again with a new sensor. If it does not get hot then you are good to go.


Now lets program the start code on to the Arduino Board.

2.1) Start the Arduino software

2.2) Open the Ardn_Temp_Sensor_Simple_StartCode.pde. 

2.3) Select the board type from the Tool --> Board menu

2.4) Select the port for the board from the Tools --> Serial Port menu. Is should have a form "/dev/tty.usbserial-A7006QUq". 

2.5) Upload the code to the board by pressing the Upload button. If you do not set the correct port or the board is not connected correctly, the error "Serial Port /dev/tty.usbserial-A7006QUq not found..." will appear. Go back through the steps in this section and confirm the board connection and that the correct USB port is selected.


Confirm the Serial connection is working

3.1) Start the Processing software

3.2) Open the Proc_Temperature_Clock_StartingCode.pde 

3.3) Press the Run button and you should see the Serial list and the below that the number "10" should begin appearing. Like so....


Stable Library


Native lib Version = RXTX-2.1-7

Java lib Version   = RXTX-2.1-7

[0] "/dev/tty.usbserial-A7006QUq"

[1] "/dev/cu.usbserial-A7006QUq"

[2] "/dev/tty.Bluetooth-Modem"

[3] "/dev/cu.Bluetooth-Modem"

[4] "/dev/tty.Bluetooth-PDA-Sync"

[5] "/dev/cu.Bluetooth-PDA-Sync"







If you see this output then board and computer are communicating correctly and you can move on. However, if you do not see any 10s then confirm the computer is looking at the same port that the Arduino Board is connected to by making sure the line starting with "[0]" is the same as the one selected in step 2.4). If is not go back to the Arduino PDE and select to Serial Port that matches that item.


4.1) The next thing to do is add the code to read the temperature from the temperature sensor. The question is what code to add. Basically we have to add code that will convert the output of the analogRead into Celsius. We can do this by figuring out the unit conversion for each step. First we convert units to voltage and then we convert voltage to temperature. The number of volts/unit can be found by dividing 5V by 1024. The 5V comes from the max voltage that can be applied to the analog input and the 1024 comes from the max number of units the analogRead will output. Using these numbers we find that there are 4.9mV/unit. Then we find on the LM35 datasheet that the relationship between voltage output and the temperature is 10mV/degC. If we invert this we get 100degC/V. Now lets put all the unit conversion together.


Temperature [degC]  = analogRead output [units] x 5[V] / 1024 [units] x 100degC/ 1 [V


4.2) So now we know what we have to put in the code to read the temperature lets go ahead and do it. In Arduino: replace the code where it says " tempc = 10; // Insert Analog read code here" with the code below


for(i = 0;i<= 7;i++){ // gets 8 samples of temperature

// System Volatge is 5V

// Analog read max ouput is 1024 units

// Therefore 4.9mV/unit

// LM35 has a linear scale of 10mV/degC

samples[i] = (analogRead(pin)*(5.0/1024) * 100); 

tempc = tempc + samples[i]; 



tempc = tempc/8.0; // better precision


As you can see most of the action happens in the line beginning with "samples[i]...". You can see the unit conversions that give us Celsius when we are done. The extra code around that line averages eight different measurements of the temperature to make it more accurate. 

4.3) Upload the Arduino code again

4.4) In Processing: Run the Temperature Clock again and you should see the following output. It may take a little longer to appear because of the "delay(150)" in the code you just added. 


Stable Library


Native lib Version = RXTX-2.1-7

Java lib Version   = RXTX-2.1-7

[0] "/dev/tty.usbserial-A7006QUq"

[1] "/dev/cu.usbserial-A7006QUq"

[2] "/dev/tty.Bluetooth-Modem"

[3] "/dev/cu.Bluetooth-Modem"

[4] "/dev/tty.Bluetooth-PDA-Sync"

[5] "/dev/cu.Bluetooth-PDA-Sync"






So we have the temperature sensor working and transmitting data to the computer. Now lets turn our attention to the display. 


5.1) In Processing:  find the lines in the Temperature Clock code


displayColor = 0; // user defined

displayLength = 0; //user defined


Changes the zeros to some other number between 0 and 100. For example try:


displayColor = 32; // user defined

displayLength = 54; //user defined 

5.2) Run the Processing code and see how that display changes.


However this is not very interesting since they never change. So lets display the temperature instead of a fixed number. This also requires us to scale the values again so they display in a interesting way. The temperature is stored in the "data" variable so that is the one we have to connect to the display variables. 


5.3) In Processing: Replace the existing displayColor and displayLength equations with the ones below. These equations take the the temperature and coverts it into a Hue value and and the length of a line. 


                   displayColor = 120.0 -4.0*float (data);

                   displayLength = 4.0*float(data);



5.4) In Processing: Run the Temperature Clock again and you will now see a display where the length and color of the lines is dependent on the temperature. Play around with the input by putting your figure on the temperature sensor and see the length of the lines grow longer. For a more dramatic effect use a hair dryer to heat up the temperature sensor. 


Your done!


Now you can play with the displayColor, diplayLength, and the clockRate parameters and see what other cool visuals you can create. One question you can try and answer is what is the correct clockRate to get the clock to make one revolution is a day. 
























Comments (0)

You don't have permission to comment on this page.