Jos Malig-onStephen MarconKevin Lata
Published

Plant Gang

Our names are Kevin Lata, Stephen Marcon, and Jos Malig-on. We are freshmen from Rice University and this is our ELEC 220 Spring Project.

BeginnerFull instructions provided805
Plant Gang

Things used in this project

Hardware components

EK-TM4C123GXL TM4C Tiva LaunchPad
Texas Instruments EK-TM4C123GXL TM4C Tiva LaunchPad
×1
Grove Starter Kit for LaunchPad
Seeed Studio Grove Starter Kit for LaunchPad
Specifically uses the following: o Piezo Buzzer o Light Sensor o Moisture Sensor o Grove Base BoosterPack o Three Wires that connect the BoosterPack to the modules
×1
Seeed Studio Sidekick Basic Kit for TI LaunchPad
Specifically uses the following: o The breadboard o 4 LED lights (3 red and 1 green) o 4 10kΩ resistors o 6 Breadboard Jumper Wires as (any length)
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
We just need a standard USB cable you'd use to connect an Android to your computer. We think its this type.
×1

Software apps and online services

Energia
Texas Instruments Energia

Hand tools and fabrication machines

A Potted Plant With Soil

Story

Read more

Schematics

Schematic/Block Diagram For Plant Gang

This schematic roughly shows the connections between our breadboard and Launchpad, although there exists no parts for the Grove light sensor, Grove moisture sensor, Grove piezo module, or the launchpad itself in Fritzing, so we kind of substituted similar parts. As a consequence, the pin numbers on the microcontroller are inaccurate when compared to the code we are using. Therefore it is unwise to use this schematic when building Plant Gang.

Code

Code for Controlling Alarm and Water Monitoring System Appropriately

C/C++
We use Energia to run the following code, with a USB between the laptop Energia is running on and the LaunchPad
// written by Kevin Lata, Stephen Marcon, and Jos Malig-on
 
int analog_value = 0; // value which we'll use to check the moisture levels
int analog_light = 0; // value which we'll use to check the light levels
 
#define MOISTURE_PIN        24          /* pin of Moisture Sensor */
#define BUZZER_PIN          39          /* pin of Piezzo Buzzer   */
#define LIGHT_SENSOR        23          /* pin connected to the Light Sensor */
#define LED1                9           /* pin of first (bottom) LED   */
#define LED2                8           /* pin of next (second) LED   */
#define LED3                7           /* pin of third LED   */
#define GREEN               6           /* pin of the top/green LED   */
 
char notes[] = "cgfgbf "; // notes in the song
int beats[] = { 1, 1, 1, 1, 1, 2, 4}; //length of each note
int tempo = 240;  // value which speeds up or slows down the rate at which the song is played
int length = 10;
 
void setup() {
  // The following setup is for the serial monitor as well as to permit the pins for the LEDs
  // and the buzzer to be output instead of input
  Serial.begin(9600);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(GREEN, OUTPUT);
}
 
void loop() {
  // These two lines allow us to assign the values read from those pins to their corresponding variable names
  analog_value = analogRead(MOISTURE_PIN);
  analog_light = analogRead(LIGHT_SENSOR);
  // The following few lines just help us monitor the value assigned to the variables above on the serial monitor
  Serial.print("Moisture Level: ");
  Serial.println(analog_value);
  Serial.print("Light Level: ");
  Serial.println(analog_light);
  Serial.println("");
  delay(1000);
  // The following if statement initiates the logic regarding setting off the piezzo buzzer only if the
  // readings of the moisture sensor are low enough and the readings from the light sensor are high enough
  if (analog_value < 400 && analog_light > 1000) {
    // While the reading of the moisture is too low, we want the loop to stay in the leogic that permits the
    // piezo buzzer to sound
    while(analog_value < 400) {
      // This is in the case that the buzzer is ringing (so the moisture was low when it was daytime) but it then
      // turns to night time, so it consistently checks the light levels in here too so if it gets dark, the loop
      // gets stuck in here. If it becomes light again, it breaks out of this loop.
      while(analog_light < 1000) {
        analog_light = analogRead(LIGHT_SENSOR);
        analog_value = analogRead(MOISTURE_PIN);
        if (analog_value > 35){
          break;
        }
      }
      // Here its checking the levels again and if it detects that the moisture level rose, it breaks from the
      // previous "checking" loops. If this doesn't happen, then it advances to the logic that makes the buzzer go off.
      analog_value = analogRead(MOISTURE_PIN);
      analog_light = analogRead(LIGHT_SENSOR);
      if (analog_value > 400){
        break;
      }
      // The following plays the preprogrammed piezo buzzer "song"
      for(int i = 0; i < length; i++)
  {
    //space indicates a pause
    if(notes[i] == ' ')
    {
      analog_value = analogRead(MOISTURE_PIN);
      delay(beats[i] * tempo);
    }
    else
    {
      analog_value = analogRead(MOISTURE_PIN);
      playNote(notes[i], beats[i] * tempo);
    }
    delay(tempo / 2);    /* delay between notes */
  }
    }
    // At this point, an increase in moisture was detected so until the plant is fully watered, the following is executed.
    analog_value = analogRead(MOISTURE_PIN);
    while(analog_value < 1900) {
      analog_value = analogRead(MOISTURE_PIN);
      // This just allows the looping to exit in case for some reason the plant isn't fully watered but the owner stops watering it.
      // Eventually the moisture will go down and the loop starts again from the begining.
      if(analog_value < 400) {
        break;
      }
      // Lights up the first LED if a certain moisture is reached
      if(analog_value > 720) {
        digitalWrite(LED1, HIGH);
      }
      // Lights up the second LED if a certain moisture is reached
      if(analog_value > 1200) {
        digitalWrite(LED2, HIGH);
      }
      // Lights up the third LED if a certain moisture is reached
      if(analog_value > 1500) {
        digitalWrite(LED3, HIGH);
      }
      analog_value = analogRead(MOISTURE_PIN);
    }
    // Once the loop breaks out of the last while statement, the user will have presumably watered the plant above the required
    // amount, so the last light will light up letting the user know that they are done, and in a second all the LEDs will turn
    // back off. Once this is done the loop will begin again, monitoring the plant's readings.
    digitalWrite(GREEN, HIGH);
    delay(3000);
    digitalWrite(LED1, LOW); digitalWrite(LED2, LOW); digitalWrite(LED3, LOW); digitalWrite(GREEN, LOW);
  }
}
// This function allows the buzzer to play the different tones
void playTone(int tone, int duration)
{
  for (long i = 0; i < duration * 1000L; i += tone * 2)
  {
    digitalWrite(BUZZER_PIN, HIGH);
    delayMicroseconds(tone);
    digitalWrite(BUZZER_PIN, LOW);
    delayMicroseconds(tone);
  }
}
// The following two lines establishes the letter associations of each tone and their numerical values for the piezo buzzer,
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1074, 956 };
// This function helps the buzzer play the desired note for the desired duration
void playNote(char note, int duration)
{
  // play the tone corresponding to the note name
  for (int i = 0; i < 8; i++)
  {
    if (names[i] == note)
    {
      playTone(tones[i], duration);
    }
  }
}

Credits

Jos Malig-on
1 project • 0 followers
Stephen Marcon
1 project • 0 followers
Kevin Lata
2 projects • 0 followers

Comments