IlaryGila
Published © CC BY-NC-SA

Compressor & IoT

Remote control and data analysis of a compressor with the Blynk app and Google Sheets

IntermediateFull instructions provided77
Compressor & IoT

Things used in this project

Hardware components

Wemos D1 Mini
Espressif Wemos D1 Mini
×1
Breadboard (generic)
Breadboard (generic)
×1
SHT30
×1
Accelerometer GY-521
×1
Pressure sensor
×1
Resistor 330 ohm
Resistor 330 ohm
×1
Resistor 100 ohm
Resistor 100 ohm
×1
Through Hole Resistor, 20 ohm
Through Hole Resistor, 20 ohm
×2

Software apps and online services

Blynk
Blynk
Google Sheets
Google Sheets

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)
Multitool, Screwdriver
Multitool, Screwdriver

Story

Read more

Custom parts and enclosures

Box and Support

Schematics

Compressor and WeMos

Code

Compressor and WeMos

Arduino
#include <Wire.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <WiFiClientSecure.h>
#include <WEMOS_SHT3X.h>
SHT3X sht30(0x45);
BlynkTimer timer;
BlynkTimer timer2;

const int MPU = 0x68;
int16_t AcZ;
int LED = LED_BUILTIN;
double t;
double h;
double v;
double p;
int Pressure = A0;
WidgetLED led1(V5);

char auth[] = "xxxxxxxxxxxxxxxxxxx";  //your Blynk authentication token
String readString;
const char* ssid = "xxxxxxxxxxxxxxxxxxx";  //your network SSID
const char* password = "xxxxxxxxxxxxxxxxxxx";  //your network password

const char* host = "script.google.com";
const int httpsPort = 443;

WiFiClientSecure client;


const char* fingerprint = "75 E0 AB B6 13 85 12 27 1C 04 F8 5F DD DE 38 E4 B7 24 2E FE";
String GAS_ID = "xxxxxxxxxxxxxxxxxxx";  // Replace by your GAS service id

void setup()
{
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B);
  Wire.write(0);
  Wire.endTransmission(true);
  Serial.begin(115200);
  pinMode(LED, OUTPUT);
  pinMode(Pressure, INPUT);
  Serial.println();
  Serial.print("Connecting to wifi: ");
  Serial.println(ssid);
  // flush() is needed to print the above (connecting...) message reliably,
  // in case the wireless connection doesn't go through
  Serial.flush();

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  Blynk.begin(auth, ssid, password);
  timer.setInterval(120000L, push);
  timer2.setInterval (1000L, data);
}

BLYNK_CONNECTED() {
  Blynk.syncAll();
}

void loop()
{
  Blynk.run();
  timer.run();
  timer2.run();
}

void push() {
  sendData(t, h, p, v);
}

void data () {
  Wire.beginTransmission(MPU);
  Wire.write(0x3B);
  Wire.endTransmission(false);
  Wire.requestFrom(MPU, 12, true);
  AcZ = Wire.read() << 8 | Wire.read();
  Serial.print("Vibration: ");
  Serial.print(" | Z = "); Serial.println(AcZ);
  v = AcZ;
  p = analogRead(Pressure);
  p = map (p, 0, 1023, 0, 1200);
  p = p / 100;
  Serial.print("Pressure :");
  Serial.println(p);
  Blynk.virtualWrite(V1, p);
  Blynk.virtualWrite(V2, p);
  Blynk.virtualWrite(V3, t);

  if (sht30.get() == 0) {
    t = sht30.cTemp;
    h = sht30.humidity;
    Serial.print("Temperature in Celsius : ");
    Serial.println(t);
    Serial.print("Relative Humidity : ");
    Serial.println(h);
  }
  else
  {
    Serial.println("Error!");
  }
  if (v > 18000 || v < 17000) {
    led1.on();
  }
  else {
    led1.off();
  }
}

BLYNK_WRITE(V0) {
  int pinValue = param.asInt();
  if (pinValue == 1) {
    digitalWrite(LED, LOW); // Turn LED on.
  } else {
    digitalWrite(LED, HIGH); // Turn LED off.
  }
}

void sendData(double x, double y, double z, double k)
{
  Serial.print("connecting to ");
  Serial.println(host);
  if (!client.connect(host, httpsPort)) {
    Serial.println("connection failed");
    return;
  }

  if (client.verify(fingerprint, host)) {
    Serial.println("certificate matches");
  } else {
    Serial.println("certificate doesn't match");
  }
  String string_x     =  String(x);
  String string_y     =  String(y);
  String url = "/macros/s/" + GAS_ID + "/exec?temperature=" + string_x + "&humidity=" + string_y + "&pressure=" + p + "&vibration=" + v;
  Serial.print("requesting URL: ");
  Serial.println(url);

  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "User-Agent: BuildFailureDetectorESP8266\r\n" +
               "Connection: close\r\n\r\n");

  Serial.println("request sent");
  while (client.connected()) {
    String line = client.readStringUntil('\n');
    if (line == "\r") {
      Serial.println("headers received");
      break;
    }
  }
  String line = client.readStringUntil('\n');
  if (line.startsWith("{\"state\":\"success\"")) {
    Serial.println("esp8266/Arduino CI successfull!");
  } else {
    Serial.println("esp8266/Arduino CI has failed");
  }
  Serial.println("reply was:");
  Serial.println("==========");
  Serial.println(line);
  Serial.println("==========");
  Serial.println("closing connection");
}

Credits

IlaryGila

IlaryGila

1 project • 0 followers

Comments

Add projectSign up / Login