Mandy's Farm Smart Greenhouse

In this smart greenhouse, you'll find sensors that measure the moisture in the soil, temperature, humidity in the air, and water flowrate.

AdvancedWork in progress161
Mandy's Farm Smart Greenhouse

Things used in this project

Hardware components

Boron
Particle Boron
×1
General Purpose Transistor PNP
General Purpose Transistor PNP
×4
Resistor 10k ohm
Resistor 10k ohm
×4
Resistor 220 ohm
Resistor 220 ohm
×4
4-CHANNEL RELAY CONTROLLER FOR I2C
ControlEverything.com 4-CHANNEL RELAY CONTROLLER FOR I2C
×1
Solenoid Valve, 2 Way
Solenoid Valve, 2 Way
×4
Flow Sensor, Analog Output
Flow Sensor, Analog Output
×1
Gravity: Analog Capacitive Soil Moisture Sensor- Corrosion Resistant
DFRobot Gravity: Analog Capacitive Soil Moisture Sensor- Corrosion Resistant
×5
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
SparkFun 7-Segment Serial Display - Red
SparkFun 7-Segment Serial Display - Red
×2
Gravity:Digital Push Button (Yellow)
DFRobot Gravity:Digital Push Button (Yellow)
×4

Software apps and online services

Visual Studio Code Extension for Arduino
Microsoft Visual Studio Code Extension for Arduino

Story

Read more

Custom parts and enclosures

Mandy's Enclosure 1

Mandy's Enclosure 2

Schematics

Mandy's Fritz

Mandy's Schem

Code

Mandy' Farm

C/C++
// RELAY VARIABLES
#define RELAYPIN1 D2
#define RELAYPIN2 D3
#define RELAYPIN3 D4
#define RELAYPIN4 D5
const int buttonPin1 = D6;
const int buttonPin2 = D7;
const int buttonPin3 = A0;
const int buttonPin4 = A5;
int relaypins[] = {RELAYPIN1, RELAYPIN2, RELAYPIN3, RELAYPIN4};
int relayCount = 4;
int relayState1;
int relayState2;
int Off = HIGH;
int On = LOW;
//TIMER VARIABLE
unsigned long lastRelaytimer = 0;
// SOIL MOISTURE VARIABLES
const int AirValue = 3580;
const int WaterValue = 330;
int intervals = (AirValue - WaterValue) / 3;
int moisturePin1 = A1;
int moisturePin2 = A2;
int moisturePin3 = A3;
int moisturePin4 = A4;
int moisturePins[] = {moisturePin1, moisturePin2, moisturePin3, moisturePin4};
int currentState;
int lastState1 = 0;
int modeCount = 0;


#define FLOWSENSORPIN D13


void setup(){
  Serial.begin(9600);
  init();
  //attachInterrupt(FLOWSENSORPIN, flowMeter, RISING);
}

void loop(){
  modeChangebutton();
  modes();
}
// INITIALIZE SETUP
void init(){
  for (int thispin = 0; thispin <= relayCount; thispin++){
    pinMode(relaypins[thispin], OUTPUT);
    pinMode(moisturePins[thispin], INPUT);
    pinMode(buttonPin1, INPUT);
    relayOff(relaypins[thispin], Off);
    pinMode(D13, INPUT);
  }
}
//Cycles Mode Number 
int modeChangebutton(){
   currentState = digitalRead(buttonPin1);
    if(currentState != lastState1){
      if(currentState == HIGH){
        modeCount++;
        Serial.printf(" %i \n", modeCount);
        if(modeCount == 3){
          modeCount = 0;
          
        }
      } 
    }
  lastState1 = currentState;
  return modeCount;
}
// CHECK SOIL MOISTURE LEVEL & SEND WATER IF NEEDED
int moistureMonitor(int moistPin, int rPin){
  int moistVal = analogRead(moistPin);
  if (moistVal > WaterValue && moistVal < (WaterValue + intervals)){
    Serial.println("Very Wet");
    relayOff(rPin, Off);
  }
  else if (moistVal > (WaterValue + intervals) && moistVal < (AirValue - intervals)){
    Serial.println("Wet");
    relayOff(rPin, Off);
  }
  else if (moistVal < AirValue && moistVal > (AirValue - intervals)){
    Serial.println("Dry");
    relayOn(rPin, On);
  }
  return moistVal;
}
// RELAY TIMER FUNCTION
void relayTimer(int timerInterval){
  unsigned long currentRelaytimer = millis();
  if ((currentRelaytimer - lastRelaytimer) >= timerInterval){
    if(relayState2 == HIGH){
      relayState2 = LOW;
      relayOn(RELAYPIN1, relayState2);
      relayOn(RELAYPIN2, relayState2);
      relayOn(RELAYPIN3, relayState2);
      relayOn(RELAYPIN4, relayState2);
    }
    else{
      relayState2 = HIGH;
      relayOff(RELAYPIN1,relayState2);
      relayOff(RELAYPIN2,relayState2);
      relayOff(RELAYPIN3,relayState2);
      relayOff(RELAYPIN4,relayState2);
    }
     lastRelaytimer = millis();
  }
}
// RELAY ON/OFF FUNCTIONS
void relayOn(int rpin, int state){
  digitalWrite(rpin, state);
  // Serial.printf("ON  \n" );
}
void relayOff(int rpin, int state){
  digitalWrite(rpin, state);
  // Serial.printf("OFF \n" );
}
//On/Off toggle
void zoneToggle(int bpin, int rpin){
  int buttonState1 = digitalRead(bpin);
   if(buttonState1 == LOW && lastState1 == HIGH){
     if (relayState1 == HIGH){
      relayState1 = LOW;
      relayOn(rpin, relayState1);
      Serial.printf("RELAY ON \n");
     }
    else{
      relayState1 = HIGH;
      relayOff(rpin, relayState1);
      Serial.printf("RELAY OFF \n");
       }
     }
     lastState1 = buttonState1;
   }
//Mode environments
   void modes(){
     switch(modeCount){
       case 1:
        moistureMonitor(moisturePin1, RELAYPIN1);
        moistureMonitor(moisturePin2, RELAYPIN2);
        moistureMonitor(moisturePin3, RELAYPIN3);
        moistureMonitor(moisturePin4, RELAYPIN4);
       break;
       case 2:
        relayTimer(10000);
       break;
       default:
       relayOff(RELAYPIN1, Off);
       relayOff(RELAYPIN2, Off);
       relayOff(RELAYPIN3, Off);
       relayOff(RELAYPIN4, Off);
       
     }
   }

Credits

user2152977

user2152977

1 project • 1 follower
Brian Rashap

Brian Rashap

3 projects • 46 followers
Former General Manager of US Facilities Operations at Intel Corporation. Currently loving my encore career as a teacher focused on IoT.
Jessica Rodriquez

Jessica Rodriquez

4 projects • 7 followers

Comments

Add projectSign up / Login