Adithya TG
Published

Smart Kitchen Containers

Kitchen at your Fingertips!

BeginnerProtip3 hours1,232
Smart Kitchen Containers

Things used in this project

Hardware components

ESP8266 ESP-01
Espressif ESP8266 ESP-01
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1

Software apps and online services

Cayenne
myDevices Cayenne
Arduino IDE
Arduino IDE

Story

Read more

Schematics

Working of Smart Containers

Working of smart Containers

Cayenne Screenshot

Circuit1

Circuit2

Setup

Setup2

Connection

Code

Smart Containers

Arduino
Shows the amount of contents in the Container
// This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.
// Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling. 
int echoPin1=2,trigPin1=0;

#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>

// WiFi network info.
char ssid[] = "***";
char wifiPassword[] = "***";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "***************";
char password[] = "***************";
char clientID[] = "***************";

unsigned long lastMillis = 0;

void setup() {
  Serial.begin(9600);
  Serial.println("hello");
// pinMode(LED_BUILTIN, OUTPUT); 
 pinMode(echoPin1,INPUT);
 pinMode(trigPin1,OUTPUT);
//  digitalWrite(LED_BUILTIN, LOW);
 // delay(3000);
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
   int duration,distance;
    
  Cayenne.loop();
  //-----------------------------------------------------------------------------------------------------------------------------------
  //                                                 Content Measurement
  //-----------------------------------------------------------------------------------------------------------------------------------
       digitalWrite(trigPin1,LOW);
       delayMicroseconds(2); 
       digitalWrite(trigPin1,HIGH);
       delayMicroseconds(10); 
       digitalWrite(trigPin1,LOW);
       duration = pulseIn(echoPin1,HIGH);
       distance = ((duration/2))/29.1;
       Serial.println(distance);
       delay(300);
  //-----------------------------------------------------------------------------------------------------------------------------------
//                                                End of Content Measurement
  //-----------------------------------------------------------------------------------------------------------------------------------
  //Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
  if (millis() - lastMillis > 1000) {
    lastMillis = millis();
    
    Cayenne.virtualWrite(0, distance, TYPE_PROXIMITY, UNIT_CENTIMETER);    // writing the content information
  }
}


      

Credits

Adithya TG

Adithya TG

3 projects • 65 followers
Passionate Electronics and communication engineering, IOT, MicroControllers.

Comments