If ( current date && day value)

Hi Friends,

i have an arduino Uno connected with a Real time Clock. i am getting the current date ( actually i am interested only for the day of the week)

No i have 7 variables as

int Sunday; int Monday; . . . int Saturday

Now, i want to write a code to activate the Pin 10 if the currect day is Sunday and the sunday variable is 1

if the currect day is monday and the monday variable is 0 to not actiuvate it

i wrote that code

if (Sun == 1 && read_day == 1) {
    digitalWrite(Zone1, HIGH);
  }else {
   digitalWrite(Zone1, LOW);
  }
  if (Mon == 1 && read_day == 2) {
    digitalWrite(Zone1, HIGH);
    Serial.println("Send '1' to turn LED on");
  } else {
    digitalWrite(Zone1, LOW);
    Serial.println("Send '2' to turn LED oFF");
 }
  if (Tue == 1 && read_day == 3) {
    digitalWrite(Zone1, HIGH);
  } else {
   digitalWrite(Zone1, LOW);
 }
  if (Wed == 1 && read_day == 4) {
    digitalWrite(Zone1, HIGH);
  } else {
    digitalWrite(Zone1, LOW);
  }
  if (Thu == 1 && read_day == 5) {
    digitalWrite(Zone1, HIGH);
  } else {
    digitalWrite(Zone1, LOW);
  }
  if (Fri == 1 && read_day == 6) {
    digitalWrite(Zone1, HIGH);
  } else {
    digitalWrite(Zone1, LOW);
 }
  if (Sat == 1 && read_day == 7) {
    digitalWrite(Zone1, HIGH);
  } else {
   digitalWrite(Zone1, LOW);
  }

the problem is that if the currect day is Monday and the Monday variable is 1 it activate the Pin but then deactivate it ( switch to LOW) since the next if is LOW

how can i do that ????

thanks Lazaros

if (Mon == 1 && read_day == 2)"Monday" does not equal "Mon".

Post ALL your code.

Here is my code

//=========  code for Bluetooth ========


#include <SoftwareSerial.h>
SoftwareSerial BTSerial(2, 3);



int duration1;
int duration2;
int duration3;



char BluetoothData;

//zone 1

int Sun;
int Mon;
int Tue;
int Wed;
int Thu;
int Fri;
int Sat;

//zone 2


int Sun2;
int Mon2;
int Tue2;
int Wed2;
int Thu2;
int Fri2;
int Sat2;

//zone 3


int Sun3;
int Mon3;
int Tue3;
int Wed3;
int Thu3;
int Fri3;
int Sat3;




//=========code for RTC==============

#include "Wire.h"
#include <LiquidCrystal.h>
#define DS1307_ADDRESS 0x68
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

byte read_second;
byte read_minute;
byte read_hour;
byte read_day;
byte read_date;
byte read_month;
byte read_year;

byte bcd_to_Dec(byte val)
{
  return ( (val / 16 * 10) + (val % 16) );
}

byte dec_to_bcd(byte val)
{
  return ( (val / 10 * 16) + (val % 10) );
}


//=========COMMON========

const int Zone1 = 13;
const int Zone2 = 11;
const int Zone3 = 12;





void setup() {

  //=========CODE FOR BT===============

  // initialize serial communications at 9600 bps:
  Wire.begin();
  Serial.begin(9600);
  BTSerial.begin(9600);
  lcd.begin(16, 2);
  lcd.clear();


  pinMode(Zone1, OUTPUT);
  pinMode(Zone2, OUTPUT);
  pinMode(Zone3, OUTPUT);


}



