Train your pets with custom commands


This is why I love Arduino so much, it opens so many ways of innovations. Recently I saw a video where someone was giving her/his cats food when they were ringing the bell. So after watching that video I thought why not make multiple button with different commands so that it can express the exact thing that it wants.
Ad

For example: You make  one button for food, one for water and one for go to toilet. Or maybe make 5/10 different buttons for different food, so if the cat doesn't like one kind of food it will ask for different one and that's how you might even find out his best food.

Some people might say well you can make a cat feeder so what's the point making buttons?
That's right and even I can make the cat feeder as well if I want to, but this is for those people who enjoy feeding their pets and by doing this you are giving the cats/dogs more choice of foods and stuff.

What do you need to make it work?
* 1× Arduino board.
* 1× Catalex Serial mp3 player with micro sd card.
* 3× Push button switches.
* 3× 10k ohm resistors.
* Some jumper wires.
* And finally the sketch, which you can find right below.

Note:
Remember you need to have three soundtracks in your SD card and rename it by 001, 002 and 003. if you don't know how to run a mp3 player with Arduino then please read this post first I have explained it in details.
Ad

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

const int buttonPin1 = 8;
int buttonState1 = 0;

const int buttonPin2 = 9;     // the number of the pushbutton pin
int buttonState2 = 0;         // variable for reading the pushbutton status

const int buttonPin3 = 10;
int buttonState3 = 0;

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

     pinMode(buttonPin1, INPUT);
     pinMode(buttonPin2, INPUT);
     pinMode(buttonPin3, INPUT);
}

void loop() {
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3); 

  if (buttonState1 == HIGH) {
sendCommand(CMD_PLAY_W_VOL, 0X1E01);//This doorbell is for friends and family.
  }
 
else if (buttonState2 == HIGH) {
sendCommand(CMD_PLAY_W_VOL, 0X1E02);//This doorbell is for post men.
  }

else if (buttonState3 == HIGH) {
sendCommand(CMD_PLAY_W_VOL, 0X1E03);//This doorbell for is normal people.
  } 
}

void sendCommand(int8_t command, int16_t dat)
{
  delay(20);
  Send_buf[0] = 0x7e; //starting byte
  Send_buf[1] = 0xff; //version
  Send_buf[2] = 0x06; //the number of bytes of the command without starting byte and ending byte
  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]) ;
  }
}

Circuit diagram
One quick note: Try not to connect the RX and TX wires before uploading the sketch, it might not work if you do so.
That's all for this post, hopefully it helps you. :)
Ad



1 comment:

  1. Creative idea! The video of the cats asking for food is also very funny. :)

    ReplyDelete



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