Mitch K
Published © CC BY-NC

Moisty v2 - a Plant Moisture Sensor

This is a 6x plant moisture sensor using Cayenne & a 3D printed case.

EasyShowcase (no instructions)5 hours1,434
Moisty v2 - a Plant Moisture Sensor

Things used in this project

Hardware components

Arduino Pro Mini 328 - 5V/16MHz
SparkFun Arduino Pro Mini 328 - 5V/16MHz
×1
ESP8266 ESP-01
Everything ESP ESP8266 ESP-01
×1
SparkFun microB USB Breakout
SparkFun microB USB Breakout
×1
SparkFun Voltage Regulator - 3.3V
×1
100uf Capacitor
×2
Soil moisture sensor
×6
Blank PCB board
×1

Software apps and online services

Cayenne
myDevices Cayenne

Hand tools and fabrication machines

3d printer

Story

Read more

Custom parts and enclosures

Case_top

STL of the top of the case

Case_bottom

bottom of the case

Schematics

Circuit

Plantmoisture schem yzrxgcbxyu

Code

Moisty code

Arduino
#include <Arduino.h>
#include <CayenneESP8266Shield.h>

#define SERIAL_BUFFER_SIZE    256
#define SERIAL_TX_BUFFER_SIZE 256
#define SERIAL_RX_BUFFER_SIZE 256


char token[] = "token";
char ssid[] = "wifi";
char password[] = "wifipassword";

#define EspSerial             Serial
ESP8266 wifi(EspSerial);

const unsigned long interval = 120000;  // milliseconds to check moisture

unsigned long time1 = 0;
unsigned long onlineTime;
unsigned long prevTime;

byte disco = 0;


void setup()
{
	EspSerial.begin(9600);
	delay(10);

	pinMode(2, OUTPUT);
	pinMode(3, OUTPUT);
	pinMode(4, OUTPUT);
	pinMode(5, OUTPUT);
	pinMode(6, OUTPUT);
	pinMode(7, OUTPUT);
	pinMode(13, OUTPUT);

	Cayenne.begin(token, wifi, ssid, password);
}



void loop()
{
	Cayenne.run();

	if (millis() - time1 > interval)
	  {
		  runMoist();
		  time1 = millis();
	  }
}



void runMoist()
{
	int x = 2; // pwr pin
	int y = 0; // data
	int z = 1; // channel


	for (byte i = 0; i <= 6; i++)
	  {
		  checkMoist(x, y, z);
		  x++;
		  y++;
		  z++;

		  if (y == 4)
		    {
			    y = 6;
		    }
	  }
}


void checkMoist(byte pwrPin, byte dataPin, byte channel)
{
	digitalWrite(pwrPin, HIGH);
	delay(300);
	float plant = ( 1024 - analogRead(dataPin) );
	byte plantPer = float(plant / 800) * 100;  // ~800 is top range for my sensors

	digitalWrite(pwrPin, LOW);

	Cayenne.virtualWrite(channel, plantPer);

}





CAYENNE_CONNECTED()
{
	prevTime = millis();
	digitalWrite(13, HIGH);

}

CAYENNE_DISCONNECTED()
{
	disco++;
	digitalWrite(13, LOW);
}



CAYENNE_OUT(V23)
{
	Cayenne.virtualWrite(V23, disco);
}

CAYENNE_OUT(V24)
{
	float time2 = ( millis() / 1000 ) / 60;
	Cayenne.virtualWrite(V24, time2);
}

CAYENNE_OUT(V25)
{
	onlineTime = ( ( millis() - prevTime ) / 1000 ) / 60;
	Cayenne.virtualWrite(V25, onlineTime);
}

Credits

Mitch K

Mitch K

0 projects • 9 followers
Contact

Comments