人体感应模块控制LCD1602背景灯是否开启

/* Web client This sketch connects to a website (http://www.google.com) using an Arduino Wiznet Ethernet shield. Circuit: * Ethernet shield attached to pins 10, 11, 12, 13 created 18 Dec 2009 by David A. Mellis modified 9 Apr 2012 by Tom Igoe, based on work by Adrian McEwen */ #include <SPI.h> #include <Ethernet.h> #include <LiquidCrystal.h> #define ResetPIN 7 // 初始化引脚 LiquidCrystal lcd(9, 8, 5, 4, 3, 6); // Enter a MAC address for your controller below. // Newer Ethernet shields have a MAC address printed on a sticker on the shield byte mac[] = { 0xDE, 0xAA, 0xCE, 0xEA, 0xFF, 0xE1 }; // if you don't want to use DNS (and reduce your sketch size) // use the numeric IP instead of the name for the server: //IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) char server[] = "192.168.9.6"; // name address for Google (using DNS) String clientPwd="-1"; // Set the static IP address to use if the DHCP fails to assign IPAddress ip(172,16,0,222); IPAddress gateway(172,16,0,1); IPAddress dns_server(60,191,134,196); IPAddress subnet(255,255,0,0); // Initialize the Ethernet client library // with the IP address and port of the server // that you want to connect to (port 80 is default for HTTP): EthernetClient client; int errCount=0; void setup() { //LCD // 设置行列值 lcd.begin(16, 2); pinMode(ResetPIN,OUTPUT); digitalWrite(ResetPIN,LOW); // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } // start the Ethernet connection: // give the Ethernet shield a second to initialize: if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); Ethernet.begin(mac, ip,dns_server,gateway,subnet); } delay(1000); Serial.println("Ready"); } void loop() { Serial.println(clientPwd); // 打印字符串 lcd.setCursor(0,0); lcd.print(clientPwd); httpRequest(); delay(1000); } //================Http Request Code======================== void httpRequest(){ // if you get a connection, report back via serial: if(!client.connected()){ Serial.println("disconnecting."); client.stop(); if (client.connect(server, 9988)) { Serial.println("connected"); }else{ // kf you didn't get a connection to the server: Serial.println("connection failed"); errCount++; if(errCount>=3){ digitalWrite(ResetPIN,HIGH); delay(1000); } } } else{ // Make a HTTP request: client.println("GET /main.ashx?m=c&mil=" + String(millis()) + "&cpwd="+clientPwd+"&rf=0" +" HTTP/1.1"); client.println("Host:" +String(server)); //client.println("Connection: close"); client.println(); delay(10); String reply=""; // if there are incoming bytes available // from the server, read them and print them: while (client.available()) { char c = client.read(); reply+=c; } //Serial.print(reply); int index=reply.indexOf("\"Model\":\"8888"); if(index>=0){ index=index+9; clientPwd= reply.substring(index,index+8); Serial.println("Changed:" + clientPwd); } errCount=0; //wdt_reset(); } } //================End Http Request Code===============
arduino网卡扩展板,会使用 2,10,11,12,13 i/o口,所以要调整lcd使用的接口
人体感应器信号输出连S9013三极管(来控制lcd背景灯的亮与灭(使用K编号的脚)

/* Web client This sketch connects to a website (http://www.google.com) using an Arduino Wiznet Ethernet shield. Circuit: * Ethernet shield attached to pins 10, 11, 12, 13 created 18 Dec 2009 by David A. Mellis modified 9 Apr 2012 by Tom Igoe, based on work by Adrian McEwen */ #include <SPI.h> #include <Ethernet.h> #include <Wire.h> #include <LiquidCrystal_I2C.h> #include <avr/wdt.h> #define ResetPIN 7 #define HasManPIN 8 #define RebootPIN 6 // Enter a MAC address for your controller below. // Newer Ethernet shields have a MAC address printed on a sticker on the shield byte mac[] = { 0xDE, 0xAA, 0xCE, 0x3A, 0x6F, 0xE1 }; // if you don't want to use DNS (and reduce your sketch size) // use the numeric IP instead of the name for the server: //IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) char server[] = "192.168.9.6"; // name address for Google (using DNS) String clientPwd="-1"; int hasMan=0; LiquidCrystal_I2C lcd(0x27,16,2); // Set the static IP address to use if the DHCP fails to assign IPAddress ip(172,16,0,172); IPAddress gateway(172,16,0,1); IPAddress dns_server(60,191,134,196); IPAddress subnet(255,255,0,0); // Initialize the Ethernet client library // with the IP address and port of the server // that you want to connect to (port 80 is default for HTTP): EthernetClient client; int errCount=0; unsigned long lastRequest=0; void setup() { pinMode(HasManPIN,INPUT); pinMode(ResetPIN,OUTPUT); pinMode(RebootPIN,OUTPUT); digitalWrite(ResetPIN,LOW); digitalWrite(RebootPIN,LOW); // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } // start the Ethernet connection: // give the Ethernet shield a second to initialize: if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); Ethernet.begin(mac, ip,dns_server,gateway,subnet); } lcd.init(); lcd.backlight(); lcd.print("-1"); delay(1000); Serial.println("Ready"); lastRequest=millis(); wdt_enable(WDTO_8S); } void loop() { //digitalWrite(RebootPIN,LOW); if((millis()-lastRequest)>=1200){ Serial.println("reboot"); digitalWrite(ResetPIN,HIGH); delay(1000); } Serial.println("lcd..."); Serial.println(clientPwd); // 打印字符串 lcd.setCursor(0,0); lcd.print(clientPwd); //digitalWrite(RebootPIN,HIGH); hasMan=digitalRead(HasManPIN); Serial.println(hasMan); if(hasMan==1){ lcd.backlight(); }else{ lcd.noBacklight(); } if( (millis() - lastRequest) >=1000) { httpRequest(); lastRequest=millis(); } delay(25); Serial.println("lcd over!"); // wdt_reset(); } //================Http Request Code======================== void httpRequest(){ // if you get a connection, report back via serial: if(!client.connected()){ Serial.println("disconnecting."); client.stop(); if (client.connect(server, 9988)) { Serial.println("connected"); }else{ // kf you didn't get a connection to the server: Serial.println("connection failed"); errCount++; if(errCount>=3){ digitalWrite(ResetPIN,HIGH); delay(1000); } } } else{ // Make a HTTP request: client.println("GET /main.ashx?m=c&mil=" + String(millis()) + "&cpwd="+clientPwd+"&rf="+String(hasMan) +" HTTP/1.1"); client.println("Host:" +String(server)); //client.println("Connection: close"); client.println(); delay(10); String reply=""; // if there are incoming bytes available // from the server, read them and print them: while (client.available()) { char c = client.read(); reply+=c; } //Serial.print(reply); int index=reply.indexOf("\"Model\":\"8888"); if(index>=0){ index=index+9; clientPwd= reply.substring(index,index+8); Serial.println("Changed:" + clientPwd); } errCount=0; //wdt_reset(); } } //================End Http Request Code===============
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述
2008-10-17 C#中的时间操作