Hendra Kusumah
Published © GPL3+

Smart Connected Open Source Pot (Scopot)

A Smart Pot that has all the component inside of the pot and gives the light and humidity data to the web

IntermediateShowcase (no instructions)2 hours4,464
Smart Connected Open Source Pot (Scopot)

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
×1
Solid State Relay
Solid State Relay
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
SparkFun water pump
×1

Software apps and online services

Arduino IDE
Arduino IDE
Ubidots
Ubidots

Hand tools and fabrication machines

rotary rool

Story

Read more

Schematics

Scopot Fritzing

Code

Scopot Code

Arduino
Make sure you already have the arduino MKR1000 library
#include <SPI.h>
#include <WiFi101.h>

char ssid [] = "Wifi SSID";
char password [] = "Wifi Password";
int keyIndex = 0;
int status = WL_IDLE_STATUS;

#define errorPin 6
const int sleepTimeS = 20;// Time to sleep (in seconds):
long lastReadingTime = 0;
WiFiClient client;

String idvariable = "ubidots_variable_id";
String token = "ubidots_token";
int Relay = 12; 
const int sensorMin = 0;      // sensor minimum, discovered through experiment
const int sensorMax = 1023;    // sensor maximum, discovered through experiment

//////////////////////////////////////////////////////////////////////////////////

void setup(){

  pinMode(errorPin, OUTPUT);
  pinMode(Relay, OUTPUT);
  

  for (int i=0;i<4; i++){   // let know we are working
    digitalWrite(errorPin ,HIGH);
    delay(200);
    digitalWrite(errorPin ,LOW);
    delay(200);
  }

  // Create an instance of the server
  // specify the port to listen on as an argument

  WiFiServer server(80);
  Serial.begin(9600);
  delay(10);

 
   if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }
 int n = WiFi.scanNetworks();
  Serial.println("scan done");
 
  if (n == 0){
    Serial.println("no networks found");
    Serial.println("Going into sleep");
// ESP.deepSleep(sleepTimeS * 1000000);
  }

  while (status != WL_CONNECTED) {
    delay(500);
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, password);
    delay(10000);
  }
  
  Serial.println("");
  Serial.println("WiFi connected");
  printWifiStatus();

  // Start the server
  server.begin();
  Serial.println("WiFi Server started");
 


}

////////////////////////////////////////////////////////////////////////////////

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}
void loop(){
  int value = (analogRead(A0));
  ubiSave_value(String(value));
  
  Serial.println("Ubidots data");
  Serial.println(value);
  Serial.println(" Going to Sleep for a while !" );

 
  delay(10000);// change this for the upload data time to ubidots 
  
}

void ubiSave_value(String value) {
  // if you get a connection, report back via serial:
  int num=0;
  String var = "{\"value\": " + String(value)+"}";
  num = var.length();
  if (client.connect("things.ubidots.com", 80)) {
    Serial.println("connected ubidots");
    delay(100);
    client.println("POST /api/v1.6/variables/"+idvariable+"/values HTTP/1.1");
    Serial.println("POST /api/v1.6/variables/"+idvariable+"/values HTTP/1.1");
    client.println("Content-Type: application/json");
    Serial.println("Content-Type: application/json");
    client.println("Content-Length: "+String(num));
    Serial.println("Content-Length: "+String(num));
    client.println("X-Auth-Token: "+token);
    Serial.println("X-Auth-Token: "+token);
    client.println("Host: things.ubidots.com\n");
    Serial.println("Host: things.ubidots.com\n");
    client.print(var);
    Serial.print(var+"\n");

  }
  else {
    // if you didn't get a connection to the server:
    Serial.println("ubidots connection failed");
  }

  if (!client.connected()) {
    Serial.println("NotConnected");
    Serial.println("disconnecting ubidots.");
    client.stop();
    // do nothing forevermore:
    for(;;);
  }

  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
}

Credits

Hendra Kusumah

Hendra Kusumah

30 projects • 126 followers
Love hacking and making new things from IoT to robotics
Thanks to Akin Yildiz.

Comments