» » » Pressure and Temperature Monitoring Web Server using ESP8266 and CPS120

Pressure and Temperature Monitoring Web Server using ESP8266 and CPS120

posted in: Others | 0
Picture of Pressure and Temperature Monitoring Web Server using ESP8266 and CPS120

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 !!

Picture of What we need !!
New Image.jpg New Image2.jpg
New Image4.jpg

Step 2: Hardware Connections

Picture of Hardware Connections
New Image9.jpg New Image6.jpg
New Image8.jpg

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

Picture of Code
Screenshot (15).png
Screenshot (17).png

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 theReadme 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:





// 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


(“<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>”);


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


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


(“<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 cancollect and manage the data over the Internet or control our Home Appliances over the Wi-fi Network, use them in Home Automation or build aSensor 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.

Leave a Reply