L O A D I N G
blog banner

OrganiCom | Turn your plant into a smart one (to the level that it starts tweeting)

Last weekend, during my “consolation time” after getting bummed up in a Hackathon, I needed something interesting to do (Lmao I had my next 48 hours planned fr, as I was expecting to move forward with the hackathon). Anyways, that reminded me of a blog article that I came across a few days ago, which was about some scientists from the Massachusetts Institute of Technology who taught spinach to send emails. At first, I was baffled about how they did it, but after some deep diving into it, they used nanotech to detect nitroaromatics (mostly found in explosives).

So, I was indeed desperate (for some tech-based ideas, ofc) and thought of other procedures to implement the same, something to the level of technology that I had access to and then I looked for a NodeMCU, a soil moisture sensor, understood some portion about GET requests, and finally came across this platform called IFTTT that allows you to tweet or do some task whenever an event is triggered.

After I posted about it on my social handles (you can find em in the author column at the bottom), the reach was tremendous, as compared to my previous posts and even a bunch of curious techies wanted to know more about it, so here’s how you can build one yourself!

Here’s what you’ll need to do the same:

  • NodeMCU
  • Soil Moisture Sensor
  • Jumper wires

So to start off with it, you’ll have to connect A0 of the NodeMCU to the Soil Moisture Sensor’s Data pin (marked as A0). Connect the 3V3 pin to the one on NodeMCU, and GND to GND in a similar manner and voila, we’re done with the hardware part!

For this part, you’ll need an IFTTT account, so make one here. Go to applets and create an applet. Choose webhooks in “THIS” part, put up any event name like “detect” and in “THAT” part, choose Twitter and “Post a tweet”. Replace “{{EventName}}” with your event (detect in our case).

After that, you need to program the NodeMCU in such a way, that it triggers that GET request.

Here’s the code:

#include <ESP8266WiFi.h>
const char *ssid =  "WiFi SSID";
const char *pass =  "WiFi Password";
const char* _getLink = "https://maker.ifttt.com/trigger/"event_name"/with/key/key_here";
const int sensor_pin = A0;
WiFiClient client;
void setup()
{
  Serial.begin(9600);
  delay(10);
  Serial.println("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
}
void loop()
{
  float moisture_percentage;
  moisture_percentage = ( 100.00 - ( (analogRead(sensor_pin) / 1023.00) * 100.00 ) );
  Serial.print("Soil Moisture(in Percentage) = ");
  Serial.print(moisture_percentage);
  if (moisture_percentage < 30) {
    String link = "maker.ifttt.com";
    if (client.connect(link, 80)) {
      String getStr = _getLink + String(random(0, 100000));
      Serial.println(getStr);
      client.print("GET " + getStr + "\n");
      client.print("HTTP/1.1\n");
      client.print("Host: maker.ifttt.com\n");
      client.print("Connection: close\n\n\n");
      while (client.available()) {
        char c = client.read();
        Serial.print(c);
        Serial.print("and done!");
      }
      Serial.println("");
    }
    else {
      Serial.println("nope");
    }
    delay(900000);
  }
}

Just upload it and you’ll be good to go. Drop a comment in case you have any problems with it, and you do know where to reach out to me.

Leave a Reply

Your email address will not be published. Required fields are marked *



shares