Hardware components | ||||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
Software apps and online services | ||||||
![]() |
|
I want to present an IoT barometer. It permits to measure and store temperature and pressure data in theAdafruit IoT Platform.
I have published a similar project that measures temperature and humidity.
For this project, I used a BMP280 sensor connected to an ESP8266. This one connects via wifi to send data to the Adafruit IO platform.
I show a picture of my dashboards.
If you do not know about Adafruit IO. Go to the following link for a tutorial:
Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-analog-input
Note: If you are having issues connecting, please ensure you have the latest Adafruit IO Arduino library.
Diagram
Power Pins:
• Vin: 3-5VDC.
• 3Vo: 3.3V output from the voltage regulator.
• GND - common ground for power and logic.
I2C Logic pins:
• SCK: the I2C clock pin, connect to your microcontroller I2C clock line.
• SDI: the I2C data pin, connect to your microcontroller I2C data line.
Connections
D1 => SCK
D2 => SDI
• Vin: 3-5VDC.
• 3Vo: 3.3V output from the voltage regulator.
• GND - common ground for power and logic.
I2C Logic pins:
• SCK: the I2C clock pin, connect to your microcontroller I2C clock line.
• SDI: the I2C data pin, connect to your microcontroller I2C data line.
Connections
D1 => SCK
D2 => SDI

// IoT Barometer
// Based on:
// Adafruit IO Analog In Example
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-analog-input
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Written by Todd Treece for Adafruit Industries
// Copyright (c) 2016 Adafruit Industries
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.
/************************** Configuration ***********************************/
// edit the config.h tab and enter your Adafruit IO credentials
// and any additional configuration needed for WiFi, cellular,
// or ethernet clients.
#include "config.h" // include config.h. it contains wifi and Adafruit credentials
#include <Wire.h> // I2C library
#include <Adafruit_BMP280.h> // BMP280 library
/************************ Example Starts Here *******************************/
// Variable declarations
float current_temp = 0;
float last_temp = -1;
float current_pres = 0.0;
float last_pres = -1;
Adafruit_BMP280 bmp; // sensor object
// set up the feeds
AdafruitIO_Feed *tempe_feed = io.feed("tempe_feed");
AdafruitIO_Feed *pres_feed = io.feed("pres_feed");
void setup() {
// start the serial connection
Serial.begin(115200);
// wait for serial monitor to open
while(! Serial);
// connect to io.adafruit.com
Serial.print("Connecting to Adafruit IO");
io.connect();
// wait for a connection
while(io.status() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}
// we are connected
Serial.println();
Serial.println(io.statusText());
if (!bmp.begin()) {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
while (1);
}
/* Default settings from datasheet. */
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
Adafruit_BMP280::FILTER_X16, /* Filtering. */
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
}
void loop() {
// io.run(); is required for all sketches.
// it should always be present at the top of your loop
// function. it keeps the client connected to
// io.adafruit.com, and processes any incoming data.
io.run();
// read presure value
float pres = bmp.readPressure();
// read temperature
float temp = bmp.readTemperature();
// wait 10 seconds
delay(10000);
// Check for reading errors
if (isnan(pres) || isnan(temp)){
Serial.println("Error en obtener los datos ");
return;
}
// Save currrent values
current_temp = temp;
current_pres = pres / 100;
// return if the value hasn't changed
if((current_temp == last_temp) && (current_pres == last_pres))
return;
// save the current state to the presure and temperature feeds
Serial.println("sending -> ");
Serial.println(current_temp);
tempe_feed->save(current_temp);
Serial.println(current_pres);
pres_feed->save(current_pres);
// Store last values
last_temp = current_temp;
last_pres = current_pres;
// wait for 50 seconds to complete 1 minute.
delay(50000);
}
/************************ Adafruit IO Config *******************************/
// visit io.adafruit.com if you need to create an account,
// or if you need your Adafruit IO key.
#define IO_USERNAME "rjconcepcion"
#define IO_KEY "ce712b7e28e641ada9ce2757ccf00bcb"
/******************************* WIFI **************************************/
// the AdafruitIO_WiFi client will work with the following boards:
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
// - Feather WICED -> https://www.adafruit.com/products/3056
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
// - Adafruit Metro M4 Express AirLift Lite -> https://www.adafruit.com/product/4000
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
#define WIFI_SSID "SSID"
#define WIFI_PASS "Wifi password"
// uncomment the following line if you are using airlift
// #define USE_AIRLIFT
// uncomment the following line if you are using winc1500
// #define USE_WINC1500
// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE)
// Configure the pins used for the ESP32 connection
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
// Don't change the names of these #define's! they match the variant ones
#define SPIWIFI SPI
#define SPIWIFI_SS 10 // Chip select pin
#define NINA_ACK 9 // a.k.a BUSY or READY pin
#define NINA_RESETN 6 // Reset pin
#define NINA_GPIO0 -1 // Not connected
#endif
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS, NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
#else
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
#endif
/******************************* FONA **************************************/
// the AdafruitIO_FONA client will work with the following boards:
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
// uncomment the following two lines for 32u4 FONA,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_FONA.h"
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
/**************************** ETHERNET ************************************/
// the AdafruitIO_Ethernet client will work with the following boards:
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
// uncomment the following two lines for ethernet,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_Ethernet.h"
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
11 projects • 8 followers
Electronic is my passion. I like to work with programming devices like Arduino, ESP8266, Raspberry Pi. I enjoy design electronic projects.
Comments
Please log in or sign up to comment.