void loop() {


  //==========CODE FOR RTC===================

  Wire.beginTransmission(DS1307_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS1307_ADDRESS, 7);
  read_second = bcd_to_Dec(Wire.read());
  read_minute = bcd_to_Dec(Wire.read());
  read_hour = bcd_to_Dec(Wire.read());
  read_day = bcd_to_Dec(Wire.read());
  read_date = bcd_to_Dec(Wire.read());
  read_month = bcd_to_Dec(Wire.read());
  read_year = bcd_to_Dec(Wire.read());

  lcd.clear();
  Serial.println();

  lcd.setCursor(0, 0);
  if (read_hour < 10)
  {
    lcd.print("0");
    Serial.print ("0");
  }
  lcd.print(read_hour);
  Serial.print (read_hour);
  lcd.print(":");
  Serial.print(":");

  if (read_minute < 10)
  {
    lcd.print("0");
    Serial.print ("0");
  }
  lcd.print(read_minute);
  Serial.print (read_minute);
  lcd.print(":");
  Serial.print(":");


  if (read_second < 10)
  {
    lcd.print("0");
    Serial.print ("0");
  }
  lcd.print(read_second);
  Serial.print (read_second);
  Serial.println();

  if (  read_day == 1)
  {
    lcd.print("Sun");
    Serial.print ("Sun");
  }
  if (  read_day == 2)
  {
    lcd.print("Mon");
    Serial.print ("Mon");
  }

  if (  read_day == 3)
  {
    lcd.print("Tue");
    Serial.print ("Tue");

  }

  if (  read_day == 4)
  {
    lcd.print("Wed");
    Serial.print ("Wed");
  }
  if (  read_day == 5)
  {
    lcd.print("Thu");
    Serial.print ("Thu");
  }

  if (  read_day == 6)
  {
    lcd.print("Fri");
    Serial.print ("Fri");
  }

  if (  read_day == 7)
  {
    lcd.print("Sat");
    Serial.print ("Sat");

  }

  Serial.println();
  lcd.setCursor(0, 1);
  lcd.print(read_date);
  Serial.print (read_date);
  lcd.print("/");
  Serial.print("/");
  lcd.print(read_month);
  Serial.print (read_month);
  lcd.print("/");
  Serial.print("/");
  lcd.print(read_year);
  Serial.print (read_year);


  //================CODE FOR BT============



  if (BTSerial.available()) {
    BluetoothData = BTSerial.read(); //Get next character from bluetooth

    //-----------activate days

    //    ZONE 1

    if (BluetoothData == 'A') {
      Sun = 1;
    }
    if (BluetoothData == 'B') {
      Mon = 1;
    }
    if (BluetoothData == 'C') {
      Tue = 1;
    }
    if (BluetoothData == 'D') {
      Wed = 1;
    }
    if (BluetoothData == 'E') {
      Thu = 1;
    }
    if (BluetoothData == 'F') {
      Fri = 1;
    }
    if (BluetoothData == 'G') {
      Sat = 1;
    }

    // -------------  De activate days

    if (BluetoothData == 'a') {
      Sun = 0;
    }
    if (BluetoothData == 'b') {
      Mon = 0;
    }
    if (BluetoothData == 'c') {
      Tue = 0;
    }
    if (BluetoothData == 'd') {
      Wed = 0;
    }
    if (BluetoothData == 'e') {
      Thu = 0;
    }
    if (BluetoothData == 'f') {
      Fri = 0;
    }
    if (BluetoothData == 'g') {
      Sat = 0;
    }



    //    ZONE 2

    if (BluetoothData == 'H') {
      Sun2 = 1;
    }
    if (BluetoothData == 'I') {
      Mon2 = 1;
    }
    if (BluetoothData == 'J') {
      Tue2 = 1;
    }
    if (BluetoothData == 'K') {
      Wed2 = 1;
    }
    if (BluetoothData == 'L') {
      Thu2 = 1;
    }
    if (BluetoothData == 'M') {
      Fri2 = 1;
    }
    if (BluetoothData == 'N') {
      Sat2 = 1;
    }

    // -------------  De activate days

    if (BluetoothData == 'h') {
      Sun2 = 0;
    }
    if (BluetoothData == 'i') {
      Mon2 = 0;
    }
    if (BluetoothData == 'j') {
      Tue2 = 0;
    }
    if (BluetoothData == 'k') {
      Wed2 = 0;
    }
    if (BluetoothData == 'l') {
      Thu2 = 0;
    }
    if (BluetoothData == 'm') {
      Fri2 = 0;
    }
    if (BluetoothData == 'n') {
      Sat2 = 0;
    }



    //    ZONE 3

    if (BluetoothData == 'O') {
      Sun3 = 1;
    }
    if (BluetoothData == 'P') {
      Mon3 = 1;
    }
    if (BluetoothData == 'Q') {
      Tue3 = 1;
    }
    if (BluetoothData == 'R') {
      Wed3 = 1;
    }
    if (BluetoothData == 'S') {
      Thu3 = 1;
    }
    if (BluetoothData == 'T') {
      Fri3 = 1;
    }
    if (BluetoothData == 'U') {
      Sat3 = 1;
    }

    // -------------  De activate days

    if (BluetoothData == 'o') {
      Sun3 = 0;
    }
    if (BluetoothData == 'p') {
      Mon3 = 0;
    }
    if (BluetoothData == 'q') {
      Tue3 = 0;
    }
    if (BluetoothData == 'r') {
      Wed3 = 0;
    }
    if (BluetoothData == 's') {
      Thu3 = 0;
    }
    if (BluetoothData == 't') {
      Fri3 = 0;
    }
    if (BluetoothData == 'u') {
      Sat3 = 0;
    }

    //=======================================Duration


    if (BluetoothData == 'V')  {
      int dura1 = BTSerial.parseInt();
      duration1 = dura1 ;
    }


    if (BluetoothData == 'W')  {
      int dura2 = BTSerial.parseInt();
      duration2 = dura2 ;
    }

    if (BluetoothData == 'X')  {
      int dura3 = BTSerial.parseInt();
      duration3 = dura3 ;
    }






    if (BluetoothData == '?')
    {
      Serial.println("Send '1' to turn LED on");
      Serial.println("Send '2' to turn LED on");


    }
  }


  float Vsi = analogRead(0);   // read the sensor voltage
  BTSerial.println("*T" + String(Vsi) + "*");
  Serial.println(Vsi);




  if (read_day == 1){
    if(Sun == 1) {
    digitalWrite(Zone1, HIGH);
  } else {
    digitalWrite(Zone1, LOW);
  }
  if (Mon == 1 && read_day == 2) {
    digitalWrite(Zone1, HIGH);
    Serial.println("Send '1' to turn LED on");
  }// else {
   // digitalWrite(Zone1, LOW);
    Serial.println("Send '2' to turn LED oFF");
//  }
  if (Tue == 1 && read_day == 3) {
    digitalWrite(Zone1, HIGH);
  }// else {
   // digitalWrite(Zone1, LOW);
 // }
  if (Wed == 1 && read_day == 4) {
    digitalWrite(Zone1, HIGH);
  } //else {
   // digitalWrite(Zone1, LOW);
 // }
  if (Thu == 1 && read_day == 5) {
    digitalWrite(Zone1, HIGH);
  } //else {
    //digitalWrite(Zone1, LOW);
 // }
  if (Fri == 1 && read_day == 6) {
    digitalWrite(Zone1, HIGH);
  } //else {
    //digitalWrite(Zone1, LOW);
 // }
  if (Sat == 1 && read_day == 7) {
    digitalWrite(Zone1, HIGH);
  }// else {
    //digitalWrite(Zone1, LOW);
 // }








  int ;
  int Mon;
  int Tue;
  int Wed;
  int Thu;
  int Fri;
  int Sat;


  //  { BTSerial.println("*S");
  //  }


  delay (1000);
}

tsiorak: the problem is that if the currect day is Monday and the Monday variable is 1 it activate the Pin but then deactivate it ( switch to LOW) since the next if is LOW

how can i do that ????

Sounds like you need to learn how to use "else if"

Use if / else if?

Do you think that i sould use the while option ?

or the if/else with multiple if ???

can you provide me a sample of code to understand it better?

thanks Lazaros

Well it isn't entirely clear to any of us how you want it to behave. But from your earlier description it sounds like putting an else in front of all the if statements but the first one would solve your problem. You're asking do we think you should use while or else if but those two things do completely different things. Which one is the right one depends on what you want to have happen. If you don't know the difference then you should learn it before you use either.