Akshayan SinhaCommon9899
Published

Arduino IoT | IoT Platform Series #4 (Part 1)

Monitor and Control a Hardware Device (ESP32 Dev Board) from Arduino IoT Cloud

IntermediateFull instructions provided35
Arduino IoT | IoT Platform Series #4 (Part 1)

Things used in this project

Hardware components

Adafruit HUZZAH32 – ESP32 Feather Board
Adafruit HUZZAH32 – ESP32 Feather Board
×1
SparkFun Atmospheric Sensor Breakout - BME280
SparkFun Atmospheric Sensor Breakout - BME280
×1

Software apps and online services

Arduino IoT Cloud
Arduino IoT Cloud
Arduino IDE
Arduino IDE
Arduino Web Editor
Arduino Web Editor

Story

Read more

Code

BME280 Sensor data to Cloud

C/C++
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>
#include <Wire.h>
#include "SparkFunBME280.h"

#define SEALEVELPRESSURE_HPA (1013.25)

BME280 mySensor;
float temp;
bool light;
int LED = 2;
void onLightChange();

const char THING_ID[]           = " ";    // Thing ID of Arduino Cloud
const char DEVICE_LOGIN_NAME[]  = " ";    // Device ID of Thing
const char DEVICE_KEY[]         = " ";    // Secret device password

const char SSID[]               = " ";    // Network SSID (name)
const char PASS[]               = " ";    // Network password (use for WPA, or use as key for WEP)

void initProperties(){
  ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);
  ArduinoCloud.setSecretDeviceKey(DEVICE_KEY);
  ArduinoCloud.setThingId(THING_ID);
  ArduinoCloud.addProperty(temp, READ, 1 * SECONDS, NULL);
}

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

void setup() { 
  pinMode(LED, OUTPUT); 
  Serial.begin(9600);
  delay(1500); 
  
  // Defined in thingProperties.h
  initProperties();
  
  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
  
  Wire.begin();
  if (mySensor.beginI2C() == false) //Begin communication over I2C
  {
    Serial.println("The sensor did not respond. Please check wiring.");
    while(1); //Freeze
  }
}

void loop() {
  ArduinoCloud.update();
  temp = mySensor.readTempC();
  delay(500);
}

void onLightChange() {
  if(light){
    digitalWrite(LED, HIGH);
  }
  else{
    digitalWrite(LED, LOW);
  }
}

Credits

Akshayan Sinha

Akshayan Sinha

17 projects β€’ 13 followers
A maker who makes.
Common9899

Common9899

38 projects β€’ 28 followers

Comments

Add projectSign up / Login