The Eager Succulents – Final Project

on

I titled my final project “The Eager Succulents” and its objective is to animate something that is not capable of speaking to crave human attention. The ultrasonic sensor picks up how close the person is making the lights within the plant light up and the sound picks up voice so the plants could “talk” back.

Though I had a few setbacks and issues I was able to have proof of concept within the Serial Monitor in place of the LCD for the plant text. It would say nice things such as “WE love hearing your voice” or “We feel prickly” or “You make us feel less lonely.”

Final Code:

#define trigPin 12
#define echoPin 13 // sensor input
#define led 11
#define led2 10
const int upPin = 8; // transistor – output

// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button
#include <LiquidCrystal.h>

LiquidCrystal lcd(9, 7, 5, 4, 3, 2) ;

int sensorPin = A0;  //microphone sensor

int volume = 0;  // variable to store the volume level value coming from the sensor
int volume2 = 0;  // variable to store the volume level value coming from the sensor – mapped to a range of 0-255
int delayTime = 100;
int reply;

void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);  // sensor input
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(8, OUTPUT);  // transistor – output
 // void setup() {
  lcd.begin (16, 2);
  pinMode (sensorPin, INPUT);
  lcd.print (“Hello there!”);
  lcd.setCursor(0,1);
 //  Serial.begin(9600);
 // }
}

void loop() {

 soundSensor();
 ultrasonic();

  }
 
void ultrasonic() {
  digitalWrite(upPin, LOW); // transistor – output
  long duration, distance;
  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
//  delayMicroseconds(1000); – Removed this line
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
 Serial.print(“distance:  “);
 Serial.println(distance);

  if (distance < 150 ) {  // This is where the LED On/Off happens
    if (buttonState == LOW) {
    digitalWrite(led,HIGH); // When the Red condition (ON) is met, the Green LED should turn off
    Serial.println(“ON”);
    digitalWrite(led2,LOW);
   digitalWrite(upPin, HIGH);
  delay(100);
  digitalWrite(upPin, LOW);
  buttonState = HIGH;
    }
   delay(200);
}
  else {
    if (buttonState == HIGH) {
     buttonState = LOW;
     Serial.println(“OFF”);
    digitalWrite(led,LOW);
    digitalWrite(led2,HIGH);
    digitalWrite(upPin, HIGH);
  delay(100);
  digitalWrite(upPin, LOW);
   }
   delay(100);
  }
}
 
void soundSensor() {
  volume = analogRead(sensorPin);
 //  Serial.print(“Volume:  “);
 // Serial.println(volume);
   if (volume < 800) {  // more sensative the higher the number ie,  800 + 390
    volume=abs(volume-410);
     volume2 = map(volume, 0, 390, 0, 1000); // if you need to subtract 760 (as suggested above), change the initial range to 0, 263 instead of 0, 1023
     Serial.print(“volume:  “);
     Serial.println(volume2);
     Serial.print(“volume:  “);
     delay(delayTime);
   
       if (volume2 < 820) {
      reply = random(5);
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print (“Guess What?”);
      lcd.setCursor(0,1);
      switch(reply){
        case 0:
        Serial.print(“We love you:  “);
        lcd. print (“We love you”);
        break;
       
        case 1:
        Serial.print(“We’re Hungry:  “);
        lcd.print (“We’re hungry”);
        break;
       
        case 2:
        Serial.print(“We love hearing your voice:  “);
        lcd.print (“We love hearing your voice”);
        break;
       
        case 3:
        Serial.print(“You look nice!:  “);
        lcd.print (“You look nice!”);
        break;
       
        case 4:
        Serial.print(“We feel prickly:  “);
        lcd.print (“We feel prickly”);
        break;
       
        case 5:
        Serial.print(“You make us feel less lonely: “);
        lcd.print (“You make us feel less lonely”);
        break;
      }
        }
   }
}