Google Assistant Powered Pet Feeder
by nisala in Circuits > Arduino
400 Views, 1 Favorites, 0 Comments
Google Assistant Powered Pet Feeder
This projects aims to make a petfeeder, that you can activate using voice commands from Google Assistant. In addition to activating the feeder immediately, you will also have the option to set it to activate at specific times, morning, afternoon and evening .
Supplies
- 1 x NodeMCU Esp8266 Development Board
- 1 x Piezo Buzzer
- 1 x Potentiometer
- Jumper Cables
- Computer
- Wireless access point
- 3D printed bottle connector (File Provided)
- 3D printed motor mount (File Provided)
Adafruit and IFTTT Setup
The first step will be setting up one component of the wireless section of the project. What this will do is allow the user to say a certain line, in this case, "Feed the pet", and have the trigger activated on the NodeMCU. There are two websites that we will use:
Adafruit
Your first step is to create an account, clicking the "Get started for free" button in the top right hand corner. Once that has been set up, click the "My Key" button. Your AIO key will connect your phone to the NodeMCU. Copy it for now, you'll be needing it later.
The last thing you'll need to is to create a new feed, available in the 'Feed' tab. Give it a name and description that fits it, I called it "Pet Feeder".
IFTTT
Applet 1:
IFTTT is service that allows you to do a 'If-This-Then-That' programs called applets. This is what's going to creating the google assistants commands, and will be sending the results to the Adafruit feed, and thus the NodeMCU.
Create an account again, but this time, use the same email as the one that you are logged in on your phone as.
Now, you can create an applet. As mentioned before, it's in a "If-This-Then-That" format. Since the trigger is if you are speaking into google assistant, for the 'If' block, choose Google Assistant.
In Google Assistant, choose, "Say a simple phrase". This will be the basic phrase that you say to activate the pet feeder. Fill in the field according to picture labelled "1".
Now, the "That block" will be Adafruit, as the data from here will be sent to the Adafruit feed, and thus the arduino. Log in, and select your Adafruit feed, putting in "On" in the 'Data to save section'.
Applet 2
The second applet will activate the pet feeder at a set time. Creating it will be mostly similar. The trigger, instead of being 'Say a simple phrase' will be 'Say a simple phrase with a text ingredient'. This will allow us to collect variable fields, which will be sent to the NodeMCU. In the 'If' portion, write "Feed My Pet Today $". The '$' will denote the time of day (Morning, Afternoon, Evening). What the assistants says will also be affected, with a 'in $' being added on the end of the statement.
This will also be reflected in the 'That' adafruit section. Under 'Data to Save', add the ingredient 'Text Field' . This will send the time of day that you said to the NodeMCU. Depending on what you said, it will set the feeder to activate at specific times.
Code
With the Google Assistant back-end done, the next step is to make sure that the Arduino is connected to the internet and thus, Adafruit. The first block connects the NodeMCU to the internet. Replace "SSID" with the SSID, or name, of the network you are aiming to connect to, for example, "NETGEAR10". "Password", will be that ne password. The second block connects the NodeMCU to your Adafruit feed. "Username", will be your account username, while "AIO Key" will be the key from your settings that you copied earlier. This blocks are labeled (1) and (2) respectably in the code.
#define WIFI_SSID "SSID" //(1) #define WIFI_PASS "Password"
#define MQTT_SERV "io.adafruit.com" //(2) #define MQTT_PORT 1883 #define MQTT_NAME "Username" #define MQTT_PASS "AIO Key"
Downloads
Buzzer
The buzzer is a nonessential part of the project, but nonetheless useful. When connected, it will emit a buzzing sound when the motor is activated. The potentiometer, is used to control the volume of this sound. As shown in the diagram, connect the buzzer and potentiometer to the NodeMCU. If you want to change the sound, look in the part of the code labelled '(3)', as shown below. This controls what specific note you want to play.
if (!strcmp((char*) onoff.lastread, "ON"))
{
int trimpos = analogRead(trimPin);
int f = map(trimpos, 0, 1023, 300, 1000); //(3)
tone(buzzerPin, f);
open_door();
delay(1000);
noTone(buzzerPin);
close_door();
}
Motor
The next step is connecting the motor. The connection will just require, connecting VIN (5V), GND and D1 (Pin) to the respective motor ports as shown in the diagram.
However, the motor is useless without the dispenser for the pet feeder. The 3D printed bottle dispenser will screw into the top threads of a soda bottle. in which the actual pet food would be stored. When rotated at a certain angle, food will be depnsed. Using the 'horns' provided with the motor, an example of which is shown, screw the motor into the holes on the dispenser side of the contraption, though in our build we simply hot glued them together.
Finshing Up
All that's left to do is mount your device in a place which best suits your needs. Using a 3D printed mount, files of which are provided, we screwed the motor into it, and positioned it angled on the outside of a shoe box, the NodeMCU device itself being tucked away inside. Make sure your dispenser is angled too to allow the pet food to easily fall out.
Now your done ! By voicing the commands from commands that you wrote ealier in Google Assistant, you can activate your pet feeder. However, there are ways of customizing the program, specifically, what time the motor can activate for the 'Morning, Afternoon and Evening' set times.
As an example, in the morning part of the code , (Marked by (4), there are two variables as shown:
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style="font-size: 11pt; font-family: Arial; color: rgb(0, 0, 0); font-variant-numeric: normal; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;"> if (!strcmp((char*) onoff.lastread, "Morning")) //(4)</p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"> {</p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"> feed_hour = 10;</p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"> feed_minute = 30; </p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"> }</p></span>
Feed_hour, will be the hour that you want it to activate, while feed_minute will be the minute. These variables are also declared for the 'Afternoon' and 'Evening' portions of the code just below the provided example, allowing you to customize these options too.
With that, you are free to enjoy the use of your pet feeder !