回到首页 返回首页
回到顶部 回到顶部
返回上一页 返回上一页

智能小屋 简单

头像 VDong 2019.07.22 1479 1

        也是心血来潮,刚接触了掌控板的一些简单操作,就想做一个作品出来。

        一开始做的规划很性感。我的作品名字叫《智能小屋》。

       作品的初衷是希望在摄影爱好者经常去的偏僻地方,能有这样一间小屋,可以存放设备,可以避雨,可以拍摄,比如银河呀、山水啦什么的。

       功能包括:1.智能路灯。当有人经过就会亮起。没有人就熄灭。

                  2.密码开锁。从网上获取密码,然后通过触摸数字密码登录。

                  3.室内有风扇,当温度超过29度自动运行。

                  4.有显示屏,可以看到当前的温度、湿度、天气情况。

       以上是我对作品的构想,但现实却及其不如意。 我学掌控用的是盛思的设备,通过mpythonx编程,我购买的设备是掌控板+df的扩展板,用mind+编程。一开始用python,可用的传感器和执行器极少,不得不改用c语言编程。 密码登录,本想着利用扩展板p、y、t、h、o、n的触摸功能,外接杜邦线,加上金属触摸按钮(图钉),实现密码输入。可试过多次,在掌控板上可以实现,接到扩展板就无法实现。于是只能用一个触摸传感器代替了。 单个程序运行的物联网是可以实现连接,但,将物联网程序加到源程序就完全无法运行。目前还没找到原因。

project-image

好吧,说了这么多,来看看能实现的功能吧。 1.智能路灯。有人经过即亮起。 2触摸按钮开门。接触触摸传感器驱动舵机开门。 3.室温超过29℃自动打开风扇。 4.显示当前温度、湿度,天气。

project-image

有路人经过灯会自动点亮。这里在屋檐下加了一个人体红外传感器,加了两个led灯,当感应到人体即点亮小灯。检测不到人体,灯灭。

project-image

手触摸按键可以打开门。在这里加了一个触摸传感器。屋里有一个舵机,控制门的开关。

project-image

当检测到触摸开关,舵机调整到0度,打开房门。等待10秒,舵机调整到90度,自动关门。

project-image

在屋内加了lm35温度、湿度传感器。在掌控板上显示当前的湿度和湿度。本想着最后一行显示今日天气,mqtt试验没成功。所以在这里只能显示“今天天气不错”代替了。

project-image

当屋内温度大于29度,就会驱动风扇电机转动。

project-image

材料清单

  • 掌控板 X1
  • 掌控板i/o扩展板 X1
  • lm35温度湿度传感器 X1
  • 风扇 X1
  • 人体红外感应传感器 X1
  • led灯 X2
  • 舵机 X1
代码
#include <MPython.h>
#include <DFRobot_DHT.h>
#include <DFRobot_Servo.h>

DFRobot_DHT dht11_P1(P1, DHT11);
Servo myservoP8;

