0% found this document useful (0 votes)
24 views8 pages

EXPERIMENT 09

Uploaded by

om raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views8 pages

EXPERIMENT 09

Uploaded by

om raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

To BMP180 interface with ESP8266 and post the data in to THINGSPEAK cloud

2210040117
OM RAJ
SOFTWARES USED

ESP8266 BOARD (Arduino IDE)


APPARATUS/ COMPONENTS REQUIRED

1. ESP8266
2. BMP180 PressureSensor
3. Connecting Cables
4. DC 5V, 1A Power Adaptor

THEORY:
This precision sensor from Bosch is the best low-cost sensing solution for measuring barometric
pressure and temperature. Because pressure changes with altitude you can also use it as an
altimeter! The sensor is soldered onto a PCB with a 3.3V regulator, I2C level shifter and pull-up
resistors on the I2C pins.

The BMP180 is the next-generation of sensors from Bosch, and replaces the BMP085. The good
news is that it is completely identical to the BMP085 in terms of firmware/software - you can use
our BMP085 tutorial and any example code/libraries as a drop-in replacement. The XCLR pin is
not physically present on the BMP180 so if you need to know that data is ready you will need to
query the I2C bus.

This board is 5V compliant - a 3.3V regulator and a i2c level shifter circuit is included so you
can use this sensor safely with 5V logic and power.

Using the sensor is easy. For example, if you're using an Arduino, simply connect the VIN pin to
the 5V voltage pin, GND to ground, SCL to I2C Clock (Analog 5) and SDA to I2C Data (Analog
4). Then download our BMP085/BMP180 Arduino library and example code for temperature,
pressure and altitude calculation. Install the library, and load the example sketch. Immediately
you'll have precision temperature, pressure and altitude data.

HARDWARE CONNECTION:
INSTALL THE NECESSARY LIBRARY FILE:

1. Download the BMP180 ZIP library from https://github.com/LowPowerLab/SFE_BMP180


2. Open Arduino IDE. Then go to and select Sketch->Include Library->Add .ZIP Library.

3. Choose SFE_BMP180-master.zip file and click to Open.

CODE/PROGRAM:-

#include <ESP8266WiFi.h>
#include <SFE_BMP180.h>
#include <SPI.h>
#include <Wire.h>

// You will need to create an SFE_BMP180 object, here called "pressure":


SFE_BMP180 pressure;

#define ALTITUDE 24.0 // Altitude of SparkFun's HQ in Boulder, CO. in meters


String apiKey = "your apiKey"; // Enter your Write API key from ThingSpeak
const char *ssid = "your name"; // replace with your wifi ssid and wpa2 key
const char *pass = " your password";
const char* server = "api.thingspeak.com";
WiFiClient client;

void setup()
{
Serial.begin(115200); // open serial port, set the baud rate to 9600 bps
delay(10);
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");

Serial.println("REBOOT");

// Initialize the sensor (it is important to get calibration values stored on the device).

if (pressure.begin())
{
Serial.println("BMP180 init success");

}
else
{
// Oops, something went wrong, this is usually a connection problem,
// see the comments at the top of this sketch for the proper connections.

Serial.println("BMP180 init fail\n\n");


while(1); // Pause forever.
}
}

void loop()
{
char status;
double T,P,p0,a;

// Loop here getting pressure readings every 10 seconds.

// If you want sea-level-compensated pressure, as used in weather reports,


// you will need to know the altitude at which your measurements are taken.
// We're using a constant called ALTITUDE in this sketch:
Serial.println();
Serial.print("provided altitude: ");
Serial.print(ALTITUDE,0);
Serial.print(" meters, ");
Serial.print(ALTITUDE*3.28084,0);
Serial.println(" feet");
// If you want to measure altitude, and not pressure, you will instead need
// to provide a known baseline pressure. This is shown at the end of the sketch.

// You must first get a temperature measurement to perform a pressure reading.

// Start a temperature measurement:


// If request is successful, the number of ms to wait is returned.
// If request is unsuccessful, 0 is returned.
status = pressure.startTemperature();
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);

// Retrieve the completed temperature measurement:


// Note that the measurement is stored in the variable T.
// Function returns 1 if successful, 0 if failure.

status = pressure.getTemperature(T);
if (status != 0)
{
// Print out the measurement:
Serial.print("temperature: ");
Serial.print(T,2);
Serial.print(" deg C, ");
Serial.print((9.0/5.0)*T+32.0,2);
Serial.println(" deg F");

// Start a pressure measurement:


// The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait).
// If request is successful, the number of ms to wait is returned.
// If request is unsuccessful, 0 is returned.

status = pressure.startPressure(3);
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);

// Retrieve the completed pressure measurement:


// Note that the measurement is stored in the variable P.
// Note also that the function requires the previous temperature measurement (T).
// (If temperature is stable, you can do one temperature measurement for a number of
pressure measurements.)
// Function returns 1 if successful, 0 if failure.
status = pressure.getPressure(P,T);
if (status != 0)
{
// Print out the measurement:
Serial.print("absolute pressure: ");
Serial.print(P,2);
Serial.print(" mb, ");
Serial.print(P*0.0295333727,2);
Serial.println(" inHg");
// The pressuresensor returns abolute pressure, which varies with altitude.
// To remove the effects of altitude, use the sealevel function and your current altitude.
// This number is commonly used in weather reports.
// Parameters: P = absolute pressure in mb, ALTITUDE = current altitude in m.
// Result: p0 = sea-level compensated pressure in mb

p0 = pressure.sealevel(P,ALTITUDE); // we're at 1655 meters (Boulder, CO)


Serial.print("relative (sea-level) pressure: ");
Serial.print(p0,2);
Serial.print(" mb, ");
Serial.print(p0*0.0295333727,2);
Serial.println(" inHg");

// On the other hand, if you want to determine your altitude from the pressure reading,
// use the altitude function along with a baseline pressure (sea-level or other).
// Parameters: P = absolute pressure in mb, p0 = baseline pressure in mb.
// Result: a = altitude in m.

a = pressure.altitude(P,p0);
Serial.print("computed altitude: ");
Serial.print(a,0);
Serial.print(" meters, ");
Serial.print(a*3.28084,0);
Serial.println(" feet");

}
else Serial.println("error retrieving pressure measurement\n");
}
else Serial.println("error starting pressure measurement\n");
}
else Serial.println("error retrieving temperature measurement\n");
}
else Serial.println("error starting temperature measurement\n");

if (client.connect(server, 80)) // "184.106.153.149" or api.thingspeak.com


{
String postStr = apiKey;
postStr += "&field1=";
postStr += String(T,2);
postStr += "&field2=";
postStr += String(P*0.0295333727,2);
postStr += "&field3=";
postStr += String(p0*0.0295333727,2);
postStr += "&field4=";
postStr += String(a,0);
postStr += "\r\n\r\n\r\n\r\n";

client.print("POST /update HTTP/1.1\n");


client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);

Serial.println("");
Serial.println("Data Send to Thingspeak");
}
client.stop();
Serial.println("Waiting...");
Serial.println("");
Serial.println("*************************************************");
delay(5000); // Pause for 5 seconds.
}

PRECAUTIONS
1. Use insulation tools while you connect the Circuit.
2. Wear Good Insulating Shoes.
3. Avoid contacting circuits with wet hands or wet materials.
4. Maintain a work space clear of extraneous material such as books, papers, and clothes.
5. Be careful while connecting any actuators in 230V AC Mains.

Results
VANGALA THANUSREE
REG NO:2210040049
ECE-HONOURS

You might also like