NODMCU sketch problem

hello.i have a board NODMCU,and i want you to help me make a sketch to press a button and one relay output is activated for 3 minutes and then another relay output is activated for 1 minute.hope i didn't bore you and find a way ' that bit of a beginner. Thanks

Hello,

why did you post in the Emergency Response: Covid-19 Projects category?

do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation for your ask).

(I moved your post for this time to a more suitable place)


how do you define "help you"? make the code for you or review your code and circuit and provide guidance? what have you done so far? how did you decide to go for a NODMCU?

Start by reading about millis: https://docs.arduino.cc/built-in-examples/digital/BlinkWithoutDelay/

Using millis is just one option. If you choose to use millis, then there are again a number of good options.
I would create a timer of 1 minute, and then count the minutes and act if something needs to be done.

If you are new to programming and Arduino, then I suggest to start reading about digitalRead() and digitalWrite().

Thanks for your answers. The board was there, that's why I wanted to experiment with this one. I made an attempt and made a sketch, then I did the wiring, and it worked. Even though I'm a beginner with a little reading you said, I did something! Next time I will upload the sketch normally. I'm sorry, I'll correct it.

please, please never ever again post pictures of text... Not only they are not readable nor usable directly for copy&paste but they use up lots of storage and internet bandwidth which contributes to polluting the planet.

➜ do your part and do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation for your ask).

I think that is a HL-525 relay module. Some explanation is here: https://components101.com/switches/5v-dual-channel-relay-module-pinout-features-applications-working-datasheet
I think it is not fully compatible with a 3.3V board.

I think your board is a ESP8266.

It is dangerous to solder wires to the pins like that. The board around it gets easily too hot and copper traces might break.

You also need a button.

I apologize for posting the photos.
Very well, the board is HL-52S
Powered by 5 volts.
As a sketch, I notice that it works just fine!
Do I need to conclude anything else?

int Relay1Pin =4;
int Relay2Pin =14; // push button is connected
const int button = 0;
int temp = 0;    // temporary variable for reading the button pin status

void setup() {
  Serial.begin(9600);
  pinMode(Relay1Pin,OUTPUT);
  pinMode(Relay2Pin,OUTPUT);
  pinMode(button, INPUT);
  digitalWrite(Relay1Pin, HIGH);
  digitalWrite(Relay2Pin, HIGH);
}

void loop() {
  temp = digitalRead(button);
     
     if (temp == LOW) {
        Serial.println("Relay1Pin ON");
        digitalWrite(Relay1Pin, LOW);
        delay(10000);
        digitalWrite(Relay1Pin, HIGH);
        Serial.println("Relay1Pin OFF");
     if (digitalRead(Relay1Pin) == HIGH);
        Serial.println("Relay2Pin ON");
       digitalWrite(Relay2Pin,LOW);
       delay(30000);
       digitalWrite(Relay2Pin, HIGH);
       Serial.println("Relay2Pin OFF");}}

Are you using the Arduino IDE ?
Can your right-click on the code and select "Format Document", then fix all the brackets '{' and '}'.
A if-statement with a ';' is doing nothing, the semi-colon ';' is a empty statement.

// This is a empty if-statement
if (day == monday);        // if it is monday, do nothing

// This is a if-statement with a single command line
if (day == tuesday)
  Serial.println("What a nice day");

// This is a if-statement with a block of code
if (day = wednesday)
{
  // buzzer
  tone(9, 1000);
  // message
  Serial.println("Message");
  // relay
  digitalWrite(relayPin,HIGH);
}

Now is OK?

int Relay1Pin = 4;
int Relay2Pin = 14; // push button is connected
const int button = 0;
int temp = 0;    // temporary variable for reading the button pin status

void setup() {
  Serial.begin(9600);
  pinMode(Relay1Pin, OUTPUT);
  pinMode(Relay2Pin, OUTPUT);
  pinMode(button, INPUT);
  digitalWrite(Relay1Pin, HIGH);
  digitalWrite(Relay2Pin, HIGH);
}

void loop() {
  temp = digitalRead(button);

  if (temp == LOW) {
    Serial.println("Relay1Pin ON");
    digitalWrite(Relay1Pin, LOW);
    delay(10000);
    digitalWrite(Relay1Pin, HIGH);
    Serial.println("Relay1Pin OFF");
    if (digitalRead(Relay1Pin) == HIGH)
    { Serial.println("Relay2Pin ON");
      digitalWrite(Relay2Pin, LOW);
      delay(15000);
      digitalWrite(Relay2Pin, HIGH);
      Serial.println("Relay2Pin OFF");
    }
  }
}

Better :smiley:

Why do you do a digitalRead() ? If you set the output HIGH, then you know it is HIGH, if you set the output LOW, then you know it is LOW.

The hardest part of writing code is describing something from the real world in a logical way. If you can do that, then half the sketch is already written.

This is the most simple description.

Is button pressed ?
  activate relay 1
  wait 3 minutes
  de-activate relay 1
  activate relay 2
  wait 1 minute
  de-activate relay 2

That description is not complete. What happens if the button is pressed and never released ?
Do you want to add things to the sketch ? for example a blinking led ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.