Raspberry Pi and Thingspeak (using BMP180) Used For Home Temperature monitoring


Raspberry Pi and Thingspeak(using BMP180) Used For Home Temperature monitoring:

Raspberry Pi and Thingspeak

Home Temperature Monitoring

Today is the era of IOT. The use of cloud is increasing consistently and people connect their devices to the cloud often. A raspberry pi B+ pumped up an almost 1GHz that was lying around the table, so it looks like the injustice had been done to the temperature /pressure. Aren’t they required to put in good use? As a result hardware arranged. The time to select a software cloud platform was when both hardware and software need to collaborate in the internet scheme of things. Before the journey started, we found the extremely convenient platform thing speak with its effortless method.

Step 1:

These parts are needed to work the magic

BMP180 for temperature and pressure Latest Raspbian installed with Raspberry Pi B+(or RPI2)

  1. The latest Raspbian image installed with Raspberry Pi B+(or RPI2)
  2. BMP180 for temperature and pressure
  3. For the Raspberry Pi we need 4 male to male headers, an Ethernet cable or Wi-Fi dongle and power cable.
  4. Raspberry pi (or putty on windows) connects to a Linux based PC/laptop remotely.

Step 2:

A Small Theory Which Can Be Skipped

Now the pressure sensing device (BMP180) connects to the cloud (i.e. is Thing speak) by the Raspberry Pi. The following connections are:-

  1. BMP180 from Raspberry Pi: – In this connection, the communication protocol used that is standard I2C protocol which is two wire interface; basically it is a master slave configuration. The main pins are include:-
  • Serial data (SDA):- The work of talking between the two devices done by this pin.
  • Serial clock (SCL):- The speed of data transfer between RPI and BMP180 is decided by this pin.

 A 7-bit addressing mode and 10-bit addressing (BMP has address 0x77) follows by I2C protocol from time to time and at around standard speed of 100KHZ (standard mode) it works. This protocol  design by Philips and it allows up to 400KHz which is fast mode, hi-speed mode is 3.4MHz and even up to ultra high mode which is 5MHz in different modes of working. The use of making “system management bus “or ‘SMBUS’ which is an Intel variant of I2C.

The master pulls SDA low (leaving SCL high) which alerts all the slaves to start communication and then it starts transmitting data.

SDA toggle condition (0 to 1) follows the master toggles SCL (0 to 1) and leaves it high to stop communication.

  1. Thing speak from Raspberry Pi:- The temperature/pressure values uploaded by RPI to the thing speak channel which will be creating in a minute by POSTing values to a provided custom API key.

Now, we have to know that what the “POST” really is. So, for this we have to know the networking basics. To communicate over the internet, computers use the TCP/IP model. The application layer is the topmost layer of this model. If we are requesting for some information, the application layer tells only. The protocols available in this layer are HTTP, OMAP, SMTP, POP3 etc. HTTP protocol helps to get/send a page or page info. So, the HTTP method of submitting data to a particular source is POST.

Step 3:

How to connect?

How to connect Graph Raspberry Pi and Thingspeak

With respect to the Raspberry Pi, the connections made. They are

  • BMP180 from Raspberry Pi: The master (Rasp Pi) and slave(BMP180) needed four connection to made between them are –


  • Raspberry Pi SDA ————–> BMP180 SDA
  • Raspberry Pi SCL ————–> BMP180 SCL
  • Raspberry 3.3V —————–>BMP180 Vin
  • Raspberry GND —————–>BMP180 GND
  • Thing speak from Raspberry Pi: This part is needed an internet connection. Through Ethernet or Wi-Fi , Raspberry Pi can connect to your home router. You will make sure that Raspberry Pi supports to get your device online with the Wi-Fi adaptor.


Step 4:

Creation of account

         Thingspeak sign up
create a channel  give name or identifie later

Write API Key

First we will need to create an account and then proceed to thingspeak site to create our channel with after the wiring is all done. To complete the channel creation needed steps are following:-

  1. Thingspeak sign up
  2. Click on “create channel” and create a channel
  3. Check the fields 1 and 2 and give them a name for the use of identifier later.
  4. If you want to make your data publicly visible, you can select ‘make public’ checkbox and click on save channel.
  5. Click on API tab and you will get write API key and copy the write API key
  6. Clicking on the private tab
  7. Click on “Add Visualizations” and select both the fields and done.

Step 5:

I2 C Bus To Be Enabled

I2 C Bus To Be Enabled

I2 C Module Yes-No

I2c module After Pressing Yes

I2c kernel module Again Press Yes

With the BMP180 to enable the Raspberry Pi communication, the instructions are given below:-

  1. Type “sudo raspi-config” on the CMD line
  2. Go to Advanced options—>I2C
  1. Click yes when it will ask to add the I2c module.
  2. Again click yes, when it will again ask for default loading of I2c kernel module

Step 6:

Writing Code

Channel Status

Thingspeak Temprature Report

Channel Status

All setup with the account and channel. The important part of writing code on the Raspi sends usual updates on the thingspeak channel. From the BMP180, temperature and pressure reads by the code and for making use of the custom write API key, it sends to thingspeak channel.

Follow the instructions given below:-

  • Via SSH you must log in Raspberry
  • Make a folder on command line and choose a name for it and cd into it.
  • Install git if not present and write the following command “git init” followed by “git clone”.
  • Cd into “bKKkM” the newly created folder and check for “Thingspeak_bmp180.py” file
  • To add your write API key in params inside the loop of main () function using nano editoredit file.
  • Using “sudo python Thingspeak_bmp180.py”, save and run the python script.
  • Click thingspeak channel and check inside private view tab.

      On the Raspberry Pi, the code is written in python.

  • BMP sensor gives temperature/pressure values to RPITo read both temperature and pressure values, the python scriptmain() has a readBMP180() function.

 bus=smbus.SMBus(1) #RPi rev2 uses 1

 #Read Temperature

bus.write_byte_data(addr,REG_MEAS,CRV_TEMP)#sending temperature control command to BMP180 inquiring temperature

time.sleep(0.005)#wait for 5ms

(msb,lsb) = bus.read_i2c_block_data(addr,REG_MSB,2)

UT = (msb<<8) + lsb # unrefined 16-byte temperature is generated by adding lsb and 8bit left-shift msb

#Read Pressure

bus.write_data_byte(addr,REG_MEAS,CRV_PRES + (OVERSAMPLE<<6))


(msb,lsb,xsb) = bus.read_i2c_block_data(addr,REG_MSB,3)

UP = ((msb<<16) + (lsb<<8) + xsb ) >> (8-OVERSAMPLE) #unrefined pressure value


For offsets and refining of each value more code is needed inside main().

  • This data send to Thingspeak channel by RPI – to POST values to the Thingspeak channel, the httplib module in python is to be used.


conn = httplib.HTTPConnection(“api.thingspeak.com:80”)

headers = {“Content-type”:”application/x-www-form-uelencoded”,”Accept”:”text/plain”}


params = urllib.encode({“field1″ : temperature,’field2′:pressure,’key’:”Your Write API key”})



print response.status,response.reason



Note – replace “your write API key” by write API key inside “params”. Inside the settings tab, you can clear or delete channel.

 Step 7:

The conclusion

Now, we connect to the cloud. In play store a few thingspeak mobile applications are available. To get started you required your channel ID and API key.


About Author

1 Comment

Leave A Reply