Jump to content
ELFORUM - Forumul electronistilor

Wireless WIFI Development Board D1 R2 WiFi based ESP8266 for arduino nodemcu WeMos uno-R3


Recommended Posts

Salutare! Am nevoie de ajutor pentru rezolvarea urmatoarei probleme: am un modul Wireless WIFI Development Board  D1 R2 WiFi based ESP8266 for arduino nodemcu  WeMos uno-R3, un modul releu pe 5V si un senzor de tensiune. Am scris o schita pentru comandarea releului in functie de tensiunea citita la bornele unei baterii de 12V, respectiv daca tensiunea este mai mare decat 12.5V sa inchida releul(High) iar daca este mai mica sa dechida releul(Low). Problema este ca daca folosesc un modul Arduino uno, releul si senzorul, montajul merge, iar cand inlocuiesc modulul Arduino cu WeMos, releul nu mai este actionat. In fapt LED-ul martor ramane mereu aprins fapt ce ar insemna ca releul trebuie sa se inchida, iar la releu nu se aude nici un tacanit, adica nu se inchide. Tensiune de alimentare a modulului este 5V. Am alimentat releul atat din modul, cat si separat, dar rezultatul este acelasi. Am incercat pe mai multe module, caci am cumparat mai multe, dar acelasi rezultat. multumesc!

Link to comment
  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

#include <ESP8266WiFi.h>

const char* ssid = "XXXXX"; // Set the SSID for the Wi-Fi access point
const char* password = "YYYYYYY"; // Set the password for the Wi-Fi access point

// Pin assignments

const int tensionSensorPin = A0; // Analog pin for tension sensor

const int relay1Pin = 5;         // Digital pin for relay 1 invertor

const int relay2Pin = 4;         // Digital pin for relay 2 priza  = faza prizei

const int relay3Pin = 3;         // Digital pin for relay 3 priza = nulul prizei

const int relayPin = 2;         // Digital pin for relay 4  program pentru ventilator

unsigned long previousMillis = 0; // Variable to store the last time the relay was switched

int relayState = LOW; // Initial state of the relay

unsigned long intervalLowDay = 120000; // 120 seconds in milliseconds during the day

unsigned long intervalHighDay = 1680000; // 28 minutes in milliseconds during the day

unsigned long intervalLowNight = 90000; // 90 seconds in milliseconds during the night

unsigned long intervalHighNight = 3480000; // 58 minutes in milliseconds during the night

void setup() {

  pinMode(relay1Pin, OUTPUT);

  pinMode(relay2Pin, OUTPUT);

  pinMode(relay3Pin, OUTPUT);

  pinMode(relayPin, OUTPUT);

  pinMode(tensionSensorPin, INPUT);

Serial.begin(115200);
WiFi.begin(ssid, password);

 

  Serial.print("Connecting to ");

  Serial.println(ssid);

 

  while (WiFi.status() != WL_CONNECTED) {

    delay(500);

    Serial.print(".");

  }

 

  Serial.println("");

  Serial.println("WiFi connected");

  Serial.println("IP address: ");

  Serial.println(WiFi.localIP());

}

void loop() {

  // Read tension from the sensor (assuming 0-5V range)

  float tension = analogRead(tensionSensorPin) * 5.0 / 1023.0;

  if (tension >= 12.5) {

    // High tension: Turn relay 2 and 3 off, then relay 1 on

    digitalWrite(relay2Pin, HIGH);

    Serial.println("Releu 2 oprit");

    digitalWrite(relay3Pin, HIGH);

    Serial.println("Releu 3 oprit");

delay(100); // Wait for 1.0 seconds

    digitalWrite(relay1Pin, LOW);

    Serial.println("Releu 1 pornit");

    delay(10000); // Wait for 10 seconds

  } else {

    // Low tension: Turn relay 1 off, then relay 2 and 3 on

    digitalWrite(relay1Pin, HIGH);

    Serial.println("Releu 1 oprit");

    delay(1000); // Wait for 1.0 seconds

    digitalWrite(relay2Pin, LOW);

    Serial.println("Releu 2 pornit");

    digitalWrite(relay3Pin, LOW);

    Serial.println("Releu 3 pornit");

    delay(60000); // Wait for 60 seconds

  }

 

unsigned long currentMillis = millis(); // Get the current time

 

if ((currentMillis >= 36000000 && currentMillis < 64800000) || (currentMillis >= 68400000 || currentMillis < 25200000)) {

// Daytime operation

if (relayState == LOW && currentMillis - previousMillis >= intervalLowDay) {

relayState = HIGH;

previousMillis = currentMillis;

} else if (relayState == HIGH && currentMillis - previousMillis >= intervalHighDay) {

relayState = LOW;

previousMillis = currentMillis;

}

} else {

// Nighttime operation

if (relayState == LOW && currentMillis - previousMillis >= intervalLowNight) {

relayState = HIGH;

previousMillis = currentMillis;

} else if (relayState == HIGH && currentMillis - previousMillis >= intervalHighNight) {

relayState = LOW;

previousMillis = currentMillis;

}

}

digitalWrite(relayPin, relayState); // Set the relay to the current state

}

Link to comment

Pe  ESP8266 ai un singur pin analogic, deci linia de mai jos nu prea are sens

const int tensionSensorPin = A0; // Analog pin for tension sensor

Ai nevoie de un divizor rezistiv ca sa citesti tensiunea de 12-14V de la baterie, pinul A0 accepta maxim 1V (pe unele module exista un divizor integrat, caz in care se poate masura maxim 3,3V).
In codul tau, in setup, pinul A0 este declarat ca fiind intrare digitala.
Pinii analogici nu au nevoie de pinMode.

Link to comment

Verifica timpii aici:

if ((currentMillis >= 36000000 && currentMillis < 64800000) || (currentMillis >= 68400000 || currentMillis < 25200000))

 Aici:

  Serial.println("Releu 3 oprit");

delay(100); // Wait for 1.0 seconds

probabil ca ai vrut 1 secunda si a iesit 100ms.

In alta ordine de idei, verifica, cu un osciloscop, ce se intampla pe pinul de comanda al releului care nu raspunde la comenzi.

Link to comment

Multumesc tuturor celor care mi-ati raspuns. Pana una alta folosesc modulul Arduino acum. Nu am stiut ca la WeMos la pinul A0 trebuie un semnal cu tensiunea in intervalul 0-1V, am crezut ca merge cu 3,3V. Ce trebuie sa fac in acest caz, sa inseriez o rezistenta? Aveti idee ce valoare ar trebui sa aiba rezistenta? In alta ordine de idei am mai cautat schite si scheme cu WeMos pe Google si am vazut ca sunt relee dedicate pentru WeMos. Eu am niste relee cu optocuplor  cu doua posibilitati de cuplare, low si high...teoretic ar fi trebuit sa mearga macar pe una dintre variantele de cuplare, dar LED-urile de control se aprind aiurea, ci nu conform schitei.

Elison, daca ai chef si timp copiaza schita mea intr-un Word, corecteaza ceea ce crezi ca nu este corect si pune inapoi aici varianta ta.

Multumesc inca o data tuturor!

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.




×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.Terms of Use si Guidelines