Introduction: Pressure and Temperature Monitoring Web Server Using ESP8266 and CPS120

About: We are a group of makers. We work in IoT, IOS app, android app, embedded design, sensor design, raspberry pi, arduino, beaglebone, particle electron, particle photon, Bluetooth.

The CPS120 is a high-quality, low-cost capacitive absolute pressure sensor solution with a compensated digital pressure and temperature output for low pressure applications, such as barometric sensing. A robust sensor design (single crystal silicon structure and backside pressure port) makes the CPS120 suitable for extreme temperatures and harsh environments.

Today we will be demonstrating how to monitor the data of CPS120 over Web Server using ESP8266. ESP8266 offers a complete and self-contained WiFi networking solution, it can be used to host the application or to offload WiFi networking functions from another application processor.

SO, lets get started.

Step 1: What We Need !!

Step 2: Hardware Connections

Take ESP8266 and gently push it over the USB Programmer. Then connect the one end of I2C cable to CPS120 sensor and the other end to the USB Programmer. And you are done.

With the help of ESP8266 USB Programmer, it is very easy to program ESP. All you need to do is plug the sensor into USB Programmer and you are good to go. I prefer to use this adapter because it makes a lot easier to connect the hardware. Without these plug and play USB Programmer there is a lot of risk of making wrong connection. A bad wiring can kill your wifi as well as your sensor.

Note: While making connections please make sure the brown wire of the connecting cable is connected to the ground terminal of the sensor and same for USB Programmer.

Step 3: Code

The ESP8266 code for CPS120 can be downloaded from our github repository.

Before going on to the code, make sure you read the instructions given in the Readme file and setup your ESP8266 according to it. It will take just 5 minutes to setup the ESP.

Now, download (or git pull) the code and open it in the Arduino IDE. Compile and upload the code and see the output on Serial Monitor.

Note: Before uploading, make sure you enter your SSID network and password in the code.

You can copy the working ESP code for this sensor from here also:

#include<ESP8266WiFi.h>

#include<WiFiClient.h>

#include<ESP8266WebServer.h>

#include<Wire.h>

// CPS120 I2C address is 0x28(40) #define Addr 0x28

const char* ssid = "Dcube_web"; const char* password = "12345670"; float pressure, cTemp, fTemp;

ESP8266WebServer server(80);

void handleroot() { unsigned int data[4];

// Start I2C Transmission Wire.beginTransmission(Addr);

// Request 4 byte of data Wire.requestFrom(Addr, 4);

// Read 4 bytes of data // pressure msb, pressure lsb, temp msb, temp lsb if (Wire.available() == 4) { data[0] = Wire.read(); data[1] = Wire.read(); data[2] = Wire.read(); data[3] = Wire.read(); delay(300);

// Stop I2C Transmission Wire.endTransmission();

// Convert the data to 14 bits pressure = ((((data[0] & 0x3F) * 265 + data[1]) / 16384.0 ) * 90.0 ) + 30.0 ; cTemp = ((((data[2] * 256) + (data[3] & 0xFC)) / 4.0 ) * (165.0 / 16384.0)) - 40.0; fTemp = cTemp * 1.8 + 32;

// Output data to serial monitor Serial.print("Pressure is : "); Serial.print(pressure); Serial.println(" kPa"); Serial.print("Temperature in Celsius : "); Serial.print(cTemp); Serial.println(" C"); Serial.print("Temperature in Fahrenheit : "); Serial.print(fTemp); Serial.println(" F");

// Output data to web server

server.sendContent

("<html><head><meta http-equiv='refresh' content='5'</meta>"

"<h1 style=text-align:center;font-size:300%;color:blue;font-family:britannic bold;>CONTROL EVERYTHING</h1>" "<h3 style=text-align:center;font-family:courier new;><a href=http://www.controleverything.com/ target=_blank>www.controleverything.com</a></h3><hr>" "<h2 style=text-align:center;font-family:tahoma;><a href=https://www.controleverything.com/content/Barometer?sku=CPS120_I2CS#tabs-0-product_tabset-2/ \n" "target=_blank>CPS120 Sensor I2C Mini Module</a></h2>");

server.sendContent

("<h3 style=text-align:center;font-family:tahoma;>Pressure = " + String(pressure) + " kPa");

server.sendContent

("<h3 style=text-align:center;font-family:tahoma;>Temperature in Celsius = " + String(cTemp) + " C");

server.sendContent

("<h3 style=text-align:center;font-family:tahoma;>Temperature in Fahrenheit = " + String(fTemp) + " F"); } delay(1000); }

void setup() { // Initialise I2C communication as MASTER Wire.begin(2, 14); // Initialise serial communication, set baud rate = 115200 Serial.begin(115200);

// Connect to WiFi network WiFi.begin(ssid, password);

// Wait for connection while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected to "); Serial.println(ssid);

// Get the IP address of ESP8266 Serial.print("IP address: "); Serial.println(WiFi.localIP());

// Start the server server.on("/", handleroot); server.begin(); Serial.println("HTTP server started"); }

void loop() { server.handleClient(); }

Copy the IP address of ESP8266 from the Serial Monitor and paste it in your web browser.

You will see a web page with pressure and temperature reading. The output of the sensor on Serial Monitor and Web Server are shown in the picture above.

Step 4: Applications and Features

CPS120 Sensor has various indusrty level applications like Portable and Stationary Barometers, Altimeters, Weather Stations, GPS Applications, Hard Disk Drives (HDD), Industrial Equipment, Air Control Systems, Vacuum Systems.

Step 5: Conclusion

With the help of ESP8266, we can take CPS120 to a whole new level. We can collect and manage the data over the Internet or control our Home Appliances over the Wi-fi Network, use them in Home Automation or build a Sensor Network or use it in Wearable Electronics or WiFi Location-aware Devices and many more like this.

For more information about CPS120 and ESP8266, check out the links below:

For more info, visit Control Everything.