当前位置:网站首页>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
边栏推荐
- Derivation of sin (a+b) =sina*cosb+sinb*cosa
- 3dmax软件的制作木桶过程:三步流程
- Ctfhub web - divulgation d'informations - traversée du Répertoire
- Grouped uitableview has 20px of extra padding at the bottom
- Leetcode 2163. Minimum difference of sum after element deletion
- In a single-page app, what is the right way to deal with wrong URLs (404 errors)?
- Analysis on the scale of China's smart airport industry in 2020: there is still a large space for competition in the market [figure]
- JD 8 fleet stores search history, deletes history, clears history (not finished)
- Single lithium battery 3.7V power supply 2x12w stereo boost audio power amplifier IC combination solution
- Drosophila played VR and entered nature. It was found that there were attention mechanisms and working memory. The insect brain was no worse than that of mammals
猜你喜欢
Baidu map - introductory tutorial
Ctfhub web - divulgation d'informations - traversée du Répertoire
ACWING/2004. Misspelling
[speech discrimination] discrimination of speech signals based on MATLAB double threshold method [including Matlab source code 1720]
Understand what MTU is
Zero foundation wants to learn web security, how to get started?
Drosophila played VR and entered nature. It was found that there were attention mechanisms and working memory. The insect brain was no worse than that of mammals
ACWING2013. 三条线
Sleep quality today 67 points
[short time energy] short time energy of speech signal based on MATLAB [including Matlab source code 1719]
随机推荐
Self adjustment process of MySQL index tree when adding data
Ht8513 single lithium battery power supply with built-in Dynamic Synchronous Boost 5W mono audio power amplifier IC solution
燕京啤酒何以至此?
DataX tutorial (10) - hot plug principle of dataX plug-in
Non-contact infrared temperature measurement system for human body based on single chip microcomputer
Are these old system codes written by pigs?
Tp6 interface returns three elements
Derivation of sin (a-b) =sina*cosb-sinb*cosa
sin(a-b)=sina*cosb-sinb*cosa的推导过程
Are you still doing the dishes yourself? Teach you how to make dishwasher controller with single chip microcomputer
How to deploy locally developed SAP ui5 applications to ABAP servers
Understand what ICMP Protocol is
[从零开始学习FPGA编程-43]:视野篇 - 后摩尔时代”芯片设计的技术演进-2-演进方向
父爱的表达方式
レレ / 蕾蕾
The process of making wooden barrels with 3DMAX software: a three-step process
Your local changes to the following files would be overwritten by merge: .vs/slnx.sqlite
Entry level use of flask
Is the number of indexes in a table the more the better?
Grouped uitableview has 20px of extra padding at the bottom