This tutorial was featured on the official Arduino blog on 3/9/2011
As promised, this week brings another communications tutorial! In this video, we’ll use both the serial and processing knowledge that we gained last week, plus an I2C enabled temperature-sensing IC. We’ll use processing to generate a pretty room temperature display on your computer screen. If you are new to processing, they have an excellent set of tutorials to help you get started.
You can download the files associated with this episode here:
Distributed under the GNU General Public (Open-Source) License.
Please Attribute and Share-Alike.













February 16, 2011 at 3:09 pm
thanks! great resource .
Pingback: Must-See Beginner Tutorials For Arduino | inmotion.pt
March 12, 2011 at 1:03 am
I just finished with putting together my first temperature display from this tutorial. I created the background art in Inkscape. I would like to show it to you. What is the best way to do that?
Steven
March 14, 2011 at 10:49 am
Contact me via the contact page link up top.
March 14, 2011 at 2:50 am
How you know it will be 72?
March 14, 2011 at 10:50 am
It’s specified in the datasheet
March 19, 2011 at 9:57 pm
Just how accurate is the I2C temperature sensor at getting room temperature? Are there other temperature sensors? The readout with my build is consistently 70-72°F and the temperature feels much warmer. I can see the temperature change when I pinch the sensor between my fingers.
March 20, 2011 at 2:31 pm
It’s pretty accurate. A thermistor might show fluctuations better, but you’d have to convert the voltage to a temperature on your own.
Pingback: Ellentriek » Blog Archive » Arduino, Processing and sensors Part 2
August 21, 2011 at 10:10 pm
Just tried using an HH10D humidity sensor. I keep getting nothing but zeroes back from the sensor. I used this code:
/*
* Read HH10D humidity sensor (http://www.sparkfun.com/products/10239)
* It contains a M24C02BN6 Eeprom with calibration values.
*
* Author: Patrik Hermansson, http://www.patrikhermansson.se
* Date: 110309
*
* Connections:
* Vss – Gnd
* Vdd – +3.3V
* Fout – D5 (Mega168 pin 11)
* SDA – A4 (pin 27)
* SCL – A5 (pin 28)
*/
#include
int rv = 0;
void setup() {
Wire.begin();
Serial.begin(9600);
Serial.println(“Hi!”);
}
void loop() {
readCalib(81,10);
Serial.print(“Sensitivity: “);
Serial.println(rv);
readCalib(81,12);
Serial.print(“Offset: “);
Serial.println(rv);
delay(1000);
}
int readCalib( int deviceaddress, int calibAddress ) // deviceaddress is 1 according to datasheet
{
// Set address
Wire.beginTransmission(deviceaddress);
Wire.send(calibAddress);
Wire.endTransmission();
// Request return value
Wire.requestFrom(deviceaddress, 2);
// Collect return value
for (int c = 0; c < 2; c++ )
if (Wire.available()) rv = rv * 256 + Wire.receive();
return rv;
}
Not sure what I am doing wrong. It says the device has an EEPROM and that in order to read out the correct humidity, 4 calibration factors need to be read out from the EEPROM at address of 10 and 11,12 and 13 for sensitivity, offset.
This one blew me away a bit.
September 25, 2011 at 3:42 am
This is a great video and series! Very informative and easy to follow. I have two quick questions;
1) How many of these temperature sensors can you connect to each bus? I’m looking to connect about 10 if possible.
2) If I had multiple sensors on one SDA and SCL line, would I need to connect pull up resistors for each sensor, or would all the sensors share two resistors at the start of the SD and SCL line?
Thanks Sciguy!!
October 28, 2011 at 2:20 pm
You only need one set of pull-ups for the entire bus. You can connect as many as you want so long as they have different IDs.
January 14, 2012 at 9:31 am
Jeremy:
I replicated your schematic using a T 74a7 with an ID of 79 and it worked fine except the temperature reads about 10F higher than it should accross the range frm 20-100F. Is there a means of inserting a calibrating resistor to compensate?
I tried replacing one of the 10k pull up resistor with a variable pot with no change across the 10k range, and in the process found out tha the 10k pull up resistors had no effect at all on the readout.
Would appreciate your comments.
Thanks
January 14, 2012 at 5:52 pm
The pullup won’t affect the value – that’s just for setting the default digital values of the I2C lines. If it is consistently 10 degrees to high, why not just subtract 10 in software from whatever value you are reading?
January 21, 2012 at 2:42 pm
Thanks Jeremy:
I adjusted as follows:
int c=Wire.receive()-5;
Still playing with the correction. But for now -5F seems to work well
Thanks a lot
January 20, 2012 at 7:40 pm
Hi Jeremy,
Great demo.
It’s not the same components, but I have a SRF10 ultra sonic range sensor connected to an Arduino Pro Mini, and I’m trying to get the I2C protocol to work but it’s not happening. Based on my testing (println to check for code progression), I found that when the code gets to the “endTransmission” instruction, it freezes, and nothing else happens. It looks like this has been a problem, but I don’t know how to get around it. Any idea?
Thanks.
January 21, 2012 at 10:47 pm
Have you tried some sample code? http://www.robot-electronics.co.uk/files/srf08.pde
January 26, 2012 at 6:59 pm
Hi Jeremy,
Your tutorials are the best. Thanks for all your effort. As with others above, I’m interested in using more than one sensor on the bus, but am aware that I will need to change the address of the other sensors so that there isn’t a data crash.
How would I
a) write a new address to a device and
b) poll each sensor individually to recover the temperature at each sensor?
I must admit that my biggest difficulty is understanding how to use library functions. I don’t know what each one holds or how to use them correctly.
What resources are there that will explain how to use libraries?
February 13, 2012 at 10:54 am
Most I2C devices cannot have new ID’s assigned to them, so you need to find ones with different ID’s. An alternative is to bit-bang two I2C devices with the same ID on different bus lines.
The best way to understand libraries is to check out the source code and see how the functions are written.
February 7, 2012 at 7:27 pm
Hi,
Very good tutorial. I have two questions, so far:
1. The serial communication to the computer, is in fact an emulation of an RS232 via the USB right ? You are not really doing an RS232 link betwen the Arduino and your PC…
2. If I got it right, the Arduino, here, is a development tool. After you do your programing and testing, would you be able to “burn” a microcontroler in orther to have it embeded in a circuit?
Thank you,
April 23, 2012 at 3:42 pm
Correct, there is chip on the arduino doing RS232 emulation over USB. You can indeed burn the program to a chip built into larger circuit.
February 12, 2012 at 9:08 am
Hello Jeremy!
After your lessons I fill power in my hands and begin to wire different parts to my “clock”
And I was success with LCD (COG 2×16 LCD board from http://www.mikroe.com)
But with I2C RTClock board (PCF8583 chip)I meet some difficulties.
I’ve connected Vss and Ground to the board, pullup with 10kom SDA(5 to A4) & SCL(6 to A5) and …
nothing else. (may be I have to wire 3 & 7 pin on chip to Vcc?)
I was try to read time & date but it is fail.
Help me< where I am wrong?
thank you a lot!
March 3, 2012 at 7:42 am
hi
guys, help me in this error as i m new to arduino
wire.send () has been renamed wire.write().
what does that mean ???
i copied the code and paste it in ardiuno window!!
THANKS
March 21, 2012 at 9:27 am
// New code for Arduino 1.0, library has changed slightly from older versions
//Program by Jeremy Blum
//www.jeremyblum.com
//Reads Temp in Celsius and Shows it on Computer
//Include Wire I2C Library
#include
int temp_address = 72;
void setup()
{
//Create Serial Object (9600 Baud)
Serial.begin(9600);
//Create a Wire Object
Wire.begin();
}
void loop()
{
//Send Request
Wire.beginTransmission(temp_address); //Start talking
Wire.write(8); //Changed command send to write (8 bit device)
Wire.endTransmission(); //Complete Transmission
Wire.requestFrom(temp_address, 1); //Request 1 Byte
while(Wire.available() == 0); //wait for response
int c = Wire.read(); // Changed command from receive to read, Get the temp
//do some math…
int f = round(c*9.0/5.0 +32.0);
Serial.print(c);
Serial.print(“C,”);
Serial.print(f);
Serial.print(“F.”);
delay(500);
}