NodeMCU bilan 5 voltli o'rni qanday ishlaydi?

Quyidagi fritzingda ko'rsatilganidek, NodeMCU v1.0 bilan 2 ta kanalli 5 voltli o'rni qo`shdim.

Relay are powered with a different power source than NodeMCU Relay are powered with a different power source than NodeMCU.

Hozirda men NodeMCU'imni noutbukdan va 5-voltli akkumulyatordan o'rni kartasidan quvvatladim.

Quyida men yozgan kodim:

#include 
#include 
#include 
#include 

const char* ssid = "said.";
const char* password = "secret";
ESP8266WebServer server ( 80 );
const int led = 13;
const int outputLed = 12;

void turnOnRelayOne(){
  digitalWrite (outputLed, 1);
  digitalWrite (5, HIGH); //GPIO 5//Relay 1
  server.send (200, "text/html", "Relay 1 turned on.");
  digitalWrite (outputLed, 0);
}

void turnOnRelayTwo(){
  digitalWrite (outputLed, 1);
  digitalWrite (4, HIGH); //GPIO 4//Relay 2
  server.send (200, "text/html", "Relay 2 turned on.");
  digitalWrite (outputLed, 0);
}

void handleRoot() {
  digitalWrite ( led, 1 );

  char temp[400];
  int sec = millis()/1000;
  int min = sec/60;
  int hr = min/60;
  int h = dht.readHumidity();
  int t = dht.readTemperature();
  snprintf ( temp, 400,

             "<html>\
  <head>\
    <meta http-equiv='refresh' content='5'/>\
    <title>NodeMCU hooked to Relay Board</title>\
    \
  </head>\
  <body>\
  

Hello from NodeMCU!

\

Uptime: %02d:%02d:%02d

\ </body>\ </html>", hr, min % 60, sec % 60 ); server.send ( 200, "text/html", temp ); digitalWrite ( led, 0 ); } void handleNotFound() { digitalWrite ( led, 1 ); String message = "File Not Found\n\n"; message += "URI: "; message += server.uri(); message += "\nMethod: "; message += ( server.method() == HTTP_GET ) ? "GET" : "POST"; message += "\nArguments: "; message += server.args(); message += "\n"; for ( uint8_t i = 0; i < server.args(); i++ ) { message += " " + server.argName ( i ) + ": " + server.arg ( i ) + "\n"; } server.send ( 404, "text/plain", message ); digitalWrite ( led, 0 ); } void setup ( void ) { pinMode ( led, OUTPUT ); pinMode(10, OUTPUT); pinMode(5, OUTPUT); pinMode(4, OUTPUT); pinMode(outputLed, OUTPUT); digitalWrite ( led, 0 ); Serial.begin ( 9600 ); WiFi.begin ( ssid, password ); Serial.println ( "" ); //Wait for connection while ( WiFi.status() != WL_CONNECTED ) { delay ( 500 ); Serial.print ( "." ); } Serial.println ( "" ); Serial.print ( "Connected to " ); Serial.println ( ssid ); Serial.print ( "IP address: " ); Serial.println ( WiFi.localIP() ); if ( MDNS.begin ( "esp8266" ) ) { Serial.println ( "MDNS responder started" ); } server.on ( "/", handleRoot ); server.on ( "/inline", []() { server.send ( 200, "text/plain", "this works as well" ); } ); server.on("/relay1", turnOnRelayOne); server.on("/relay2", turnOnRelayTwo); server.onNotFound ( handleNotFound ); server.begin(); Serial.println ( "HTTP server started" ); } void loop (void) { server.handleClient(); }

URLni bajarganimda: 192.168.1.8/relay1 outputLed turnOnRelayOne dagi mantiqqa ko'ra, yonib-o'chib turadi.

Biroq, o'rni hech qachon o'chmaydi. Iltimos yordam bering.

0
Men ishonchim komil emas, lekin u 5 voltli yopiq elektron emas. Men 5voltli prizdan yerni ajratish mumkin, deb o'ylayman, biri NodeMCU uchun va biri uchun o'rni uchun. Keyinchalik, o'rni va NodeMCU o'rtasida yopiq eshik ochiladi.
qo'shib qo'ydi muallif product researcher, manba
nima qilish kerak, nima, g ga esp8266 va batareyada g ga ulash
qo'shib qo'ydi muallif Ander Biguri, manba

5 javoblar

Bu modullarning bir nechtasi bor. O'rnatilgan ixtiyoriy opto izolyatorga ega, lekin ularni ishlatish uchun o'tish kabelini olib tashlashingiz kerak.

  • Connect your GPIO trigger as you have it
  • Run the relay's Vcc and Gnd pins to the MCU, not the power plug.
  • connect the power plug's +5v to the left-most pin, where the jumper once stood: JDVcc
  • connect the power plug ground to the MCU or the open common Gnd on the left-group of pins.

Endi sizning o'rni lampalari 5v vilkasini ushlab turadi, lekin o'rni mantig'i va boshqaruvi MCU tomonidan boshqariladi.

5
qo'shib qo'ydi
diagramma meni bir muddat kechiktiradi, men ish joyida suzib boraman, lekin bu so'nggi aloqada umumiy asosdir: agar OPning qora simasi yoki GND ni yoki GPR-da MCU bilan bog'langan bo'lsa, u OK.
qo'shib qo'ydi muallif Alastair, manba
o'ngda, o'rni modulidagi (va MCU) GND'lerin davomiyligi bor, shuning uchun bu variantlar bir xil tarzda harakat qilishadi.
qo'shib qo'ydi muallif Alastair, manba
Javobingizdagi oxirgi aloqani yaxshilab o'ylab ko'rsata olasizmi, ehtimol fritzing diagrammini baham ko'rasizmi?
qo'shib qo'ydi muallif Gusep, manba
Faqatgina tasdiqlash uchun, 5V kuchlanish manbasi yoki o'rni ustidagi ikkinchi pog'onaga (JD-VCC bilan birga) yoki MCU ustidagi tuproq pimiga ulanishi mumkin. To'g'rimi?
qo'shib qo'ydi muallif Gusep, manba

O'rnimizni NodeMCU-dan kuchlanish uchun hech qanday ma'lumotga ega emas. Ikkala qurilmaning quvvat manbalari izolyatsiya qilinganligi sababli (bir-biridan tizza kompyuteri o'zini xavfsiz holatga keltirmasligi mumkin, lekin batareya albatta bo'lishi kerak) (va aslida kerak ) o'rni taxtasi va NodeMCU bilan birga. Elektr ta'minoti xavfsiz holatga kelmasa yoki ular xavfsiz holatga keltirilsa ishonchingiz komil bo'lsa, unda potensial quvvat muammolarini bartaraf qilish uchun optoizolyatsiyalash vositasidan foydalaning.

2
qo'shib qo'ydi

Ushbu o'rni moduli har xil ishlaydi. Signal LOW bo'lsa va u signal yuqori bo'lganida o'chadi (NodeMCUda 3v3V) Ya'ni, ikkita vazifani bajarish uchun kodni o'zgartirish kerak bo'ladi Bundan tashqari, NodeMCU va o'rni moduli umumiy joyga ega ekanligiga ishonch hosil qiling.

#include 
#include 
#include 
#include 

const char* ssid = "said.";
const char* password = "secret";
ESP8266WebServer server ( 80 );
const int led = 13;
const int outputLed = 12;

void turnOnRelayOne(){
  digitalWrite (outputLed, 1);
  digitalWrite (5, LOW); //GPIO 5//Relay 1
  server.send (200, "text/html", "Relay 1 turned on.");
  digitalWrite (outputLed, 0);
}

void turnOnRelayTwo(){
  digitalWrite (outputLed, 1);
  digitalWrite (4, LOW); //GPIO 4//Relay 2
  server.send (200, "text/html", "Relay 2 turned on.");
  digitalWrite (outputLed, 0);
}

void handleRoot() {
  digitalWrite ( led, 1 );

  char temp[400];
  int sec = millis()/1000;
  int min = sec/60;
  int hr = min/60;
  int h = dht.readHumidity();
  int t = dht.readTemperature();
  snprintf ( temp, 400,

             "<html>\
  <head>\
    <meta http-equiv='refresh' content='5'/>\
    <title>NodeMCU hooked to Relay Board</title>\
    \
  </head>\
  <body>\
  

Hello from NodeMCU!

\

Uptime: %02d:%02d:%02d

\ </body>\ </html>", hr, min % 60, sec % 60 ); server.send ( 200, "text/html", temp ); digitalWrite ( led, 0 ); } void handleNotFound() { digitalWrite ( led, 1 ); String message = "File Not Found\n\n"; message += "URI: "; message += server.uri(); message += "\nMethod: "; message += ( server.method() == HTTP_GET ) ? "GET" : "POST"; message += "\nArguments: "; message += server.args(); message += "\n"; for ( uint8_t i = 0; i < server.args(); i++ ) { message += " " + server.argName ( i ) + ": " + server.arg ( i ) + "\n"; } server.send ( 404, "text/plain", message ); digitalWrite ( led, 0 ); } void setup ( void ) { pinMode ( led, OUTPUT ); pinMode(10, OUTPUT); pinMode(5, OUTPUT); pinMode(4, OUTPUT); pinMode(outputLed, OUTPUT); digitalWrite ( led, 0 ); Serial.begin ( 9600 ); WiFi.begin ( ssid, password ); Serial.println ( "" ); //Wait for connection while ( WiFi.status() != WL_CONNECTED ) { delay ( 500 ); Serial.print ( "." ); } Serial.println ( "" ); Serial.print ( "Connected to " ); Serial.println ( ssid ); Serial.print ( "IP address: " ); Serial.println ( WiFi.localIP() ); if ( MDNS.begin ( "esp8266" ) ) { Serial.println ( "MDNS responder started" ); } server.on ( "/", handleRoot ); server.on ( "/inline", []() { server.send ( 200, "text/plain", "this works as well" ); } ); server.on("/relay1", turnOnRelayOne); server.on("/relay2", turnOnRelayTwo); server.onNotFound ( handleNotFound ); server.begin(); Serial.println ( "HTTP server started" ); } void loop (void) { server.handleClient(); }
1
qo'shib qo'ydi
Xm, siz bu rasmdan o'rni modulining haqiqiy turini o'chira olasizmi? Ko'pgina modullar ijobiy mantiqdan foydalangan bo'lsa, ya'ni kirish balandligi o'rni ochiladi.
qo'shib qo'ydi muallif joeqwerty, manba

Muammo shundaki, o'rni 5v, lekin NodeMCU dan kelgan signal 3.3v. Masalan, 5v ga signalni kuchaytirish yoki mantiqiy darajadagi shifterni qo'llash kabi bir narsani qilishingiz mumkin.

Here's a related post: https://electronics.stackexchange.com/questions/213051/how-do-i-use-a-5v-relay-with-a-3-3v-arduino-pro-mini

0
qo'shib qo'ydi
Bunday emas, IMO. NodeMcu ning chiqishi o'rni haydash emas, balki transistor/fet/optocouplerni boshqaradi. Barcha holatlarda, 3.3V yoqilishi uchun juda yaxshi. @Ingacio to'g'ri, sabablar bog'langan bo'lishi kerak. Endi faqat bitta tel NodeMcu va o'rni o'rtasidagi aloqadir. "Voltaj", ikki potensiali orasidagi farq sifatida aniqlanadi, shuning uchun bitta sim etarli emas.
qo'shib qo'ydi muallif joeqwerty, manba

ESP-12E-ni qanday qilib kuchaytirasiz? Bu sizning diagramangizga kiritilmagan. Mikro-USB'dan quvvat olayotganda VU pinini (5V chiqishi) foydalanib muvaffaqiyatga erishdim. Keyin VUni VU ga, GNDni GND ga va GPIO4-ga uzatishingiz mumkin. Agar siz ESP-12E-ni 5v kuchlanish manbasidan to'g'ridan-to'g'ri VIN piniga uloqtirsangiz, men o'sha Relayni bir xil 5V kuchlanish manbasidan kuchga kiritaman. siz GIN + (ESP) va VCC (o'rni) ga ulangan bo'lasiz.

0
qo'shib qo'ydi