[教程]ESP8266小爱同学舵机开门

展示:

APP界面
小爱同学
总览

材料:
开发板
舵机MG996R【996R为高扭矩版本,速度慢但是力量大】

注意事项!!!!!!!!
电源需要5v3A
5V1A肯定不行
测试时候无反应检查是否接到5V3A电源
并且开发板和舵机需要在同一个电源上【并联接入】
舵机有方向!!!请按照图里方向安装【自己探索也可以】
源码中每次开门锁后保持5秒,给人推开门的时间

接线:
除了电源线,就是舵机调节的线,接D4【GPIO2】

#include
#define BLINKER_WIFI
#define BLINKER_MIOT_OUTLET
Servo myServo;
#include

char auth[] = “KEY”;
char ssid[] = “SSID”;
char pswd[] = “password”;

bool oState = false;
//APP
#define BUTTON_1 “ButtonKey”
BlinkerButton Button1(BUTTON_1);
void button1_callback(const String & state)
{
BLINKER_LOG(“get button state: “, state);

if (state == BLINKER_CMD_BUTTON_TAP) {
BLINKER_LOG(“Button tap!”);
Button1.color(“#FFFFFF”);
Button1.text(“开门”);
Button1.print();
myServo.attach(2); //D4
myServo.write(0);
Blinker.delay(5000);
myServo.write(180);
Blinker.delay(400);
myServo.detach();
}
else {
BLINKER_LOG(“Get user setting: “, state);

Button1.icon(“icon_1”);
Button1.color(“#FFFFFF”);
Button1.text(“Your button name or describe”);
// Button1.text(“Your button name”, “describe”);
Button1.print();
}
}

void miotPowerState(const String & state)
{
BLINKER_LOG(“need set power state: “, state);

if (state == BLINKER_CMD_ON) {
myServo.attach(2); //D4
myServo.write(180);

BlinkerMIOT.powerState(“on”);
BlinkerMIOT.print();

oState = true;
myServo.write(0);
Blinker.delay(5000);
myServo.write(180);
Blinker.delay(400);
myServo.detach();
oState = false;
}
else if (state == BLINKER_CMD_OFF) {
BlinkerMIOT.powerState(“off”);
BlinkerMIOT.print();

oState = false;
}
}

void miotQuery(int32_t queryCode)
{
BLINKER_LOG(“MIOT Query codes: “, queryCode);

switch (queryCode)
{
case BLINKER_CMD_QUERY_ALL_NUMBER :
BLINKER_LOG(“MIOT Query All”);
BlinkerMIOT.powerState(oState ? “on” : “off”);
BlinkerMIOT.print();
break;
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
BLINKER_LOG(“MIOT Query Power State”);
BlinkerMIOT.powerState(oState ? “on” : “off”);
BlinkerMIOT.print();
break;
default :
BlinkerMIOT.powerState(oState ? “on” : “off”);
BlinkerMIOT.print();
break;
}
}

void dataRead(const String & data)
{
BLINKER_LOG(“Blinker readString: “, data);

Blinker.vibrate();

uint32_t BlinkerTime = millis();

Blinker.print(“millis”, BlinkerTime);
}

void setup()
{
myServo.attach(2); //D4
myServo.write(0);
myServo.detach();

Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);

Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
Button1.attach(button1_callback);//APP
BlinkerMIOT.attachPowerState(miotPowerState);
BlinkerMIOT.attachQuery(miotQuery);
}

void loop()
{
Blinker.run();
}

界面配置:
{¨version¨¨2.0.0¨¨config¨{¨headerColor¨¨transparent¨¨headerStyle¨¨dark¨¨background¨{¨img¨¨assets/img/headerbg.jpg¨¨isFull¨«}}¨dashboard¨|{¨type¨¨tex¨¨t0¨¨FBI ¨¨t1¨¨Open the door¨¨size¨¤E¨bg¨É¨ico¨¨fad fa-toggle-off¨¨cols¨Í¨rows¨Ë¨key¨´门´´x´É´y´É¨speech¨|÷¨lstyle¨Ì}{ßC¨btn¨ßK¨fad fa-play-circle¨¨mode¨ÉßE¨文本1¨ßG¨文本2¨ßJÉßMËßNËßO¨ButtonKey¨´x´Í´y´ÉßP|÷ßQÉ}{ßC¨deb¨ßTÉßJÉßMÑßNÌßO¨debug¨´x´É´y´Ë}÷¨actions¨|÷¨triggers¨|÷}

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