Gustavo Ortenzi
Published

IoT Smart Garden

ESP8266 Sensor Board powered by a Battery, monitoring Soil Humidity and Temperature. Data are been published at Cayenne MQTT server.

AdvancedFull instructions provided12 hours9,670

Things used in this project

Hardware components

ESP8266 ESP-12E
Espressif ESP8266 ESP-12E
It could be any other Module, compatible with ESP8266-07 Pinout and Footprint
×1
SparkFun Lithium Ion Battery
×1
5V 1AMicro USB 18650 Lithium Battery Charging Board Charger Module Protection Dual Functions
×1
SparkFun Soil Moisture Sensor (with Screw Terminals)
SparkFun Soil Moisture Sensor (with Screw Terminals)
×1
Texas Instruments LM35DZ TO92 - Precision Temperature
×1
SparkFun USB to Serial Breakout - FT232RL
SparkFun USB to Serial Breakout - FT232RL
×1

Software apps and online services

Cayenne
myDevices Cayenne
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

Gerber Files for manufacturing

Gerber file which could be used to build boards by your ownself

Bill of Materials

List of components used to build Sensor Board

Schematics

Schematic File - Sensor Board

Electronic Drawing of Electronic Circuitry

PCB File - Sensor Board

PCB printout of Sensor Board. File is not intended to be used for manufacturing.

Code

IoT Smart Garden Sensor Board

Arduino
Arduino IDE source code for Sensor Board
// Author: Gustavo Ortenzi
// Date: 11/October/2017


// Including Libraries for project
#include <ESP8266WiFi.h>
#include <Adafruit_Sensor.h>

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

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "Add your Cayenne Username here";
char password[] = "Add your Cayenne PAssword here";
char clientID[] = "Add your Cayenne ID here";

// WiFi network info.
char ssid[] = "Add your SSID here";
char wifiPassword[] = "Add your SSID password here";

// Deep Sleep Parameters (~16minutos)
uint32_t sleep_time_s = 960 * 1000000;

WiFiClient client;

// Function Prototypes

int average(void);

// Pins Declaration
  const int LM35SW = 13;
  const int VbatSW = 2;
  const int HumSW = 12;

// Average Function
// Math the average value of the analog converter
// Return: AD Value (0 - 1023)
int average(void)
{
  int analogico = 0;
  for ( int i = 0; i < 10; i++) {
    analogico += analogRead(A0);
    delay (500);
  }
  analogico = analogico / 10;
  return analogico;
}

void setup() {

  // Initializing pins
  pinMode(LM35SW, OUTPUT);
  pinMode(VbatSW, OUTPUT);
  pinMode(HumSW, OUTPUT);
  digitalWrite(LM35SW, HIGH);
  digitalWrite(VbatSW, HIGH);
  digitalWrite(HumSW, HIGH);
  delay(10);
  
  //Configurao da UART
  Serial.begin(115200);

    // Connecting to WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, wifiPassword);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
   
   // Printing the ESP IP address
  Serial.println(WiFi.localIP());
  
  // Initializing Cayenne
  Cayenne.begin(username, password, clientID);
 
}
 
  void loop() {
   
  Cayenne.loop();

  Serial.println("");
  Serial.println("-------Inicio--------");

// Temperatura LM35
  digitalWrite(LM35SW, LOW);
  digitalWrite(VbatSW, HIGH);
  digitalWrite(HumSW, HIGH);
  delay(400);
  float temp_celsius;
  temp_celsius = 330 * ( (float)average() / 1023);
  Serial.println("");
  Serial.print("Temperatura:");
  Serial.print(temp_celsius);
  Serial.print("C");
// ************************************************************
// Umidade Solo
  digitalWrite(LM35SW, HIGH);
  digitalWrite(VbatSW, HIGH);
  digitalWrite(HumSW, LOW);
  delay(400);
  int umidade = 0;
  float umidade_percent = 0;
  umidade_percent = 100 * ( (1023 - (float)average()) / 1023);
  umidade = (int)umidade_percent;
  Serial.println("");
  Serial.print("Umidade Percentual Solo:");
  Serial.print(umidade);
  Serial.print("%");
//***************************************************************
// Tenso Bateria
  digitalWrite(LM35SW, HIGH);
  digitalWrite(VbatSW, LOW);
  digitalWrite(HumSW, HIGH);
  delay(400);
  float bateria;
  bateria = 33 * ( (float)average() / 10230 );
  Serial.println("");
  Serial.print("Bateria:");
  Serial.print(bateria);
  Serial.print("Volts");
   
   // Desliga Sensores
   digitalWrite(LM35SW, HIGH);
   digitalWrite(VbatSW, HIGH);
   digitalWrite(HumSW, HIGH);
   delay(300);
  
  Cayenne.celsiusWrite(0, temp_celsius);
  Cayenne.virtualWrite(1, umidade);
  Cayenne.virtualWrite(2, bateria);
  
  ESP.deepSleep(sleep_time_s);

}

Credits

Gustavo Ortenzi

Gustavo Ortenzi

0 projects • 9 followers
Electronic Engineer and lover of DIY and Maker movements inside Open Communities. Enthusiastic of Linux and related embedded devices.

Comments