Arduino Project 7 (2D/3D pictures) – How to read up to 32 tmp102 temperature sensors with one Arduino by using 4051 multiplexers (Arduino Uno/1.0)


I bought a few tmp102 sensors on matching breakout boards from SparkFun to take measurements around the greenhouse. Apart from the fact that this sensor is tiny, very energy efficient and responsive I mainly decided to go for these instead of thermistors because they are digital (no need for endless conversions) and since they are I2C they can all be connected to the same two wires. This model is limited to four devices per I2C bus which is enough for what I want to do. If you need more you will find plenty of tmpXYZ choices on TI’s website. I’ll start with connecting the maximum of four tmp102 sensors to one Arduino Uno board, mainly to explain how the addressing scheme works and then move on to a setup which allows for multiples of four sensors to be read with the same Arduino Uno with the help of 4051 multiplexers.

Some cold facts on the tmp102 before we start:
Low Power Digital Temperature Sensor with SMBus/Two-Wire Serial Interface in SOT563
resolution of 0.0625C
range of -40C to +125C
SMBus and two-wire interface compatibility
up to four devices on one I2C/TWI bus.
1.4V to 3.6VDC supply range

And some links with with more details:


1. The theory:
The idea is simple. Imagine the I2C interface like a little network. You connect your sensors to the two wires (analog pin 4+5 on the Arduino Uno), configure each sensor to have it’s own hardware address and then just send out a request through the two wires to talk to which ever address you want.


2. Let’s connect the first one:
Connect the sensor as follows:

On the tmp102 breakout board: -> On the Arduino Uno board:
V+  -> 3.3V
SDA -> analog pin 4
SCL -> analog pin 5

With the help of this sketch we can now get the current temperature reading form our first sensor.



3. Let’s connect some more:
To get more than one of these sensors to work on our I2C network we need to configure each one of them with it’s own hardware address. This is achieved by connecting the breakout boards ADDO pin to different Arduino pins. The four possible options are:

On the tmp102 breakout board: -> On the Arduino board: -> Translates to network address:
ADDO -> GND -> 1001000 -> 0×48 -> 72
ADDO -> 3.3V -> 1001001 -> 0×48 -> 73
ADDO -> SDA -> 1001010 -> 0×48 -> 74
ADDO -> SCL -> 1001011 -> 0×48 -> 75


Once all four sensors are connected the following sketch will get the current temperature reading form all four sensors.



4. Anything else it can do?
I didn’t expect much more from a temperature sensor, in fact this is a lot for such a tiny package. Still, it’s got a few more tricks up it’s sleeve. The TI manual mentions a few more registers towards the end, in addition to the current temperature this sensor also stores it’s configuration and highest/lowest temperature readings in registers which are accessible via I2C. I doubt that many people are going to be interested in the configuration register and further options of this sensor, feel free to consult the manual for further details. I can see use for the min/max temperature registers for stand alone setups (I tend to store sensor readings in a database) and the following sketch will display the content of the current/max/min temperature registers for all four sensors.



5. One more to go:
I had ordered five of these tmp102 sensors since I was afraid I might kill one during “testing”. They have proven very hardy, even running them on 5V or connecting various pins wrongly doesn’t seem to have caused my testing sensor any obvious damage. Obviously I couldn’t resist to try and make the fifth one work as well ;)


