Sanyam B Mehta
Created January 29, 2016

IoT based Coffee Management System(CMS)

“Coffee is the oil of modern office societies.”Our main motive is to transform a simple coffee machine into an Internet of things device.

IntermediateFull instructions provided1,065
IoT based Coffee Management System(CMS)

Things used in this project

Hardware components

Raspberry Pi 2 Model B
Raspberry Pi 2 Model B
×1
Arduino MKR1000
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Relay (generic)
×1
Usb powered webcamera
×1
pressure pads FSR
×2

Software apps and online services

Windows 10 IoT Core
Microsoft Windows 10 IoT Core
ThingSpeak API
ThingSpeak API
Visual Studio 2015
Microsoft Visual Studio 2015
Arduino IDE
Arduino IDE

Story

Read more

Schematics

Connection Diagram

Code

cms_arduino

Arduino
/*
This sketch is a combination of ADAFruits DHT sketch, WiFi101 Webclient,I2C connection to Rasberry pi2,pressure pad SEN-09376-10kg
and The arduino example from ThingSpeak
Modified by Sanyam Mehta for the MKR1000, feel free to use
 */


#include <SPI.h>
#include <WiFi101.h>
#include <Wire.h>  
#include "DHT.h"

#define DHTPIN 1  // what pin DHT data line is connected to, pin1 is 5th pin from end
 #define SLAVE_ADDRESS 0x40   // Define the i2c address
// Uncomment whatever DHT sensor type you're using!
#define DHTTYPE DHT11  // DHT 11
//#define DHTTYPE DHT21  // DHT 21
//#define DHTTYPE DHT22  // DHT 22

DHT dht(DHTPIN,DHTTYPE);
// Local Network Settings
char ssid[] = "your SSID key";  // your network SSID (name)
char pass[] = "password?";    // your network password
int keyIndex = 0;             // your network key Index number (needed only for WEP)

int pressure_temp;




// ThingSpeak Settings
int status = WL_IDLE_STATUS;
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)

char thingSpeakAddress[] = "api.thingspeak.com";  // name address for Google (using DNS)
String APIKey = "Your API key";             // enter your channel's Write API Key

// Variable Setup
long lastConnectionTime = 0;
boolean lastConnected = false;

// Initialize Arduino Ethernet Client
WiFiClient client;

void setup() {
  // Start Slave address for sending pressure value of the cup
 
  Wire.begin(SLAVE_ADDRESS); 
  

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
   
    //WiFi shield not present don't continue:
    while (true);
  }

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) {
   //Attempting to connect to SSID

    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
//Connected to wifi
  
}

void loop() {
  
  // Wait a few seconds between measurements.
   delay(2000);
  // read values from pins and store as strings
   int h = dht.readHumidity();
  // Read temperature as Celsius (the default)
   int t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
   int f = dht.readTemperature(true);
  //read values for pressure pads connected to 
  pressure_temp = analogRead(A0); // read pressure value of water
  String p = String(pressure_temp,DEC);
int   pressure_temp_machine = analogRead(A1); // read pressure value of coffee machine
  String pmachine = String(pressure_temp_machine,DEC);
  Wire.onRequest(sendData); // this will be sent through I2C
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f))
  {
   //Failed to read from DHT sensor!
    return;
  }

  // Compute heat index in Fahrenheit (the default)
  int hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  int hic = dht.computeHeatIndex(t, h, false);

 
 

  
//Starting connection to server...
  // if you get a connection, report back via serial:
  if (client.connect(thingSpeakAddress, 80)) {
   //connected to server


          client.print(F("POST "));
          client.print("/update?key=apiKey&field1=" 
          +               (String) h
          +  "&field2=" +(String) t
          +  "&field3=" +(String) f
           +  "&field4=" + p
          +  "&field5=" +(String) hic
          +  "&field6=" +(String) hif
          +  "&field7=" +pmachine  );
                                      
          String tsData = "field1="   //need the length to give to ThingSpeak
          +             (String)  h
          +  "&field2=" +(String) t
          +  "&field3=" +(String) f
           +  "&field4=" + p
          +  "&field5=" +(String) hic
          +  "&field6=" +(String) hif
           +  "&field7=" +pmachine; 


          client.print("POST /update HTTP/1.1\n");  
          client.print("Host: api.thingspeak.com\n");
          client.print("Connection: close\n");
          client.print("X-THINGSPEAKAPIKEY: " + APIKey + "\n");
          client.print("Content-Type: application/x-www-form-urlencoded\n");
          client.print("Content-Length: ");
          client.print(tsData.length());  //send out data string legth to ts
          client.print("\n\n");
          client.print(tsData);
          client.stop();
          delay(1000);
    } 

}



void sendData()

{
//data sent to raspberry pi2 
 Wire.write(pressure_temp); 


}

Github

Please check Coffee-Management-System.zip and then download it

Credits

Sanyam B Mehta
1 project • 0 followers
Thanks to Sebastian Zug.

Comments