当前位置:网站首页>Following the last minor upgrade of nodemcu (esp8266)
Following the last minor upgrade of nodemcu (esp8266)
2022-06-25 06:43:00 【Murphy DL】
Next time nodemcu(esp8266) A little upgrade of
Why do you do this , It's inconvenient to turn off the lights every time you go to bed after you go home , So I thought about this , It's all because of laziness hahahaha
Video on 、 See what has been achieved
Realization : Upload of temperature and humidity , Add relay switch, etc 
nodemcu(esp8266)
Hardware

A breadboard ( It doesn't need to be , Just for the sake of beauty )
esp8266 Module one ( It should be called nodemcu) 12.8 element
A relay switch (1 road 5v) 4.2 element
A photoresistor module 3.2 element
A temperature and humidity sensor 9 element ( I seriously doubt that it is too expensive )
There are several DuPont lines
For software configuration, please read the previous article directly , Detailed description
https://blog.csdn.net/weixin_44695217/article/details/121429305?spm=1001.2014.3001.5502
Program code
Because the code is changed on the basis of the previous steering gear , Therefore, the steering gear program can be ignored
The program inside has detailed notes
#include <Servo.h>
#define BLINKER_WIFI
#define BLINKER_MIOT_LIGHT
#include <Blinker.h>
#include <DHT.h>// contain DHT The header file
// oled use
#include <Arduino.h>
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
//blinker Provided key
char auth[] = " "; // Lighting Key
char ssid[] = " "; //wifi name
char pswd[] = " "; //wifi password
// Send to blinker Humidity data of key, and blink The component name corresponds to
BlinkerNumber HUMI("humi");
// Send to blinker Temperature data of key
BlinkerNumber TEMP("temp");
BlinkerNumber LIGHT("Light"); // Photosensitive resistor
float light=0;
/*----------------------------- Switch relay and steering gear -------------------------------------------------*/
// New component object ( Key + slider )
BlinkerButton Button1("btn-maxm"); // Location 1 Button Data key name
BlinkerButton Button2("btn-closed");
BlinkerSlider Slider1("max-num"); // Location 1 slider Data key name Range 0-180
Servo myservo;
int servo_max=180;
int servo_close=0;
void button1_callback(const String & state) {
// Location 1 Button
BLINKER_LOG("get button state: ", servo_max);
myservo.write(servo_max);
digitalWrite(D3, HIGH);
Blinker.vibrate();
/*--------2021.11.23 Add servo reset program ----------------------*/
BlinkerMIOT.powerState("on");
BlinkerMIOT.print();// Feedback status
delay(1000);// Time delay 1 second
myservo.write(72);// Zero the steering gear , Return to vertical
Blinker.vibrate();
}
void button2_callback(const String & state) {
// Location 1 Button
BLINKER_LOG("get button state: ", servo_close);
myservo.write(servo_close);
digitalWrite(D3, LOW);
Blinker.vibrate();
/*--------2021.11.23 Add servo reset program ----------------------*/
BlinkerMIOT.powerState("on");
BlinkerMIOT.print();// Feedback status
delay(1000);// Time delay 1 second
myservo.write(72);// Zero the steering gear , Return to vertical
Blinker.vibrate();
}
/* void slider1_callback(int32_t value) { BLINKER_LOG("get slider value: ", value); servo_max = value; Slider1.color("#1E90FF"); Slider1.print(); //digitalWrite(D3, value); myservo.write(value);// If you include this sentence ,APP The buttons in the do not work , Only the slider works . } */
/*----------------------------- introduce DHT library , Temperature and humidity --------------------------------------------------*/
#define DHTPIN D6 // Define the temperature and humidity pin connection D6
#define DHTTYPE DHT11 // Define the type of temperature and humidity sensor
DHT dht(DHTPIN, DHTTYPE); // Generate DHT object , The parameters are pins and DHT The type of
uint32_t read_time = 0; // Define the read time
float humi_read, temp_read;// Define floating point global variables Store the temperature and humidity data read by the sensor
/*--------------------------------- Define the read time ----------------------------------------------*/
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
// Blinker.vibrate(); // Once executed, it vibrates
uint32_t BlinkerTime = millis();// This function returns Arduino The number of milliseconds when the board starts running the current program . This figure is around 50 Overflow in days , That is, back to zero .
Blinker.print("millis", BlinkerTime);
}
/*--------------------------------- Heartbeat bag , To give blink Hair temperature and humidity ----------------------------------------------*/
void heartbeat()
{
HUMI.print(humi_read);
TEMP.print(temp_read);
LIGHT.print(light);
}
/*--------------------------------- Define storage time ---------------------------------------------*/
void dataStorage() {
// Add data storage To facilitate the display of icon data
Blinker.dataStorage("humi", humi_read);
// Add data storage To facilitate the display of icon data
Blinker.dataStorage("temp", temp_read);
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead); // Read and print the time on your phone
Blinker.attachHeartbeat(heartbeat);
Blinker.attachDataStorage(dataStorage);// The function means that the above... Will be called each time the loop dataStorage function , To achieve the effect of cloud storage of the data obtained each time .
dht.begin();
u8g2.begin();
u8g2.enableUTF8Print(); // enable UTF8 support for the Arduino print() function
}
void loop()
{
Blinker.run();
/*-------------------------------------------------- Temperature and humidity sensor settings 2022.1.20-------------*/
if (read_time == 0 || (millis() - read_time) >= 2000)
{
read_time = millis();
// Reading humidity
float h = dht.readHumidity();
// Reading temperature
float t = dht.readTemperature();
// Read Fahrenheit
float f = dht.readTemperature(true);// Read Fahrenheit
// Judge whether the reading is successful , If not, return to
if (isnan(h) || isnan(t)) {
BLINKER_LOG("Failed to read from DHT sensor!");
return;
}
float hic = dht.computeHeatIndex(t, h, false);// Calculation of thermal index
humi_read = h;
temp_read = t;
//
// BLINKER_LOG("Humidity: ", h, " %");
// BLINKER_LOG("Temperature: ", t, " *C");
// BLINKER_LOG("Heat index: ", hic, " *C");
// BLINKER_LOG("HuaTemp: ", f, " F");
}
/*---------------------------------- The light detection module is added ,2021.12.21 -----------*/
light=digitalRead(D4); // read out D4 The high and low levels of are assigned to v
BLINKER_LOG("Light: ", light);
if(light==1)// bright ---0
digitalWrite(D1, HIGH);
else
digitalWrite(D1, LOW);
Blinker.delay(1000);// The time delay function
/*------------------------oled Show -----------*/
u8g2.setFont(u8g2_font_unifont_t_chinese2); // use chinese2 for all the glyphs of " Hello world "
u8g2.setFontDirection(0);
u8g2.clearBuffer();
u8g2.setCursor(0, 15);
u8g2.print("temp:",temp_read);
u8g2.sendBuffer();
delay(2000);
// u8g2.setCursor(0, 15);
// u8g2.print("humi:",humi_read);
// u8g2.setCursor(0, 40);
// u8g2.print(" I have a beautiful "); // Chinese "Hello World"
u8g2.sendBuffer();
delay(2000);
}
/* * sg90 The steering gear : 5v--vv The signal line -----D2 Temperature and humidity : D6----DA light : D4 led: D3 oled : D7 (SCL) and D8 SDA) */
Mobile interface settings , Upload of temperature and humidity

边栏推荐
- DataX tutorial (09) - how does dataX achieve speed limit?
- JD 8 fleet stores search history, deletes history, clears history (not finished)
- 了解zbrush雕刻软件,以及游戏建模的分析
- mysql 表查询json数据
- Navicat prevent new query from being deleted by mistake
- Understand what MTU is
- Report on development status and investment strategy recommendations of global and Chinese graphite polystyrene board industry 2022-2028
- Direct select sort and quick sort
- Your local changes to the following files would be overwritten by merge: .vs/slnx.sqlite
- Acwing / 2004. Mauvaise écriture
猜你喜欢

sin(a-b)=sina*cosb-sinb*cosa的推导过程

What is VLAN

After unplugging the network cable, does the original TCP connection still exist?

We cannot activate inspection type for article master in transaction code MM41?

百度地图——入门教程

SAP QM executes the transaction code qp01, and the system reports an error -material type food is not defined for task list type Q-

父爱的表达方式

Ht8513 single lithium battery power supply with built-in Dynamic Synchronous Boost 5W mono audio power amplifier IC solution

Single lithium battery 3.7V power supply 2x12w stereo boost audio power amplifier IC combination solution

Ctfhub web - divulgation d'informations - traversée du Répertoire
随机推荐
How to record a database [closed] - how to document a database [closed]
TCP BBR as rate based
燕京啤酒何以至此?
Uncaught TypeError: Cannot read properties of undefined (reading ‘prototype‘)
Cs5092 5V USB input boost two section lithium battery charging management IC, SOT23-6 miniature package
Are these old system codes written by pigs?
Cs8126t 3.1w mono ultra low EMI unfiltered class D audio power amplifier IC
How to chain multiple different InputStreams into one InputStream
Large funds support ecological construction, and Plato farm builds a real meta universe with Dao as its governance
What is cloud primordial?
Three laws of go reflection
Why can't GC () free memory- Why does gc() not free memory?
Single lithium battery 3.7V power supply 2x12w stereo boost audio power amplifier IC combination solution
【ROS2】为什么要使用ROS2?《ROS2系统特性介绍》
集群常用群起脚本
Unity获取资源路径
The "&" character will destroy the data stored in the web The "&" character breaks passwords that are stored in the web config
Kubernetes core components etcd details
We cannot activate inspection type for article master in transaction code MM41?
アルマ / 炼金妹