SAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD

Plant asks for water when it needs and somebody around it




In this post I'm going to share a sketch which can make a plan talk (ask for water) if anyone goes next to it. Let me tell you how it works. First it takes the readings from soil moisture sensor. And when it detects that the plant need some water, it turns on the motion sensor and then if anyone goes front of the motion sensor it (motion sensor) triggers the Mp3 player to play the sound.

You might be thinking what's the point making this with motion sensor?
Well even though you can make it without motion sensor, but that will keep playing the sound again and again. And on the other hand if you add the motion sensor it will only play the sound when someone around it and that seems kind of real interaction to me.

The sketch

#include <SoftwareSerial.h>
#define ARDUINO_RX 5 //should connect to TX of the Serial MP3 Player module
#define ARDUINO_TX 6 //connect to RX of the module
SoftwareSerial mySerial(ARDUINO_RX, ARDUINO_TX);
static int8_t Send_buf[8] = {0} ;

#define CMD_SEL_DEV 0X09
#define DEV_TF 0X02
#define CMD_PLAY_W_VOL 0X22
int led = 7; // pin for led
int sensor = 2; // pin for motion sensor


void setup()
{
  pinMode(sensor, INPUT);    // initialize sensor as an input
  pinMode(led, OUTPUT);
      mySerial.begin(9600);
        Serial.begin(9600);
      delay(500);//Wait chip initialization is complete
        sendCommand(CMD_SEL_DEV, DEV_TF);//select the TF card 
      delay(200);//wait for 200ms
}


void motionsensor(){ // This function is for motion sensor.

  if (digitalRead(sensor)){  
  sendCommand(CMD_PLAY_W_VOL, 0X1E001); //play the sound track
  delay(5000); // length of the sound track
    } 
}


void loop() {

delay(1000); // gets the readings after 1 second
 int sensorValue = analogRead(A1); //analogue pin 1 for soil moisture sensor

  if (sensorValue >=500){
    Serial.println(sensorValue);
    digitalWrite(led, HIGH);
    motionsensor();
  }
  else {
    Serial.println(sensorValue);
    digitalWrite(led, LOW);
  }
  
}

void sendCommand(int8_t command, int16_t dat)
{
  delay(20);
  Send_buf[0] = 0x7e;
  Send_buf[1] = 0xff;
  Send_buf[2] = 0x06;
  Send_buf[3] = command;
  Send_buf[4] = 0x00;//0x00 = no feedback, 0x01 = feedback
  Send_buf[5] = (int8_t)(dat >> 8);//datah
  Send_buf[6] = (int8_t)(dat); //datal
  Send_buf[7] = 0xef; //ending byte
  for(uint8_t i=0; i<8; i++)//
  {
    mySerial.write(Send_buf[i]) ;
  }
}

What do you need?
1x Motion sensor
1x Soil moisture sensor
1x Serial mp3 player
1x Micro SD card where you will save the sound track, make sure you name it 001.
1x Arduino board
1x led (this led will give visual indication that the plant needs water.)
1x Resistor (to make the led less bright)
few wires that's all.



No comments:

Post a Comment



Newly posted:
Reason why rich getting richer and poor getting poorer