const chCode chBuf[] = {
{0x5f53,0xe5bd93,0xB5B1,{0x00,0x00,0x01,0x00,0x21,0x08,0x19,0x30,0x09,0x20,0x01,0x00,0x7f,0xfc,0x00,0x0c,0x00,0x0c,0x3f,0xfc,0x00,0x0c,0x00,0x0c,0x7f,0xfc,0x00,0x0c,0x00,0x00,0x00,0x00}},
{0x524d,0xe5898d,0xC7B0,{0x08,0x20,0x04,0x60,0xff,0xfe,0x00,0x00,0x7f,0x6c,0x41,0x6c,0x7f,0x6c,0x41,0x6c,0x41,0x6c,0x7f,0x6c,0x41,0x0c,0x41,0x0c,0x4e,0x38,0x00,0x00,0x00,0x00,0x00,0x00}},
{0x6e29,0xe6b8a9,0xCEC2,{0x00,0x00,0x47,0xf8,0x24,0x08,0x17,0xf8,0x44,0x08,0x67,0xf8,0x24,0x08,0x00,0x00,0x27,0xfc,0x25,0x24,0x65,0x24,0x65,0x24,0x45,0x24,0x5f,0xfe,0x00,0x00,0x00,0x00}},
{0x5ea6,0xe5baa6,0xB6C8,{0x00,0x00,0x00,0x80,0x3f,0xfe,0x20,0x00,0x24,0x10,0x3f,0xfc,0x24,0x10,0x27,0xf0,0x20,0x00,0x2f,0xf8,0x66,0x10,0x41,0xc0,0x43,0x60,0x98,0x0c,0x00,0x00,0x00,0x00}},
{0xff1a,0xefbc9a,0xff1a,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x30,0x00,0x00,0x00,0x30,0x00,0x30,0x00,0x00,0x00,0x00,0x00}},
{0x6e7f,0xe6b9bf,0xCAAA,{0x00,0x00,0x47,0xfc,0x24,0x0c,0x17,0xfc,0x44,0x0c,0x67,0xfc,0x24,0x0c,0x01,0x20,0x29,0x24,0x25,0x24,0x65,0x2c,0x45,0x28,0x41,0x20,0x4f,0xfe,0x00,0x00,0x00,0x00}},
{0x4eca,0xe4bb8a,0xBDF1,{0x00,0x00,0x01,0x00,0x03,0x80,0x06,0xc0,0x0c,0x60,0x1a,0x30,0x61,0x08,0xc1,0x06,0x00,0x00,0x3f,0xf8,0x00,0x30,0x00,0x60,0x00,0xc0,0x00,0x80,0x00,0x00,0x00,0x00}},
{0x5929,0xe5a4a9,0xCCEC,{0x00,0x00,0x7f,0xfc,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xff,0xfe,0x03,0x00,0x02,0x80,0x06,0x80,0x04,0x40,0x18,0x20,0x30,0x18,0x40,0x04,0x00,0x00,0x00,0x00}},
{0x6c14,0xe6b094,0xC6F8,{0x00,0x00,0x10,0x00,0x10,0x00,0x3f,0xfc,0x20,0x00,0x7f,0xf8,0x40,0x00,0xbf,0xf0,0x00,0x10,0x00,0x10,0x00,0x12,0x00,0x12,0x00,0x0e,0x00,0x0c,0x00,0x00,0x00,0x00}},
{0x4e0d,0xe4b88d,0xB2BB,{0x00,0x00,0x7f,0xfc,0x01,0x80,0x01,0x00,0x03,0x00,0x07,0x00,0x05,0x40,0x09,0x20,0x19,0x18,0x31,0x0c,0x61,0x04,0x81,0x00,0x01,0x00,0x01,0x00,0x00,0x00,0x00,0x00}},
{0x9519,0xe99499,0xB4ED,{0x21,0x10,0x21,0x10,0x7b,0xfc,0x41,0x10,0x79,0x10,0xa7,0xfe,0x20,0x00,0xfb,0xfc,0x22,0x0c,0x23,0xfc,0x2a,0x0c,0x3b,0xfc,0x22,0x0c,0x00,0x00,0x00,0x00,0x00,0x00}},
{0xff01,0xefbc81,0xff01,{0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x00,0x00}},
};
void setup() {
	mPython.begin();
	display.setChCode(chBuf);
	myservoP8.attach(P8);
}

void loop() {
	display.setCursorXY(80, 0);
	display.print(dht11_P1.getTemperature());
	display.setCursorXY(80, 20);
	display.print(dht11_P1.getHumidity());
	display.setCursorXY(2, 0);
	display.print("当前温度:");
	display.setCursorXY(2, 20);
	display.print("当前湿度:");
	display.setCursorXY(2, 46);
	display.print("今天天气不错!");
	if ((dht11_P1.getTemperature() > 29)) {
		digitalWrite(P9, HIGH);
	}
	else {
		digitalWrite(P9, LOW);
	}
	if (((digitalRead(P14)) == 1)) {
		digitalWrite(P13, HIGH);
	}
	else {
		digitalWrite(P13, LOW);
	}
	if (((digitalRead(P15)) == 1)) {
		digitalWrite(P13, HIGH);
		myservoP8.angle(abs(0));
		delay(10000);
		digitalWrite(P13, LOW);
	}
	else {
		myservoP8.angle(abs(90));
	}
}

评论

user-avatar
  • 木子呢

    木子呢2019.07.23

    很棒的作品

    0