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);
}