Cod

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

// initialize the library instance

#include <LiquidCrystal.h>

#include <MD_DS1307.h>

#include <Wire.h>

#include <SharpIR.h>

#include <EEPROM.h>

GSM gsmAccess;

GSM_SMS sms;

#define trigPin 4

#define echoPin 5

void setup() {

// initialize serial communications and wait for port to open:

Serial.begin(9600);

while (!Serial) {

; // wait for serial port to connect. Needed for native USB port only

Serial.println("SMS Messages Sender");

// connection state

bool notConnected = true;

// Start GSM shield

// If your SIM has PIN, pass it as a parameter of begin() in quotes

while (notConnected) {
if (gsmAccess.begin("0000") == GSM_READY) {

notConnected = false;

} else {

Serial.println("Not connected");

delay(1000);

Serial.println("GSM initialized");

Serial.begin (9600);

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

// initialize the digital pin as an output.

// Pin 13 has an builtin LED connected on most Arduino boards:

pinMode(13, OUTPUT);

//Pin A1 is connected to the output of IR sensor

pinMode(IRSensor,INPUT);

const int IRSensor=A1;

void loop() {

if(digitalRead(IRSensor)==HIGH) //Check the sensor output

{
Serial.print("0746806424 ");

char remoteNum[20]; // telephone number to send sms

readSerial(remoteNum);

Serial.println(remoteNum);

// sms text

Serial.print("Este ora 8, trebuie sa-ti iei pastila");

char txtMsg[200];

readSerial(txtMsg);

Serial.println("SENDING");

Serial.println();

Serial.println("Message:");

Serial.println(txtMsg);

// send the message

sms.beginSMS(remoteNum);

sms.print(txtMsg);

sms.endSMS();

Serial.println("\nCOMPLETE!\n");

delay(10000);

/*

Read input serial

*/

int readSerial(char result[]) {

int i = 0;

while (1) {

while (Serial.available() > 0) {

char inChar = Serial.read();

if (inChar == '\n') {
result[i] = '\0';

Serial.flush();

return 0;

if (inChar != '\r') {

result[i] = inChar;

i++;

else

if(digitalRead(IRSensor)==HIGH)

Serial.print("0746806424 ");

char remoteNum[20]; // telephone number to send sms

readSerial(remoteNum);

Serial.println(remoteNum);

// sms text

Serial.print("Iti amintesc ca trebuie sa-ti iei pastila de la ora 8");

char txtMsg[200];

readSerial(txtMsg);

Serial.println("SENDING");

Serial.println();

Serial.println("Message:");

Serial.println(txtMsg);
// send the message

sms.beginSMS(remoteNum);

sms.print(txtMsg);

sms.endSMS();

Serial.println("\nCOMPLETE!\n");

delay(10000);

/*

Read input serial

*/

int readSerial(char result[]) {

int i = 0;

while (1) {

while (Serial.available() > 0) {

char inChar = Serial.read();

if (inChar == '\n') {

result[i] = '\0';

Serial.flush();

return 0;

if (inChar != '\r') {

result[i] = inChar;

i++;

else
if(digitalRead(IRSensor)==HIGH)

Serial.print("0759625348");

char remoteNum[20]; // telephone number to send sms

readSerial(remoteNum);

Serial.println(remoteNum);

// sms text

Serial.print("Pacientul X nu si-a luat pastila");

char txtMsg[200];

readSerial(txtMsg);

Serial.println("SENDING");

Serial.println();

Serial.println("Message:");

Serial.println(txtMsg);

// send the message

sms.beginSMS(remoteNum);

sms.print(txtMsg);

sms.endSMS();

Serial.println("\nCOMPLETE!\n");

delay(10000);

/*

Read input serial

*/

int readSerial(char result[]) {

int i = 0;

while (1) {
while (Serial.available() > 0) {

char inChar = Serial.read();

if (inChar == '\n') {

result[i] = '\0';

Serial.flush();

return 0;

if (inChar != '\r') {

result[i] = inChar;

i++;

else

if(digitalRead(IRSensor)==LOW)

Serial.println("Pastila de la ora 8 luata");

void loop()

{ long duration, distance;


digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance = (duration/2) / 29.1;

if (distance < 10)

Serial.println("Pastila de la ora 20:00 luata");

else {

if(distance>=10)

{Serial.print("0746806424");

char remoteNum[20]; // telephone number to send sms

readSerial(remoteNum);

Serial.println(remoteNum);
// sms text

Serial.print("Este ora 20:00, trebuie sa-ti iei pastila");

char txtMsg[200];

readSerial(txtMsg);

Serial.println("SENDING");

Serial.println();

Serial.println("Message:");

Serial.println(txtMsg);

// send the message

sms.beginSMS(remoteNum);

sms.print(txtMsg);

sms.endSMS();

Serial.println("\nCOMPLETE!\n");

delay(10000);

/*

Read input serial

*/

int readSerial(char result[]) {

int i = 0;

while (1) {

while (Serial.available() > 0) {

char inChar = Serial.read();

if (inChar == '\n') {

result[i] = '\0';

Serial.flush();

return 0;

}
}

else

if(distance>=10)

{Serial.print("0746806424");

char remoteNum[20]; // telephone number to send sms

readSerial(remoteNum);

Serial.println(remoteNum);

// sms text

Serial.print("Iti amintesc ca trebuie sa-ti iei pastila de la ora 20:00");

char txtMsg[200];

readSerial(txtMsg);

Serial.println("SENDING");

Serial.println();

Serial.println("Message:");

Serial.println(txtMsg);

// send the message

sms.beginSMS(remoteNum);

sms.print(txtMsg);

sms.endSMS();

Serial.println("\nCOMPLETE!\n");

delay(10000);

/*

Read input serial

*/

int readSerial(char result[]) {

int i = 0;
while (1) {

while (Serial.available() > 0) {

char inChar = Serial.read();

if (inChar == '\n') {

result[i] = '\0';

Serial.flush();

return 0;

else

if(distance>=10)

{Serial.print("0759625348");

char remoteNum[20]; // telephone number to send sms

readSerial(remoteNum);

Serial.println(remoteNum);

// sms text

Serial.print("Pacientul X nu si-a luat pastila");

char txtMsg[200];

readSerial(txtMsg);

Serial.println("SENDING");

Serial.println();

Serial.println("Message:");

Serial.println(txtMsg);

// send the message


sms.beginSMS(remoteNum);

sms.print(txtMsg);

sms.endSMS();

Serial.println("\nCOMPLETE!\n");

delay(10000);

/*

Read input serial

*/

int readSerial(char result[]) {

int i = 0;

while (1) {

while (Serial.available() > 0) {

char inChar = Serial.read();

if (inChar == '\n') {

result[i] = '\0';

Serial.flush();

return 0;

delay(500);

You might also like