SAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD

Rain Detector With Sound Alert


Well, I can't be bothered to explaining how it works and stuff, if you want to know the reason then please visit All Arduino posts page. If you are coming from YouTube then you probably have already seen the video where I've explained everything. So here is the Sketch for that video.

For people who wants to know what video is then I would like to say read the reason carefully then you will find out why I'm so frustrated about helping people.



#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

void setup()
{
      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 loop() {

delay(500); // gets the readings after 1 second

// read the input on analog pin 0:
int sensorValue = analogRead(A0);
Serial.println(sensorValue);

  if (sensorValue <=1010){
    Serial.println(sensorValue);
 sendCommand(CMD_PLAY_W_VOL, 0X1E01); //play the sound track
  }
  else {
    Serial.println(sensorValue);
  }
 
}

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]) ;
  }
}

Ad


No comments:

Post a Comment



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