Automatically water, soap, hand sanitizer and hand dryer problem

hello i am newbie programmer arduino. i make project automatically water, soap, hand sanitizer and hand. I have made each of the functions but the problem is I am confused about combining these functions into one program that suits the conditions I want. Can anyone help me combine this code with state machine? thank you :grin:

conditions :

  • condition 1 = when visitors come, PIR is active and turn on 0001.mp3
  • condition 2 = detection of visitor body temperature display on LCD and turn on 0002.mp3 / 0003.mp3
  • condition 3 = activate the relay (can be turned on / off continuously until condition 4)
  • condition 4 = if the visitor is not detected it will return to condition 1

code :

PIR & DFPlayer

#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"

SoftwareSerial mySoftwareSerial(11,10); // RX, TX
DFRobotDFPlayerMini myDFPlayer;

int PIR = 35;

boolean isPlaying = false;

void setup() {
    pinMode(PIR, INPUT);      // PIR = Input
    digitalWrite(PIR, HIGH);

    mySoftwareSerial.begin(9600);
    Serial.begin(9600);

    delay(1000);

    Serial.println();
    Serial.println("DFPlayer Mini Demo");
    Serial.println("Initializing DFPlayer...");

    if (!myDFPlayer.begin(mySoftwareSerial)) {
        Serial.println("Unable to begin:");
        Serial.println("1.Please recheck the connection!");
        Serial.println("2.Please insert the SD card!");
        while (true);
    }
    Serial.println(F("DFPlayer Mini online."));
    myDFPlayer.setTimeOut(500);
    //----Set volume----
    myDFPlayer.volume(30); //Set volume value (0~30).


    //----Set different EQ----
    myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
    myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
    myDFPlayer.playMp3Folder(0); 
    isPlaying = true;
    Serial.println("Playing..");
}

void loop() {
  
    while (pengunjung < 1) {
    if (digitalRead(PIR) == HIGH) {
    Serial.println("Motion Detected");
    myDFPlayer.playMp3Folder(1);          // play 0001.mp3
    delay(5000);
    pengunjung++;
    
    }
    else {
    Serial.println("No Motion");
    delay(1000);
    }                                     // loop in while
  }
}

MLX and LCD

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

#define I2C_ADDR 0x27 //I2C adress, you should use the code to scan the adress first (0x27) here
#define BACKLIGHT_PIN 3 // Declaring LCD Pins
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
Adafruit_MLX90614 mlx = Adafruit_MLX90614();

void setup() {
  
// sensor_MLX activated

 delay(1000);
 lcd.clear();
 lcd.setCursor(3,0);
 lcd.print("Non-contact");
 
 lcd.setCursor(2,1);
 lcd.print("Suhu: ");
 lcd.print(mlx.readObjectTempC());
 lcd.print("C     ");
 delay(2000);

  while (pengunjung < 1) {
   if(mlx.readObjectTempC() <= 37 and (mlx.readObjectTempC() >= 27)){   // make range temeprature 27 to 37 = normal
    digitalWrite(laser, HIGH);  // laser on
    lcd.clear();
    lcd.setCursor(1,0);
    delay(500);
    lcd.print("Suhu Tubuh Anda"); 
    lcd.setCursor(5,1);
    lcd.print("Normal");
    delay(2000);
    pengunjung++;
    IR_on;}

    else if (mlx.readObjectTempC() >= 37){   // make temperature >37 = not normal
    digitalWrite(laser, HIGH);  // laser on
    lcd.clear();
    lcd.setCursor(1,0);
    delay(500);
    lcd.print("Suhu Tubuh Anda"); 
    lcd.setCursor(2,1);
    lcd.print("Tidak Normal");
    pengunjung++;
    delay(2000);}
    
    else if (mlx.readObjectTempC() <= 25){    // make if temperature = room temeperature show name device
    digitalWrite(laser, LOW); // laser off
    lcd.clear();
    lcd.setCursor(2,0);
    delay(500);
    lcd.print("auto WITEZER"); 
    lcd.setCursor(5,1);
    lcd.print("ONLINE");
    delay(2000);}
    }
}

}

IR & Pump

//Membuat variabel untuk LED
  int PUMP1 = 6;
  int PUMP2 = 7;
  int PUMP3 = 8;
  int HDRYER4 = 9;
 
// Membuat variabel untuk IR
  int IR1 = 25;
  int IR2 = 27;
  int IR3 = 29;
  int IR4 = 31;

void setup() {

Serial.begin(9600);

// Setting Sensor IR
  // make variable pin PUMP and HDRYER = output
  pinMode(PUMP1, OUTPUT);
  pinMode(PUMP2, OUTPUT);
  pinMode(PUMP3, OUTPUT);
  pinMode(HDRYER4, OUTPUT);
 
  // make variable pin IR = input
  pinMode(IR1, INPUT);
  pinMode(IR2, INPUT);
  pinMode(IR3, INPUT);
  pinMode(IR4, INPUT);
}

void loop() {
  
// variable statusBtn save value pin IR
  int statusIR1 = digitalRead(IR1);
  int statusIR2 = digitalRead(IR2);
  int statusIR3 = digitalRead(IR3);
  int statusIR4 = digitalRead(IR4);

// Code Sensor IR
  // When the push button is not pressed the value is HIGH
    
    if(statusIR1 == HIGH)
    {
      digitalWrite(PUMP1, LOW);
    } else {
      digitalWrite(PUMP1, HIGH);
    }
    if(statusIR2 == HIGH) {
      digitalWrite(PUMP2, LOW);
    } else{
      digitalWrite(PUMP2, HIGH);
    }
    if(statusIR3 == HIGH) {
      digitalWrite(PUMP3, LOW);
    } else {
      digitalWrite(PUMP3, HIGH);
    }
    if(statusIR4 == HIGH) {
      digitalWrite(HDRYER4, LOW);
    } else {
      digitalWrite(HDRYER4, HIGH);
    }
}

2 posts were merged into an existing topic: Automatically water, soap, hand sanitizer and hand dryer