How to use 2 relay module in arduino

for (int i = COUNTDOWN_TIME; i > 0; i--) {
        minutes = COUNTDOWN_TIME / 60;
        seconds = COUNTDOWN_TIME % 60;
        display.showNumberDecEx(minutes * 100 + seconds, 0b01000000, true);
        COUNTDOWN_TIME--;
        lcd.setCursor(0, 1);
        lcd.print("   ");
        lcd.setCursor(0, 1);
        lcd.print(i);
      }

how to control the relay and inserted in my code sorry to bother you all

but I need help this is the last component that i put

this is the sequence of the system or the project i build

the function of the relay is to control the on and off of the machine for 5 to 10 sec only after 5 or 10sec the power of the machine is off

and how to code this sequence i know how to connect my machine to the relay but i don't know how to program the sequence i try a lot code but it not running

Post your complete code and your project schematic wiring.

1 Like

Since the code you posted does not use the relay, please post a copy of the code that uses the relay, but does not work. We will begin with that code!

No relays in that code.

@sai_07 - Forum procedure has not changed since your last topic.

Are you going to disappear on this topic, too, after people spend hours helping?

assuming this is continuation of previous project.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

#define coinSlot 6
#define buzzer 13
#define button 4
#define heater 5
#define pump 6
int coinSlotStatus;
int pulse;

bool userBalance = false;
bool noCoin = false;

char lcdBuffer[16];

int buttonState;

#define interval 1000
#define CLK 2  // pin D2 - CLK 
#define DIO 3 // pin D3 - DIO
#include <Arduino.h>
#include <TM1637Display.h>
int COUNTDOWN_TIME =0; //  in seconds
int minutes = 0;
int seconds = 0;
TM1637Display display(CLK, DIO);

void setup() {
  display.setBrightness(3); // set brightness of tm1637, 0 (lowest brightness) to 7 (highest brightness)
  lcd.init();
  lcd.backlight();
  lcd.clear();
  pinMode(buzzer, OUTPUT);
  pinMode(10, OUTPUT);
  digitalWrite(10, LOW);
  pinMode(coinSlot, INPUT_PULLUP);
  pinMode(button, INPUT);
  pinMode(heater, OUTPUT);
  pinMode(pump, OUTPUT);
  digitalWrite(heater, 1); // turn off heater relay 
  digitalWrite(pump, 1); // turn off pump relay 
  tone(buzzer, 262);
  delay(150);
  tone(buzzer, 294);
  delay(150);
  tone(buzzer, 330);
  delay(150);
  tone(buzzer, 349);
  delay(150);
  tone(buzzer, 392);
  delay(150);
  tone(buzzer, 440);
  delay(150);
  tone(buzzer, 394);
  delay(150);
  tone(buzzer, 563);
  delay(150);
  noTone(buzzer);
  delay(1000);
}

void loop() {
  if (noCoin == false) {
    noCoin = true;
    lcd.setCursor(0, 0);
    lcd.print(" Insert Coin");
  }


  buttonState = digitalRead(button);

  if (pulse==20 and buttonState == 1 && COUNTDOWN_TIME > 0 && userBalance) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("WARMING UP");
    digitalWrite(heater, 0);
    delay(180000); 
    digitalWrite(heater, 1);
    COUNTDOWN_TIME = COUNTDOWN_TIME - 180000;
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Pumping Liquid");

    for (int i = COUNTDOWN_TIME; i > 0; i--) {
      minutes = COUNTDOWN_TIME / 60;
      seconds = COUNTDOWN_TIME % 60;
      display.showNumberDecEx(minutes * 100 + seconds, 0b01000000, true);
      COUNTDOWN_TIME -- ;
      lcd.setCursor(0, 1);
      lcd.print("   ");
      lcd.setCursor(0, 1);
      lcd.print(i);
      tone(buzzer,523);
      digitalWrite(pump, 0); 
      delay(500);
      noTone(buzzer);
      digitalWrite(pump, 1); 
      delay(500);
    }

    pulse = 0;
    display.showNumberDecEx(0000, 0b01000000, true);
    noCoin = false;
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(" Thank You Bye!");
    delay(1700);
    tone(buzzer, 3000);
    delay(200);
    noTone(buzzer);
    delay(50);
    tone(buzzer, 3000);
    delay(50);
    noTone(buzzer);
    display.clear();


  }


  coinSlotStatus = digitalRead(coinSlot);
  delay(30);
  if (coinSlotStatus == 0) {
    userBalance = true;
    lcd.setCursor(0, 0);
    lcd.print("Press a Button");
    pulse += 1;
    COUNTDOWN_TIME=15*pulse;
    lcd.setCursor(0, 1);
    sprintf(lcdBuffer, "Bal. Php %d.00", pulse);
    lcd.setCursor(0, 1);
    lcd.print(lcdBuffer);
    delay(30);
  }
  noTone(buzzer);
 
}

this could work (not tested)

thank for your help and i hope i help other if i knowledgeable in this field and i need to learn more about Arduino and how to code

yes! you can search for Arduino coding tutorial on youtube in your own language

there's an error in code

C:\Users\SP Bel\Documents\Arduino\fogingMachine\fogingMachine.ino:16:1: error: 'boolean' does not name a type; did you mean 'bool'?
boolean userBalance = false;
^~~~~~~
bool
C:\Users\SP Bel\Documents\Arduino\fogingMachine\fogingMachine.ino:17:1: error: 'boolean' does not name a type; did you mean 'bool'?
boolean noCoin = false;
^~~~~~~
bool
C:\Users\SP Bel\Documents\Arduino\fogingMachine\fogingMachine.ino: In function 'void loop()':
C:\Users\SP Bel\Documents\Arduino\fogingMachine\fogingMachine.ino:68:7: error: 'noCoin' was not declared in this scope
if (noCoin == false) {
^~~~~~
C:\Users\SP Bel\Documents\Arduino\fogingMachine\fogingMachine.ino:68:7: note: suggested alternative: 'noTone'
if (noCoin == false) {
^~~~~~
noTone
C:\Users\SP Bel\Documents\Arduino\fogingMachine\fogingMachine.ino:77:7: warning: init-statement in selection statements only available with -std=c++1z or -std=gnu++1z
if (pulse == 20; buttonState == 1 && COUNTDOWN_TIME > 0 && userBalance) {
^~~~~
C:\Users\SP Bel\Documents\Arduino\fogingMachine\fogingMachine.ino:77:13: warning: statement has no effect [-Wunused-value]
if (pulse == 20; buttonState == 1 && COUNTDOWN_TIME > 0 && userBalance) {
^
C:\Users\SP Bel\Documents\Arduino\fogingMachine\fogingMachine.ino:77:62: error: 'userBalance' was not declared in this scope
if (pulse == 20; buttonState == 1 && COUNTDOWN_TIME > 0 && userBalance) {
^
~~~~~~~~
C:\Users\SP Bel\Documents\Arduino\fogingMachine\fogingMachine.ino:99:26: error: 'low' was not declared in this scope
digitalWrite(pump, low);
^~~
C:\Users\SP Bel\Documents\Arduino\fogingMachine\fogingMachine.ino:99:26: note: suggested alternative: 'pow'
digitalWrite(pump, low);
^~~
pow
C:\Users\SP Bel\Documents\Arduino\fogingMachine\fogingMachine.ino:102:26: error: 'high' was not declared in this scope
digitalWrite(pump, high);
^~~~
C:\Users\SP Bel\Documents\Arduino\fogingMachine\fogingMachine.ino:102:26: note: suggested alternative: 'sinh'
digitalWrite(pump, high);
^~~~
sinh
C:\Users\SP Bel\Documents\Arduino\fogingMachine\fogingMachine.ino:108:5: error: 'noCoin' was not declared in this scope
noCoin = false;
^~~~~~
C:\Users\SP Bel\Documents\Arduino\fogingMachine\fogingMachine.ino:108:5: note: suggested alternative: 'noTone'
noCoin = false;
^~~~~~
noTone
C:\Users\SP Bel\Documents\Arduino\fogingMachine\fogingMachine.ino:129:5: error: 'userBalance' was not declared in this scope
userBalance = true;
^~~~~~~~~~~

exit status 1

Compilation error: 'boolean' does not name a type; did you mean 'bool'?

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

#define coinSlot 6
#define buzzer 13
#define button 4
#define heater 5
#define pump 6
#define uvLight 7

int coinSlotStatus;
int pulse;

boolean userBalance = false;
boolean noCoin = false;

char lcdBuffer[16];

int buttonState;

#define interval 1000
#define CLK 2  // pin D2 - CLK 
#define DIO 3 // pin D3 - DIO
#include <Arduino.h>
#include <TM1637Display.h>
int COUNTDOWN_TIME =0; //  in seconds
int minutes = 0;
int seconds = 0;
TM1637Display display(CLK, DIO);

void setup() {
  display.setBrightness(3); // set brightness of tm1637, 0 (lowest brightness) to 7 (highest brightness)
  lcd.init();
  lcd.backlight();
  lcd.clear();
  pinMode(buzzer, OUTPUT);
  pinMode(10, OUTPUT);
  digitalWrite(10, LOW);
  pinMode(coinSlot, INPUT_PULLUP);
  pinMode(button, INPUT);
  pinMode(heater, OUTPUT);
  pinMode(pump, OUTPUT);
  digitalWrite(heater, HIGH); // turn off heater relay 
  digitalWrite(pump, HIGH); // turn off pump relay 
  tone(buzzer, 262);
  delay(150);
  tone(buzzer, 294);
  delay(150);
  tone(buzzer, 330);
  delay(150);
  tone(buzzer, 349);
  delay(150);
  tone(buzzer, 392);
  delay(150);
  tone(buzzer, 440);
  delay(150);
  tone(buzzer, 394);
  delay(150);
  tone(buzzer, 563);
  delay(150);
  noTone(buzzer);
  delay(1000);
}

void loop() {
  if (noCoin == false) {
    noCoin = true;
    lcd.setCursor(0, 0);
    lcd.print(" Insert Coin");
  }


  buttonState = digitalRead(button);

  if (pulse == 20; buttonState == 1 && COUNTDOWN_TIME > 0 && userBalance) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("WARMING UP");
    digitalWrite(heater, LOW);
    delay(180000); 
    digitalWrite(heater, HIGH);
    COUNTDOWN_TIME = COUNTDOWN_TIME - 180000;
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Pumping Liquid");

    for (int i = COUNTDOWN_TIME; i > 0; i--) {
      minutes = COUNTDOWN_TIME / 60;
      seconds = COUNTDOWN_TIME % 60;
      display.showNumberDecEx(minutes * 100 + seconds, 0b01000000, true);
      COUNTDOWN_TIME -- ;
      lcd.setCursor(0, 1);
      lcd.print("   ");
      lcd.setCursor(0, 1);
      lcd.print(i);
      tone(buzzer,523);
      digitalWrite(pump, low); 
      delay(500);
      noTone(buzzer);
      digitalWrite(pump, high); 
      delay(500);
    }

    pulse = 0;
    display.showNumberDecEx(0000, 0b01000000, true);
    noCoin = false;
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(" Thank You Bye!");
    delay(1700);
    tone(buzzer, 3000);
    delay(200);
    noTone(buzzer);
    delay(50);
    tone(buzzer, 3000);
    delay(50);
    noTone(buzzer);
    display.clear();


  }


  coinSlotStatus = digitalRead(coinSlot);
  delay(30);
  if (coinSlotStatus == 0) {
    userBalance = true;
    lcd.setCursor(0, 0);
    lcd.print("Press a Button");
    pulse += 1;
    COUNTDOWN_TIME=15*pulse;
    lcd.setCursor(0, 1);
    sprintf(lcdBuffer, "Bal. Php %d.00", pulse);
    lcd.setCursor(0, 1);
    lcd.print(lcdBuffer);
    delay(30);
  }
  noTone(buzzer);
 
}

I have corrected some mistakes on privious post.

I have also changed Boolean to bool but I wonder why it is showing error for Boolean

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

#define coinSlot 6
#define buzzer 13
#define button 4
#define heater 5
#define pump 6
int coinSlotStatus;
int pulse;

bool userBalance = false;
bool noCoin = false;

char lcdBuffer[16];

int buttonState;

#define interval 1000
#define CLK 2  // pin D2 - CLK 
#define DIO 3 // pin D3 - DIO
#include <Arduino.h>
#include <TM1637Display.h>
int COUNTDOWN_TIME =0; //  in seconds
int minutes = 0;
int seconds = 0;
TM1637Display display(CLK, DIO);

void setup() {
  display.setBrightness(3); // set brightness of tm1637, 0 (lowest brightness) to 7 (highest brightness)
  lcd.init();
  lcd.backlight();
  lcd.clear();
  pinMode(buzzer, OUTPUT);
  pinMode(10, OUTPUT);
  digitalWrite(10, LOW);
  pinMode(coinSlot, INPUT_PULLUP);
  pinMode(button, INPUT);
  pinMode(heater, OUTPUT);
  pinMode(pump, OUTPUT);
  digitalWrite(heater, 1); // turn off heater relay 
  digitalWrite(pump, 1); // turn off pump relay 
  tone(buzzer, 262);
  delay(150);
  tone(buzzer, 294);
  delay(150);
  tone(buzzer, 330);
  delay(150);
  tone(buzzer, 349);
  delay(150);
  tone(buzzer, 392);
  delay(150);
  tone(buzzer, 440);
  delay(150);
  tone(buzzer, 394);
  delay(150);
  tone(buzzer, 563);
  delay(150);
  noTone(buzzer);
  delay(1000);
}

void loop() {
  if (noCoin == false) {
    noCoin = true;
    lcd.setCursor(0, 0);
    lcd.print(" Insert Coin");
  }


  buttonState = digitalRead(button);

  if (pulse==20 && buttonState == 1 && COUNTDOWN_TIME > 0 && userBalance) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("WARMING UP");
    digitalWrite(heater, 0);
    delay(180000); 
    digitalWrite(heater, 1);
    COUNTDOWN_TIME = COUNTDOWN_TIME - 180000;
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Pumping Liquid");

    for (int i = COUNTDOWN_TIME; i > 0; i--) {
      minutes = COUNTDOWN_TIME / 60;
      seconds = COUNTDOWN_TIME % 60;
      display.showNumberDecEx(minutes * 100 + seconds, 0b01000000, true);
      COUNTDOWN_TIME -- ;
      lcd.setCursor(0, 1);
      lcd.print("   ");
      lcd.setCursor(0, 1);
      lcd.print(i);
      tone(buzzer,523);
      digitalWrite(pump, 0); 
      delay(500);
      noTone(buzzer);
      digitalWrite(pump, 1); 
      delay(500);
    }

    pulse = 0;
    display.showNumberDecEx(0000, 0b01000000, true);
    noCoin = false;
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(" Thank You Bye!");
    delay(1700);
    tone(buzzer, 3000);
    delay(200);
    noTone(buzzer);
    delay(50);
    tone(buzzer, 3000);
    delay(50);
    noTone(buzzer);
    display.clear();


  }


  coinSlotStatus = digitalRead(coinSlot);
  delay(30);
  if (coinSlotStatus == 0) {
    userBalance = true;
    lcd.setCursor(0, 0);
    lcd.print("Press a Button");
    pulse += 1;
    COUNTDOWN_TIME=15*pulse;
    lcd.setCursor(0, 1);
    sprintf(lcdBuffer, "Bal. Php %d.00", pulse);
    lcd.setCursor(0, 1);
    lcd.print(lcdBuffer);
    delay(30);
  }
  noTone(buzzer);
 
}

why the heater pin is in pin no 6

heater is assigned to pin D5. you can change it if you want to.

it running but the pump is like on off on off where i edit that case

how long should the motor run?
you have said the heater should turn off after 3 min, then what you want to do in remaining 2 min

the remaining 2mins is for UV light is turn on and for 5-10 sec the pump will pump the fog then after

after 10 sec you want the pump to completely off for 2 min?

yes the the UV light is turn it onto consume the 2mins

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);


#define buzzer 13
#define button 4
#define heater 5
#define coinSlot 6
#define uv 7
#define pump 8
int coinSlotStatus;
int pulse;

bool userBalance = false;
bool noCoin = false;

char lcdBuffer[16];

int buttonState;

#define interval 1000
#define CLK 2  // pin D2 - CLK 
#define DIO 3 // pin D3 - DIO
#include <Arduino.h>
#include <TM1637Display.h>
int COUNTDOWN_TIME =0; //  in seconds
int minutes = 0;
int seconds = 0;
TM1637Display display(CLK, DIO);

void setup() {
  display.setBrightness(3); // set brightness of tm1637, 0 (lowest brightness) to 7 (highest brightness)
  lcd.init();
  lcd.backlight();
  lcd.clear();
  pinMode(buzzer, OUTPUT);
  pinMode(10, OUTPUT);
  digitalWrite(10, LOW);
  pinMode(coinSlot, INPUT_PULLUP);
  pinMode(button, INPUT);
  pinMode(heater, OUTPUT);
  pinMode(pump, OUTPUT);
  digitalWrite(heater, 1); // turn off heater relay 
  digitalWrite(pump, 1); // turn off pump relay 
  digitalWrite(uv, 1); // turn off uv relay 

  tone(buzzer, 262);
  delay(150);
  tone(buzzer, 294);
  delay(150);
  tone(buzzer, 330);
  delay(150);
  tone(buzzer, 349);
  delay(150);
  tone(buzzer, 392);
  delay(150);
  tone(buzzer, 440);
  delay(150);
  tone(buzzer, 394);
  delay(150);
  tone(buzzer, 563);
  delay(150);
  noTone(buzzer);
  delay(1000);
}

void loop() {
  if (noCoin == false) {
    noCoin = true;
    lcd.setCursor(0, 0);
    lcd.print(" Insert Coin");
  }


  buttonState = digitalRead(button);

  if (pulse==20 && buttonState == 1 && COUNTDOWN_TIME > 0 && userBalance) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("WARMING UP");
    digitalWrite(heater, 0);
    delay(180000); 
    digitalWrite(heater, 1);
    

    
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Pumping Liquid");
    digitalWrite(pump, 0); 
    delay (10000);  // 10 sec
    digitalWrite(pump, 1); 
    COUNTDOWN_TIME = COUNTDOWN_TIME - 180000;
    for (int i = COUNTDOWN_TIME; i > 0; i--) {
      minutes = COUNTDOWN_TIME / 60;
      seconds = COUNTDOWN_TIME % 60;
      display.showNumberDecEx(minutes * 100 + seconds, 0b01000000, true);
      COUNTDOWN_TIME -- ;
      lcd.setCursor(0, 1);
      lcd.print("   ");
      lcd.setCursor(0, 1);
      lcd.print(i);
      tone(buzzer,523);
      digitalWrite(uv, 0); 
      delay(500);
      noTone(buzzer);
      delay(500);
    }
    digitalWrite(uv, 1); 
    pulse = 0;
    display.showNumberDecEx(0000, 0b01000000, true);
    noCoin = false;
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(" Thank You Bye!");
    delay(1700);
    tone(buzzer, 3000);
    delay(200);
    noTone(buzzer);
    delay(50);
    tone(buzzer, 3000);
    delay(50);
    noTone(buzzer);
    display.clear();


  }


  coinSlotStatus = digitalRead(coinSlot);
  delay(30);
  if (coinSlotStatus == 0) {
    userBalance = true;
    lcd.setCursor(0, 0);
    lcd.print("Press a Button");
    pulse += 1;
    COUNTDOWN_TIME=15*pulse;
    lcd.setCursor(0, 1);
    sprintf(lcdBuffer, "Bal. Php %d.00", pulse);
    lcd.setCursor(0, 1);
    lcd.print(lcdBuffer);
    delay(30);
  }
  noTone(buzzer);
 
}