How to use exteral keys to change the variables inside a loop

Hai all.

Thanks for reading. Iam a learner and am using Arduino Uno Atmega328 for learning.

I’ve finished a hardware to switch ON and switch OFF my bed room lights and fans( a separate 30A relay to switch my A/C in a different phase) with realtime DS1307 and arduino uno module.
( all with the help of arduino forum)

as per my code the device works well no problem. I wanted to change the ON and OFF time with external push buttons which will really save me by removing the Atmega 328 from socket. This will also help me in enhancing coding knowledge.

i have attached my code for reference and i need all of your support to go further.

gsm_trial.ino (1.99 KB)

i need all of your support to go further.

What help do you need? Reading the state of a pin with a switch attached is easy.

Your code seems to be talking to a GSM module to send text messages. It has nothing to do with RTC or relays.

Iam sorry. I have attached a Ist part of my code. I am now attaching the full code.

I need to alter the time and alarms using external keys. pls help.

tks

sreenathan

gsm_with_RTC.ino (2.73 KB)

Iam sorry. I have attached a Ist part of my code. I am now attaching the full code.

I need to alter the time and alarms using external keys. Pin 6 is connected to a relay.

tks

sreenathan

The code:

#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
#include <Wire.h>
#include “RTClib.h”
RTC_DS1307 RTC;

#define ON_HOUR 6
#define OFF_HOUR 21
LiquidCrystal lcd(8,9,10,11,12,13);

SoftwareSerial mySerial(3,4); //RX and TX pins to communicate with GSM module

const int buttonPin = 7;
int buttonPinState;
int lastbuttonPinState;

String number =“9381062067”; // The Number to which message / call is to be made

void setup()
{
Serial.begin(9600);
mySerial.begin(9600);
Wire.begin();
lcd.begin(16, 2);
delay(500);
RTC.adjust(DateTime(DATE, TIME)); //uncomment this line to set time to system time
pinMode(buttonPin,INPUT);
digitalWrite(buttonPin, HIGH);
pinMode(6,OUTPUT);

}

void loop()
{
DateTime now = RTC.now();// Getting the current Time and storing it into a DateTime object

if(now.hour() >= ON_HOUR && now.hour()<= OFF_HOUR ) {
digitalWrite(6,HIGH);
}
else{
digitalWrite(6,LOW);
}

lcd.setCursor(0,0);

lcd.print(“ON 6AM”);
lcd.print("-");
lcd.print(“OFF 10PM”);
lcd.print("-");

lcd.setCursor(0,1);

lcd.print(now.hour());
lcd.print(":");
lcd.print(now.minute());
lcd.print(":");
lcd.print(now.second());

lastbuttonPinState = (buttonPinState);
buttonPinState = digitalRead(7);

// lcd.clear();
// lcd.setCursor(0, 0);
//lcd.print(inches);
//lcd.print("in,Paper Qty ");
// lcd.print(buttonPinState);
// lcd.setCursor(0,1);
// lcd.print(lastbuttonPinState);

//This part sends an sms everytime sms_key is pressed
if ((buttonPinState != lastbuttonPinState) && (buttonPinState == LOW))
{

mySerial.println(“AT+CMGF=1”); // Set the Mode as Text Mode
delay(150);
mySerial.println(“AT+CMGS=”+91"+number+"""); // Specify the Destination number in international format
delay(150);
mySerial.print(“Hello…! Power Switched Off”); // Enter the message and append the ldr value
delay(150);
mySerial.write((byte)0x1A); // End of message character 0x1A : Equivalent to Ctrl+z
delay(50);
mySerial.println();

}

//This section generates a call when call_key is pressed

else if ((buttonPinState != lastbuttonPinState) && (buttonPinState == HIGH))
{
mySerial.println(“AT+CMGF=1”); // Set the Mode as Text Mode
delay(150);
mySerial.println(“AT+CMGS=”+91"+number+"""); // Specify the Destination number in international format
delay(150);
mySerial.print(“Hello…! Power Switched ON”); // Enter the message and append the ldr value
delay(150);
mySerial.write((byte)0x1A); // End of message character 0x1A : Equivalent to Ctrl+z
delay(50);
mySerial.println();

}

delay(500);

}

if ((buttonPinState != lastbuttonPinState) && (buttonPinState == LOW))

You seem to know how to handle a button state. Now do it again. A second button. Only this time, instead of sending sms when it is pressed, set whatever timing variable you want changed in there.

You haven't been really clear about how you want this button to change things or what variable you want changed, so it's hard to help you any more than that. But it really looks like you've got it figured out for this other button. I guess I don't understand the problem.

Thanks for the information. The button_state checks a relay and the relay is switch ON at 6am and off at 10pm. both the occasion an SMS is sent to the particular mobile number.

Now if have to change the ON and Off hours, i need to use few external keys, I can declare the ON hour and OFF hour as a variable but how to configure the keys for these variables. How to enter into programming mode, how to exit from the programming mode,

Also every time the power fails the time will also change to the older value. So i need to adjust the present time through the external keys. Please give me an idea

Thanks

Sreenathan

if you planning to set

1)date time externally you can use DIP & multplxer ic combination. depend on status of binary output convert the value.
2) you use
http://www.dfrobot.com/wiki/index.php?title=Arduino_LCD_KeyPad_Shield_(SKU:_DFR0009)

do programming to choose your date & time. I have code but i cant share here. Just look menu creation program for arduino .

http://dimme.net/arduino-lcd-keypad-shield-clock-application/
example code is here.

Thank you very much. i will try and give you a feedback.

Regard,

Sreenathan