element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Design For A Cause 2021
  • Challenges & Projects
  • Design Challenges
  • Design For A Cause 2021
  • More
  • Cancel
Design For A Cause 2021
Blog Garden Controller, 1 week of operation update
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: tbriceno
  • Date Created: 4 Jun 2021 1:58 PM Date Created
  • Views 830 views
  • Likes 3 likes
  • Comments 0 comments
Related
Recommended

Garden Controller, 1 week of operation update

tbriceno
tbriceno
4 Jun 2021

This video shows the plants at 3 different times of a 5 day period. Based on the first three days, a change was made to the code and hardware because the soil dried out and the plants started to wilt. The very next day the plants had bounced back. After a full week, not shown in video, the plants have actually grown and are thriving in the environment. There is still room for improvement, but the concept has been proven. There is still a long way to go to reach my initial goal and I will continue to work on the project and update it throughout the summer.

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

// Program: element14 Design for a Cause 2021 garden controller
// Programmer: Tony Briceño - Mitchell Community College
// Date: April 25th, 2019
// This project code is in the public domain.


#include <math.h>
#include <ArduinoBLE.h>
int SoilRead = A0;
int TempRead = A1;
int H2ORead = 4;
int PumpSwitch = 2;
static unsigned long soil = 0;
static unsigned long tempDegree = 0;
float temp = 0;
bool h2o = 0;
bool pumpStatus = false;
String message;


BLEService stringService("1f14be9c-bdbc-11eb-8529-0242ac130003"); // BLE String Service
BLECharacteristic soilValue("1f14bb72-bdbc-11eb-8529-0242ac130003", BLERead, 1023);
BLEFloatCharacteristic tempValue("1f14c202-bdbc-11eb-8529-0242ac130003", BLERead);
BLECharacteristic tempSettingDegree("1f14c3d8-bdbc-11eb-8529-0242ac130003", BLERead, 0);
BLECharacteristic h2oValue("1f14bfb4-bdbc-11eb-8529-0242ac130003", BLERead, "Low");
BLEByteCharacteristic pumpState("1f14c0f4-bdbc-11eb-8529-0242ac130003", BLERead | BLEWrite | BLENotify);


void setup() 
{
  pinMode(2, OUTPUT);
  pinMode(4, INPUT);
  pinMode(15, INPUT);
  pinMode(20, OUTPUT);
  
  // Include serial printing for debugging
  Serial.begin(9600);  
  Serial.println("Garden Controller v_1.0");
  Serial.println("***********************");


  // initialize the BLE hardware
   if (!BLE.begin()) {
      Serial.println("BLE initialation failed");
      Serial.println("***********************");
   }
   if (BLE.begin()) {
      BLE.setLocalName("Garden_controller");
      BLE.setAdvertisedService(stringService);
      Serial.println("BLE initialation complete");
      Serial.println(BLE.address());
      Serial.println("***********************");
   }
   
    // add the characteristic to the service
    stringService.addCharacteristic(soilValue);
    stringService.addCharacteristic(h2oValue);
    stringService.addCharacteristic(pumpState);
    stringService.addCharacteristic(tempValue);
    stringService.addCharacteristic(tempSettingDegree);    
    // add service
    BLE.addService(stringService);
  
   // Start advertising
   BLE.advertise();  


  // assign event handlers for connected, disconnected to peripheral
  BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler);
  BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);
  
}


void loop() {
  // poll for BLE events
  BLE.poll();


  while (BLE.connected()) 
  {
    // Make the first analog read
    soil = analogRead(SoilRead);
    delay(100);   //Include a slight delay to make sure ADC gets a full read
    h2o = digitalRead(H2ORead);
    delay(100);
    temp = analogRead(TempRead);
    delay(100);
    if(soil >600)
    {
      // Pump control
      digitalWrite(PumpSwitch, HIGH); //turn off pump
      pumpState.writeValue(0);
      pumpStatus = false;
    }
    else
    { 
      if(h2o == HIGH){
        digitalWrite(PumpSwitch,LOW ); //turn on pump
        pumpState.writeValue(1);
        pumpStatus = true;
        h2oValue.writeValue("OK");
      }
      else if(h2o == LOW){
        digitalWrite(PumpSwitch, HIGH); //turn off pump
        pumpState.writeValue(0);
        pumpStatus = false;
        h2oValue.writeValue("Low");
      }
    }
    if (tempSettingDegree.written())
    {
      if (tempSettingDegree.value())
      {
        tempDegree = 1;
      }
      else{
        tempDegree = 0;
      }
    }
    temp = tempcalc(temp, tempDegree);
    soilValue.writeValue(soil);
    tempValue.writeValue(temp);


    if (pumpState.written())
    {
      if (pumpState.value() == 1){
        Serial.println("ON");
      }
      else {
        Serial.println("OFF");
      }
      Serial.println("Received");
    }
  
  
    //Value check for debug
    Serial.println("^_^_^_^_^_^_^_^");
    Serial.print("soil - ");
    Serial.println(soil);
    Serial.print("h2o - ");
    Serial.println(h2o);
    Serial.print("pump - ");
    if(pumpStatus == true)
    {
      Serial.println("On");
    }
    else
    {
      Serial.println("Off");
    }
    Serial.print("temp - ");
    Serial.println(temp);


    delay(1000);    //Add a delay so the serial monitor is not too fast
  }
}


void blePeripheralConnectHandler(BLEDevice central) {
  // central connected event handler
  Serial.print("Connected event, central: ");
  Serial.println(central.address());
}


void blePeripheralDisconnectHandler(BLEDevice central) {
  // central disconnected event handler
  Serial.print("Disconnected event, central: ");
  Serial.println(central.address());
}


float tempcalc(float temp, long tempDegree){
  //Calculations to covert temperature from a voltage reading to a degrees F/C reading
  float calctemp = 0;
  calctemp = (3.279/1023); //volts per ADC digit
  calctemp = (calctemp * temp); //voltage of analog read
  calctemp = (calctemp - 0.6); //voltage offset for sensor range
  calctemp = (calctemp/0.01); //convert voltage to degrees C, 10mV per degree C
  if (tempDegree == 0)
  {
    return calctemp;
  }
  else
  {
    calctemp = ((calctemp*1.8)+32);
    return calctemp;
  }
}

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube