当前位置:网站首页>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

边栏推荐
- The perfect presentation of Dao in the metauniverse, and platofarm creates a farm themed metauniverse
- Hongmeng learning notes: creating layouts using XML
- Drawing shp files using OpenGL
- System dilemma and software complexity: Why are our systems so complex?
- The "&" character will destroy the data stored in the web The "&" character breaks passwords that are stored in the web config
- Is it safe to open a stock account on the Internet in Beijing?
- How to find happiness in programming and get lasting motivation?
- 这些老系统代码,是猪写的么?
- The Rust Programming Language
- Arm register (cortex-a), coprocessor and pipeline
猜你喜欢

直接选择排序和快速排序

ACWING/2004. Misspelling

Wan Yin revealed that he was rejected by MIT in this way: "the department doesn't like you". He confronted the principal and realized

Uncaught TypeError: Cannot read properties of undefined (reading ‘prototype‘)

Entry level use of flask

【2022黑马程序员】SQL优化

Understand ZBrush carving software and game modeling analysis

了解zbrush雕刻软件,以及游戏建模的分析

Navicat prevent new query from being deleted by mistake

Cannot activate inspection type when SAP retail uses transaction code mm41 to create commodity master data?
随机推荐
MSG_ OOB MSG_ PEEK
百度地图——入门教程
sin(a-b)=sina*cosb-sinb*cosa的推导过程
Missing libgmp-10 dll - libgmp-10. dll is missing
Metauniverse in 2022: robbing people, burning money and breaking through the experience boundary
Derivation of COS (a-b) =cosa*cosb+sina*sinb
聚类和分类的最基本区别。
sin(a+b)=sina*cosb+sinb*cosa的推导过程
Sophomores majoring in mechanics build a manipulator by hand -- full of compromise
父爱的表达方式
Arm register (cortex-a), coprocessor and pipeline
JD 8 fleet stores search history, deletes history, clears history (not finished)
Your local changes to the following files would be overwritten by merge: .vs/slnx.sqlite
直接选择排序和快速排序
ASP. Net core - encrypted configuration in asp NET Core
The Rust Programming Language
3dmax软件的制作木桶过程:三步流程
We cannot activate inspection type for article master in transaction code MM41?
mysql 表查询json数据
[200 opencv routines of youcans] 104 Motion blur degradation model