6. 2×4051=32xtmp102…
To prove that it is possible to read multiple strains of 4xtemp102 I’ve setup a little experiment with two 4051 multiplexers and two tmp102s which are both set to a 72 address by connecting their ADD0 pins to ground. Multiplexer nr1 (which is going to control all the SDA pins) has it’s z pin connected to analog pin 4 and multiplexer nr2 (which is going to control all the SDC pins) has it’s z pin connected to analog pin 5. Both multiplexers have their s0-2 pins connected to the same digital pins 8/9/10 which allows to select the eight different strains of tmp102s we can now start to connect. I’m sticking to two for the moment but this setup is obviously easily extendable.
For anyone who isn’t familiar with the 4051 there is a good introduction on the playground (


The following sketch will set the multiplexers, read both 72 tmp102s in turn and prints the result to the serial monitor.


FacebookGoogle GmailEvernoteDeliciousShare

Arduino Project 6 – Measuring a water tank level (SRF05 Ultrasonic Rangefinder/Arduino Mega 2560/Arduino Uno/1.0)


I’m harvesting rainwater from a couple of outbuildings via 110mm underground pipes connected to an underground storage tank. Since I want to stay on top of the water level in the tank and also had a SRF05 ultrasonic rangefinder sitting in a box I thought I’d put it to good use and measure the water level in the storage tank. The result is collected by an Arduino Mega 2560 and uploaded to a mysql database with the help of an ethernet shield but this is obviously optional.

The Basics:

The theory behind this sensor is easy to understand. It works pretty much like a bat hence sends out an ultra sonic pulse, waits for it to come back and depending on the time between the two events we can then calculate the distance between our sensor and the nearest obstacle. I’ve put the sensor including a little bit of perfboard with a switch and some LEDs into an enclosure and mounted it to the inside wall of the tanks collar facing down towards the bottom of the tank/water. To get the sensor connected to the Arduino Mega 2560/Uno there are four cables to connect before we can upload a sketch for testing purposes. Apart from reading from the sensor the sketch also blinks the onboard pin13 LED after each measurement and prints the result to the serial monitor.


Connect the sensor as follows:

Red -> Arduino 5V

Yellow -> Arduino digital pin 7

Lilac -> Arduino digital pin 8

Black -> Arduino GND

Upload the following sketch, open the serial monitor and you should see some results.



3. Let’s make it pretty and “put it in the hole”:

I didn’t want to just hot glue the sensor to the inside of the tank due to the humidity in there. Unfortunately I’ve currently run out of the water proof enclosures/cable glands I tend to use so I had to improvise. I also made a little perfboard which includes a switch to cut power to the sensor and board, one red LED to indicate 5V arriving on the perfboard and one yellow LED as a heart beat indicator to flash between measurements. I’ve mounted all this inside the plastic cap of an aerosol can with the LEDs sticking out the top. The two sensor eyes look out the bottom which is sealed with a bit of plastic with holes cut into it to let the sensor eyes poke through. Add a generous amount of hot glue to seal the gaps and we’re ready to mount the sensor inside the collar of the water tank.

The following sketch will print the result to the serial monitor and use the onboard pin13 LED and the perfboard LED as heart beat indicators between measurements.


FacebookGoogle GmailEvernoteDeliciousShare

Arduino Project 5 – Adding a stackable ICSP header to the Arduino Ethernet Shield (micro-SD/R3 version)


I’m currently working on a bit of coursework which includes XBee shields and XBee 2.5 ZNet modules. Since I want one of my nodes to form a bridge between the XBee network and my existing ethernet network I bought an Arduino Uno and one of the new ethernet shields with micro-SD slot. The pictures are for the older non R3 micro-SD ethernet shield but I’ve got an R3 one as well and the layout appears identical (apart from the new pins which are of no concern for this exercise) hence the procedure will be identical.

1. The problem:

The issue is obvious, the ethernet shield doesn’t pass the ICSP pins through to the next layer hence the XBee shield has nothing to plug into. Initially I wasn’t sure if there could be more than one shield using the ICSP headers so I sneakily soldered wires to the underside of an old Diecimila and the underside of an XBee board. With the ethernet shield between the two I could receive data from the XBee network and upload said data to my mysql database via the ethernet shield. So I got out the tools :)


2. Removing the existing ICSP headers:

I started by removing as much solder as possible from the top solder points of the header with de-soldering braid to make my life easier later on when trying to get the actual header pins out. Then snip off the black plastic part of the header but leave as much of the actual pins as possible attached to the board (makes it easier to get hold of them when you are trying to pull them out). Heat the pins up one by one and pull them out.


3. Tidy up:

I still had a few holes blocked with left over solder. Again de-soldering braid is your friend but you could probably just as well use a Dremel type tool with a tiny drill to clean the holes.


4. Fit and solder the new ICSP stackable header:

Like in Arduino Project 4 I used an 8-pin header and cut it down to two 3-pin ones with a Dremel and diamond cutting disc. Feel free to use whatever you have available, these 6-pin headers will be available somewhere but I just wasn’t patient to search for them ;) Fit the new header to an Arduino board and attach the ethernet shield above with the new ICSP pins fed through the appropriate holes in the ethernet shield. This would be a good point in time to take whatever second ICSP enabled shield you want to fit on top of your ethernet shield and check that it’s female ICSP header actually reaches the new ICSP pins you are about to solder in place. If you are happy with the result heat up the soldering iron. Two pins are rather close to the micro-SD slot so be careful not to connect them to the metal housing of the micro-SD slot.

FacebookGoogle GmailEvernoteDeliciousShare

Arduino Project 4 – Sparkfun Arduino Mega ProtoShield with stackable ICSP header


Since I’m planning to extend the greenhouse Arduino system before the next wave of plants go in I decided it was time to upgrade myself to an Arduino Mega 2560. All my existing shields appear to work with it but for trying new ideas out in the wild I prefer protoshields over breadboards so I got a Mega protoshield as well. There are more modern Mega protoshields around which pass through the IOREFF and ICSP pins by default but I still prefer this one as the kit is available in the UK, comes with stackable headers and has a large continuous prototyping area.


1. Inspection, let’s have a look at what we’ve bought:

My kit came with:

(1) Printed Circuit Board (PCB)

(1) momentary switch

(2) LEDs (one green, one red)

(2) 330 ohm resistors (orange/orange/brown)

(1) 10k ohm resistor (brown/black/orange)

(12) 8-pin stacking headers

Have a look at the picture below to make sure you’ve got everything you need (getting stuck half way through is terribly annoying) and know which part is which.


