构建一个基于Arduino的自动宠物喂食器

今天,我们正在构建一个基于arduino的自动宠物喂食器,它可以及时自动为您的宠物提供食物。它有一个ds3231 rtc(实时时钟)模块,用于设置宠物应进食的时间和日期。因此,通过根据宠物的进食时间表设置时间,设备会自动掉落或装满食物碗。
在本电路中,我们使用16*2 lcd通过ds3231 rtc模块和arduino uno显示时间。此外,伺服电机用于旋转容器以提供食物,4 * 4矩阵键盘用于手动设置喂食宠物的时间。您可以根据要提供给宠物的食物数量设置旋转角度和容器打开持续时间。食物的数量也可能取决于您的宠物,无论是狗、猫还是鸟。
所需材料
arduino uno
4*4矩阵键盘
16 * 2液晶显示器
按钮
伺服电机
电阻器
连接线
面包板
电路图
在这个基于arduino的cat喂食器中,为了获取时间和日期,我们使用了rtc(实时时钟)模块。我们使用 4*4 矩阵键盘在 16x2 lcd 的帮助下手动设置宠物的进食时间。伺服电机旋转容器并在用户设置的时间内放下食物。液晶屏用于显示日期和时间。完整的工作可以在最后给出的视频中找到。
3d打印宠物喂食器模型
我们使用3d打印机设计了这款arduino宠物喂食器容器。用于打印此模型的材料是 pla。它有四个部分,如下图所示:
组装四个部件并连接伺服电机,如下图所示:
ds3231 rtc 模块
ds3231是rtc(实时时钟)模块。它用于维护大多数电子项目的日期和时间。该模块有自己的纽扣电池电源,即使主电源被移除或mcu经过硬复位,它也能保持日期和时间。因此,一旦我们在此模块中设置了日期和时间,它将始终跟踪它。在我们的电路中,我们使用ds3231根据宠物主人设置的时间喂宠物,就像闹钟一样。当时钟达到设定时间时,它操作伺服电机打开容器门,食物掉入宠物的食物碗中。
注意:首次使用此模块时,您必须设置日期和时间。
在下面的代码中,我们定义了库,rtc模块的“#include ”,伺服电机的“#include ”,16 * 2 lcd的“#include ”和4 * 4矩阵键盘的“#include ”。
#include
#include
#include
#include
在下面的代码中,我们为 4*4 矩阵键盘定义键盘映射,并为键盘的行和列分配 arduino 引脚。
char keys[rows][cols] = {
{'1','2','3','a'},
{'4','5','6','b'},
{'7','8','9','c'},
{'*','0','#','d'}
};
byte rowpins[rows] = { 2, 3, 4, 5 };
byte colpins[cols] = { 6, 7, 8, 9 };
在这里,我们将使用代码中的以下命令创建键盘。
keypad kpd = keypad( makekeymap(keys), rowpins, colpins, rows, cols );
分配 a4 和 a5 arduino 引脚以连接 ds3231 的 scl 和 sda 引脚。此外,将引脚分配给 lcd 并初始化伺服电机。
ds3231 rtc(a4, a5);
servo servo_test; //initialize a servo object for the connected servo 
liquidcrystal lcd(a0, a1, a2, 11, 12, 13); // creates an lc object. parameters: (rs, enable, d4, d5, d6, d7)
在下面的代码中,我们将 t1 声明为 t6、键和数组 r[6],以及馈送。
int t1, t2, t3, t4, t5, t6;
boolean feed = true;
char key;
int r[6];
在下面的代码中,我们正在为启动设置所有组件。就像在这个代码“servo_test.attach(10);”伺服器附在 10千arduino的销钉。定义 a0、a1 和 a2 作为输出引脚并初始化 lcd 和 rtc 模块。
void setup()
{
servo_test.attach(10); // attach the signal pin of servo to pin9 of arduino
rtc.begin();
lcd.begin(16,2);
servo_test.write(55);
serial.begin(9600);
pinmode(a0, output);
pinmode(a1, output);
pinmode(a2, output);
}
现在,循环如何工作是要理解的重要部分。每当按下按钮时,它都会变高表示 1,可以通过“按钮按下 = 数字读取(a3)”来读取。现在它进入“if”语句并调用“setfeedingtime”函数。然后,它将实时时间和用户输入的时间进行比较。如果条件为真,这意味着实时时间和输入的时间相同,则伺服电机旋转至 100 度并倾斜 0.4 秒后返回其初始位置。
void loop() {
lcd.setcursor(0,0);
int buttonpress;
buttonpress = digitalread(a3);
if (buttonpress==1)
setfeedingtime();
lcd.print(time: );
string t = ;
t = rtc.gettimestr();
t1 = t.charat(0)-48;
t2 = t.charat(1)-48;
t3 = t.charat(3)-48;
t4 = t.charat(4)-48;
t5 = t.charat(6)-48;
t6 = t.charat(7)-48;
lcd.print(rtc.gettimestr());
lcd.setcursor(0,1);
lcd.print(date: );
lcd.print(rtc.getdatestr());
if (t1==r[0] && t2==r[1] && t3==r[2] && t4==r[3]&& t5<1 && t6<3 && feed==true)
{
servo_test.write(100); //command to rotate the servo to the specified angle
delay(400); 
servo_test.write(55);
feed=false;
}

在 void setfeedingtime() 函数代码中,按下按钮后,我们可以输入宠物喂食时间,然后我们必须按“d”以节省该时间。当保存的时间与实时匹配时,伺服开始旋转。
void setfeedingtime()
{
feed = true;
int i=0;
lcd.clear();
lcd.setcursor(0,0);
lcd.print(set feeding time);
lcd.clear();
lcd.print(hh:mm);
lcd.setcursor(0,1);
while(1){
key = kpd.getkey();
char j;
if(key!=no_key){
lcd.setcursor(j,1);
lcd.print(key);
r[i] = key-48;
i++;
j++;
if (j==2)
{
lcd.print(:); j++;
}
delay(500);
}
if (key == 'd')
{key=0; break; }
}
}
自动宠物喂食器的工作原理
将代码上传到arduino uno后,时间和日期将显示在16 * 2 lcd上。当您按下按钮时,它会询问宠物的喂食时间,您必须使用 4*4 矩阵键盘输入时间。显示屏将显示输入的时间,当您按“d”时,它会节省时间。当实时时间和输入时间匹配时,它将伺服电机从其初始位置旋转 55⁰ 到 100⁰,并在延迟后再次返回到其初始位置。因此,伺服电机连接到食品容器门,因此当它移动时,门将打开,一些食物落入碗或盘子中。延迟0.4秒后,伺服电机再次旋转并关闭闸门。整个过程在几秒钟内完成。这就是您的宠物在您输入时自动获得食物的方式。
#include
#include
#include
#include
const byte rows = 4; // four rows
const byte cols = 4; // three columns
// define the keymap
char keys[rows][cols] = {
{'1','2','3','a'},
{'4','5','6','b'},
{'7','8','9','c'},
{'*','0','#','d'}
};
// connect keypad row0, row1, row2 and row3 to these arduino pins.
byte rowpins[rows] = { 2, 3, 4, 5 };
// connect keypad col0, col1 and col2 to these arduino pins.
byte colpins[cols] = { 6, 7, 8, 9 };
// create the keypad
keypad kpd = keypad( makekeymap(keys), rowpins, colpins, rows, cols );
ds3231 rtc(a4, a5);
servo servo_test; //initialize a servo object for the connected servo
liquidcrystal lcd(a0, a1, a2, 11, 12, 13); // creates an lc object. parameters: (rs, enable, d4, d5, d6, d7)
//int angle = 0;
// int potentio = a0; // initialize the a0analog pin for potentiometer
int t1, t2, t3, t4, t5, t6;
boolean feed = true; // condition for alarm
char key;
int r[6];
void setup()
{
servo_test.attach(10); // attach the signal pin of servo to pin9 of arduino
rtc.begin();
lcd.begin(16,2);
servo_test.write(55);
serial.begin(9600);
pinmode(a0, output);
pinmode(a1, output);
pinmode(a2, output);
}
void loop()
{
lcd.setcursor(0,0);
int buttonpress;
buttonpress = digitalread(a3);
if (buttonpress==1)
setfeedingtime();
//serial.println(buttonpress);
lcd.print(time: );
string t = ;
t = rtc.gettimestr();
t1 = t.charat(0)-48;
t2 = t.charat(1)-48;
t3 = t.charat(3)-48;
t4 = t.charat(4)-48;
t5 = t.charat(6)-48;
t6 = t.charat(7)-48;
lcd.print(rtc.gettimestr());
lcd.setcursor(0,1);
lcd.print(date: );
lcd.print(rtc.getdatestr());
if (t1==r[0] && t2==r[1] && t3==r[2] && t4==r[3]&& t5<1 && t6<3 && feed==true)
{
servo_test.write(100); //command to rotate the servo to the specified angle
delay(400);
servo_test.write(55);
feed=false;
}
}
void setfeedingtime()
{
feed = true;
int i=0;
lcd.clear();
lcd.setcursor(0,0);
lcd.print(set feeding time);
lcd.clear();
lcd.print(hh:mm);
lcd.setcursor(0,1);
while(1){
key = kpd.getkey();
char j;
if(key!=no_key){
lcd.setcursor(j,1);
lcd.print(key);
r[i] = key-48;
i++;
j++;
if (j==2)
{
lcd.print(:); j++;
}
delay(500);
}
if (key == 'd')
{key=0; break; }
}
}

BAAS精讲(上篇):一切从失败的B2B电商模式说起
暖通空调物联网解决方案如何帮助OEM节省大量成本
【技术专栏】泰凌微电子产测工具使用——常见问题解决方法(二)
东芝笔记本电脑黑屏怎么办_东芝笔记本电脑开不了机怎么办
电流表的好坏如何判断
构建一个基于Arduino的自动宠物喂食器
物联网时代哪三种职业最吃香?
骁龙835、麒麟960、苹果A10!到底谁才是强者!
7月手机镜头出货量同比增长69.2% 舜宇光学今早股票跌4.19%
回车电子:融合脑机接口与虚拟现实,数字医疗新机遇
优秀的IC/FPGA开源项目(二)-NetFPGA
复兴伟业推动单相电机控制器走向新时代
今日直播|秋天已来,火力全开,看启明云端如何用极具性价比方案让彩屏化86盒“出圈”
一名工程师在MySQL工作的那五年
2011年半导体创新产品和技术评选结果
三星型号SM-F7000设备获3C认证,配备15W快充技术
为下一代家电供电:如何积少成多
京东新的一轮地区销量榜已经出来,小米有三部上榜,还有谁?
国内首创超低功耗存算一体人工智能芯片在合肥问世
锂电材料研究常用综合表征技术汇总!