Jerem’y Socially Interactive House Plant

Hi Everyone:

Here is a picture of my socially interactive house plant. The idea was to have a plant that needed talking to. The light colours
would change either due to room lighting or someone speaking to the plant. Also, there would be a Processing app that would
visually indicate the “happiness” of the plant (that’s a work in progress!). Basically, a stress reliever for the office cubicle!!!!

It worked pretty well except the microphone control was very unpredictable (ok, barely worked!).  I’m going to figure out why!
When  I do I will add a follow-up post.

Postscript:

I got the microphone to work! New video posted and I have updated the code.

 

Here is the video:

 

Here is the Second Video with the Audio Sensor (Mic) Working and the code cleaned up!

 

Here are the schematics (Made with Fritzing!!!!): 

Here is the layout in a manner (schematic) I find much more difficult that the visual design below!

 

 

 


 

 

 

 

 

 

 

 

 

 

 

 

 

 

‘ *******************************************************

Here is the code:

‘**********************************************************

/ Jeremy Littler
// “Hello Mr (or Mrs) Plant
// As I said that 10000000 Times!
// Interact with your Unpredicatble Plant.
// All Code is Free for Anyone to Use
//  October 2012

//       .;:;:.
//       ::;:;:
//     _ ‘;:;;’
//     >’. ||  _
//     `> \||.'<
//      `>|/ <`
//        `||/`
//  ^jgs^^^^^^^^^^^

//
// TO HARD RESET CONNECT ONE BUTTON POIN
// TO Reset and the other to ground

// Keep Track of where it should be R G or B
int showlightbank = 0; // determines which light bank get displayed

int hasbooted = 0; // do startup sequence;
int plantisawaken = 0; // make sure you can only wake the plan once
int istalkingtoplant =0; // someone is talking to the plant;

// Source: Arduino Cookbook – Detecting Light – Page 186
const int lightsendor = A5;
int ambientlightlevel= 100;

// Source: Arduino Cookbook – Page 198
const int pinMic = A0; //analog input connected to mic AUD

const int ledPin13 = 13; //digital output connected to LED 0
const int middleValue = 512; //The middle range of analog values
const int numberOfSamples=128; //number og readings  tasken

int sample; //value read from mic
long signal; //reading post DC offset removal
long averageReading; // the average of that loop of readings

long runningAverage = 0; //running average of calculated values
const int averagedOver=16; // how quickly new values affect the runniong average
const int threshold=19000; // The level the light (motor turns on)

void setup() {

Serial.begin(19200);

// For the Plant Lights
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(8, OUTPUT);

}

void loop()
{

// Check for Startup Sequence
if (hasbooted ==0) {
hasbooted = 1;
digitalWrite(8, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
delay(2000);
digitalWrite(8, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
delay(2000);
digitalWrite(8, HIGH);
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
delay(2000);
digitalWrite(8, LOW);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);

}

// ***************
// Ambient Light
// **************

// Checks the Light Sensor value
ambientlightlevel = analogRead(lightsendor);
// Serial.println(ambientlightlevel);
//delay(200);
// Serial.println(ambientlightlevel);

// If the ambinet light level drops below 50. Then it is getting dark
// Dont wake up as the light must be on
if (istalkingtoplant == 0) {
if (ambientlightlevel <= 70)  {
// Red A Night
// Sailors Delight
digitalWrite(8, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
}

if  (ambientlightlevel >= 71 && ambientlightlevel <= 125) {
// Blue A Night
// in Mid Light
digitalWrite(8, HIGH);
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
}

if  (ambientlightlevel > 125)  {
// Green when its hot
digitalWrite(8, LOW);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
}
}

// Touching or Talking. This thing is VERY unpredictable.
// Source: Arduino Cookbook – Page 198

// This code what not used (except sample = analogRead(pinMic);) as I found reading the
//pin mic sufficient. However, I have included it
//as this may work better for some microphones

long sumOfSquares = 0;
for (int i=0; i<numberOfSamples; i++) {
sample = analogRead(pinMic); //take a reading’
Serial.println(sample);
// Serial.println( sample);
signal = (sample-middleValue); // work out the offset
signal *= signal; //square the value
sumOfSquares += signal; // add to the total

}

// This code what not used (except sample = analogRead(pinMic);) as I found reading the
//pin mic sufficient. However, I have included it
//as this may work better for some microphones
// Calculates the Running Average
averageReading= sumOfSquares/numberOfSamples; // calculates running averge
runningAverage= (((averagedOver-1)*runningAverage)+averageReading)/averagedOver;

delay(150);

// Is the “level” from the mic sensor picking anything up. Movement, Sound.

if (sample >= 600) {
long runningAverage = 0;
istalkingtoplant = 1;
Serial.flush();

// if plantis
// Then put on a light show
for (int i=0; i <= 8; i++){
plantisawaken = 1;
Serial.println(“flicker”);

digitalWrite(8, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
delay(150);
digitalWrite(8, HIGH);
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
delay(150);
digitalWrite(8, LOW);
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
delay(150);
digitalWrite(8, HIGH);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
delay(150);
digitalWrite(8, LOW);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);

}
Serial.begin(19200);

} else {
istalkingtoplant = 0;

}

}

 

Comments are closed.