2. Count your headers (and don’t get angry…):

Before we start to solder we need to deal with the little issue of SparkFun supplying the wrong sort of headers. At closer inspection you will find that the header closest to the position of the switch is actually a 6-pin and that there is no way to make up 18 pins (for the two rows of 18 pins that make up the giant double row header section) from 8-pin headers. No idea why SparkFun don’t supply other headers but such is life so we’ll have to deal with it. There are three main ways forward, pick whatever you feel most comfortable with:

a. Buy yourself seven 6-pin headers. This solves the problem rather elegantly, provides the best finish but obviously means you need to invest more cash and probably drive to your local component dealer or wait for some online shop to deliver to your door.

b. Chop up the 8-pin headers. Make one 6-pin header and create the big header section from four 8-pin headers and two 2-pin headers (again from chopping up one of the 8-pin headers). This will work but if you fit the 2-pin headers to the ends of your giant header area they will tend to bend outwards hence make it difficult to attach the prototype shield to your Arduino Mega. If you want to go down this route I’d suggest to keep the 2-pin headers in the middle of the giant header area.

c. Chop up 8-pin headers to make up 6-pin ones. The latest version of this kit now has twelve 8-pin headers included (earlier versions only came with eleven) hence you should have just enough headers to do this (five to be used as 8-pin, one to be chopped down to 6-pin, six to be chopped down to 6-pin for the giant header area, makes up the twelve we got in our kit).


 3. Soldering the resistors:

We’ve got two types, 10k Ohm and 330 Ohm ones. If your eye sight is good enough you’ll find they are easy to identify by their colour bands but you can just as well put a meter against them. Have a look at the PCB, there is a little area in the lower left corner between the LEDs and the switch with little rectangles which have numbers in them. The number match up with our resistor values hence this is where we solder in our resistors. Orientation doesn’t matter for resistors, just make sure you put them into the right place. Feed the tails through the holes, solder at the back and clip off the excess tails.



4. Soldering the switch:

The switch goes into the area on the right hand side just next to the resistors we’ve just soldered. Just as with the resistors orientation isn’t critical, if you can get it mounted it’ll be fine. The legs of the switch are meant to be slightly bent, this will hold the switch in place while you solder.



5. Soldering the LEDs:

We’ve got two of those, one red and one green one. Unfortunately the one’s I got with my kit were both translucent hence the only way to find out which is which is to “make ‘em glow” :)

I’ve used an Arduino Uno for this and uploaded the Blink sketch. Attach the longer leg of the LED to pin13 and the shorter leg to the ground pin right next to it. Better make a note of which LED is which.

The soldering area for our LEDs is in the lower left corner of the board. The green LED is meant to go into the left position (STAT) and the red LED into the right position (POWER). Obviously nobody forces you to stick to this but I find it makes life easier to stick to a fixed colour scheme. If yours is different feel free to change the order or use different LEDs.

Keep in mind orientation matter with LEDs, if you look at their translucent body you will find one of the sides is slightly flattened. Check the board and the LED area and you will find that the round circles which mark the LEDs positions are flattened one one side in the same way. Make sure you fit the LEDs the right way (left/STAT/green one with the flattened side facing right, right/POWER/red one fir the flattened side facing left). As before with the resistors, feed the tails through the holes, solder at the back and clip off the excess tails.


6. Cutting the headers:

This will obviously depend on whatever tools are available to you. A wide range of scissors or sharp knifes should do the trick but keep in mind that the black plastic is a tough material to cut through and actually encloses bits of metal. I assume you can watch out for your own fingers…

I am the lucky owner of a Dremel with a matching little diamond cutting disc which makes the whole exercise rather painless and quick. If you want the result to be pretty feel free to use a bit of sanding paper to smooth the rough edges.


7. Soldering the headers:

Next step is to solder all the headers, if you put all the 8-pin ones in and turn the PCB over it is easy to solder them and the board will be nice and stable. Then repeat the same with the 6-pin header and the giant header section at the end of the PCB.



8. Adding an ICSP header

This protoshield does not come with ICSP headers but if one is prepared to sacrifice a bit of prototyping area they are easy to add. If you want to use an ethernet or XBee shield above this proto shield you are going to need these headers. I turned an 8-pin header into two 3-pin ones for this purpose. Once you’ve got them cut to the correct size simply fit them onto the header on the Arduino board and fit the protoshield on top with the new ICSP header pins fed through the appropriate holes in the prototyping area. Solder the six pins to the prototyping area of your protoshield and you’re done and ready to use ICSP dependent shields above your protoboard.



9. Further thoughts:

Apart from the fact that I can’t see an easy way to feed the IOREF pin through due to the switch which is located directly above it this protoshield is perfect for what I want to do.

FacebookGoogle GmailEvernoteDeliciousShare

Copyright © All Rights Reserved · Green Hope Theme by Sivan & schiy · Proudly powered by WordPress

Hit Counter provided by seo company