This circuit uses a TMP 36 which is an integrated circuit designed to output 10mV per degrees centigrade and it's particularly interesting because it introduces the idea and practice of letting your Arduino board talk back to your computer. This is an extraordinarily handy tool for doing diagnostics when some part of your code is not doing as it should.

The circuit (?) consists of just one component and a few jump wires. Here's how it appears in the book.


Go Back Copy & Paste Code from Here:

Once you've got this code uploaded precisely nothing visible will happen. You need to open the IDE serial monitor which you do by clicking on the button as indicated by the big red arrow upper right.

Having done this a box should appear, probably to the left of your Arduino IDE, which looks like the image on the left. It should be showing you the temperature as gauged by your TMP36, in degrees centigrade. This is your Arduino board talking back to your computer. How is it doing this? It's communicating by the USB port, obviously, and it's sending serial data back. To tell both the computer and the board that they need to talk to each other, this line appears in the code:




This introduces the board and the computer. In techiespeak it's known as a "handshake".

The figure of 9600 after it is a Baud rate and it tells both devices how fast they are going to transfer data. In the case of your Arduino, how fast it's going to chuck it out, and for your computer it's how fast it picks it up. The Baud rate on your window needs to match that set in your code or what you'll get is scribble. You shouldn't need to change it in your window as it defaults to 9600 but just in case the way you change it is by clicking on the drop-down menu marked above by the big red triangle and selecting the correct rate.


There's another part to this and it's in the line:




which tells your board to send that variable's value back to the computer, and the window tells your computer to print it. It's all very clever. Not exactly portable though is it?


So, as this is the penultimate exercise and by now you should be well acquainted with the Arduino board, let's push the boat out and build a step thermometer. A step thermometer works unlike a mercury thermometer by taking the temperature and displaying it in steps. This could be 1,2,3,4 etc degrees or 0, 0.5, 1,1.5 etc to some upper limit. We're not going that fine. We're going to build one that measures in steps of five degrees. It's good enough for gardeners. The output is going to be via eight LEDs, and as the temperature gets higher than a multiple of 5, each LED in turn will light. Our steps then are going to be:

0, 5, 10, 15, 20, 25, 30, 35. Visualising the idea:







The Baud Rate


In digital communications, it's equal to one symbol per second. A symbol can be just one, or several pieces of data and it's usually a pulse representing  an Integer number of bits. It's not to be confused with the gross bit rate which is made in bits per second. However many bits per symbol  per second there are, divide by that to get the Baud rate.

I bet you're sorry you read this sidebar now, aren't you?

LED 8 lights when ambient temperature is at or past 35 degrees


LED 7 lights                  "                                                      30 degrees


LED 6                                                                                    25       "


LED 5                                                                                    20


LED 4                                                                                    15


LED 3                                                                                    10


LED 2                                                                                      5


LED 1 lights when ambient temperature is at or past 0 degrees.


All LEDs go off in sub-zero temperatures.

    0                    5                  10               15                20              25               30            35

The above graphic shows how the LEDS  are meant to light at a range of temperatures in degrees centigrade. Here's a schematic for the circuit:

temp     C


Two pictures showing the thing realised as a rapid breadboard prototype.  The second one shows the reading on my whizz-bang all-singing all dancing multimeter which has a thermometer on it. It bloody well ought to do as well for what they charged for it! And it ought to be made of gold.

I digress. You can see the wbasad multimeter is reading a temperature of 23 degrees centigrade. The bottom five LEDs are on and the top three are off. Looking good.....

Alrighty then, if you've built the circuit here's some code to slap your board with:




int (temparray [])={102,112,122,132,142,152,162,172};


float (temperature);

void setup(){

  Serial.begin (9600);



void loop (){


readsensor =(analogRead (A0));

for (int j=0;j<8;j=j+1){

  if ( readsensor > temparray [j]){

    digitalWrite (j+2,HIGH);}

    else {

     digitalWrite (j+2,LOW);}


     temperature = readsensor ;

     temperature = (temperature - 102)*4.89;

    temperature = temperature /10;

 Serial.println(temperature );

 delay (500);



Everything working ok? If so jolly good. If not check your wires, and make sure you haven't put an LED in backwards.

The chances are the temperature where you are is unvarying. Pinch the TMP 36 between your fingers and you should get a rise in temperature. The next LED (or couple of LEDs depending on the temperature where you are) should light within a few seconds. To test it I ran my wife's hairdryer at low speed over the sensor, and going the other way jammed in an ice-pack from the freezer right next to the sensor IC.



Over the page we'll look at this code.