You are on page 1of 18

B.

PROJECT DESIGN

Figure 4.6 Gizduino Model Arrangements


Figure 4.6 Guizdino Board Arrangements from softwares tutorial pdf
Figure 4.7 GSM Board Arrangements from softwares tutorial

pdf
Figure 2.6 Schematic Diagram from softwares tutorial pdf
A. C-Language Programs of Gizduino Model in Arduino Software

#include <SoftwareSerial.h>

#include <EEPROM.h>

SoftwareSerial XTPORT(2, 3); // RX, TX

#include <LiquidCrystal.h>

LiquidCrystal lcd(13,12,11,10,9,8);

String inputString = "";

int vtime ;

int val;

int mloc;

String sloc = "00";

int addr = 0;

int Ltime ;

int simloc;

int senc= 1;

int bloc;

int dtime = 5000;

char inChar;

int Status = 0;

boolean stringComplete = false;

String simnum[4];

String simpass = "";

int i1 ;
int SIMC;

int lights = A5;

const int analogInPin = A0;

int sensorValue = 0;

long sensordelay = 0;

long lcddelay = 0;

int buton[] ={A1,A2,A3,A4};

int limit = 50;

boolean readb[4];

int readbi = 0;

String numb;

//////////////////////////////////////////////////////////////////////////////////

void setup()

pinMode(lights, OUTPUT);

for (int i = 0; i < 4; i++) {

pinMode(buton[i], INPUT);

XTPORT.begin(2400);

Serial.begin(2400);

while (!Serial) {

lcd.begin(16, 2);
lcd.print(" LDR-CONTROLLED");

lcd.setCursor(0, 1);

lcd.print(" STREETLIGHTS");

delay(1000);

//EEPROM.write(200, limit);

limit = (EEPROM.read(200));

//camera setup

delay(1000);

simnum[3] = "0000000000";

//simnum[5] = "0000000000";

for (int i = 5; i < 20; i++) {

XTPORT.write("AT+CMGD="); /////// DELETE SMS

XTPORT.print(i);

lcd.scrollDisplayLeft();

XTPORT.write(char(13));

delay(1000);

//Serial.println(millis());

XTPORT.write(char(26));

XTPORT.write("AT");

XTPORT.write(char(13));
XTPORT.write("AT+CMGF=1");

XTPORT.write(char(13));

inputString = "0123";

Serial.println(inputString);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

void loop() // run over and over

s:

GSMEVENT();

sensorsM();

if ((millis() - lcddelay) > 1000) {

sensorsA();

lcddelay = millis();

if ((millis() - sensordelay) > 10000) {

sensordelay = 0;

doTask();

sensordelay ++;

if (stringComplete == true ) {

stringComplete = false;
if (inputString.indexOf("+CNUM: ") > 0 ) {

inputString = "";

//Serial.println(" DUMMY GSM ALERT ");

XTPORT.write("AT+CMGR=7");

XTPORT.write(char(13));

else if (inputString.indexOf("+CMTI: ") > 0 ) {

i1 = inputString.indexOf("+CMTI: ");

sloc = inputString.substring(i1 + 12, i1 + 14);

Serial.println(sloc);

inputString = "";

XTPORT.write("AT+CMGR=");

XTPORT.print(sloc);

XTPORT.write(char(13));

else if (inputString.indexOf(">") > 0 ) {

//Serial.println(" GSM ALERT ");

inputString = "";

delay(2000);

else if (inputString.indexOf("+CMGR:") > 0 ) { ///"+CMTI: "

int num = inputString.indexOf("+639");

numb = inputString.substring(num + 3 , num +


13);
if((inputString.indexOf("SLIGHTS STATUS") >
50 ) ){

sendingmsm();

XTPORT.print("the streetlights are ");

if (buflights == HIGH){

XTPORT.print("on");

else {

XTPORT.print("off");

XTPORT.print(" with the limit of ");

XTPORT.print(limit);

XTPORT.print(". The sensor value is now


at ");

XTPORT.print(sensorValue);

if (sauto == true){

XTPORT.print("on");

else {

XTPORT.print("off");

boolean buflights = digitalRead(lights);

sendingmsmend();

}
else if(inputString.indexOf("RLIMIT ") > 50 ) {

//Serial.println("[CHANGE
NUMB]\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ");

i1 = inputString.indexOf("LIMIT ");

limit = (inputString.substring(i1 + 6, i1 +
9)).toInt();

//Serial.println("inputString.substring");

//Serial.println(inputString.substring(i1 + 6,
i1 + 9));

EEPROM.write(200, limit);

sensorsA();

sendingmsm();

XTPORT.print("Limit Set = ");

XTPORT.print(limit);

sendingmsmend();

else if(inputString.indexOf("SLIGHTS AUTO ")


> 50 ) {

sauto = true;

}//*/

else if((inputString.indexOf("SLIGHTS ON") >


50 )){

//Serial.println("on");

digitalWrite(lights, HIGH);

sendingmsm();

XTPORT.print("The streetlights are o");

sendingmsmend();
sensordelay = (millis()+ 20000);

else if((inputString.indexOf("SLIGHTS OFF") >


50 )){

//Serial.println("off");

digitalWrite(lights, LOW);

//inputString = ("LOCK Successfully");

sendingmsm();

XTPORT.print("The streetlights are off");

sendingmsmend();

sensordelay = (millis()+ 20000);

Serial.println("T D");

inputString ="5";

XTPORT.write("AT+CMGD="); /////// DELETE SMS

XTPORT.print(sloc);

XTPORT.write(char(13));

/////////////////////////// else if (inputStr Of("+CMGR:") > 0 )

else if (inputString.indexOf("OK") > 0) {

Status = 1;

//Serial.println(" GSM CONNECTED ");

Serial.println("OK");

//digitalWrite(GSM, HIGH);
inputString = "";

else if ((inputString.indexOf("AT") > 0 ) && (inputString.indexOf("OK") >


0)){

Status = 1;

//digitalWrite(GSM, HIGH);

Serial.println("OK2");

inputString = "";

else {

Status = 0;

//digitalWrite(GSM, LOW);

Serial.println("N");

inputString = "";

vtime = millis();

//*/

//digitalWrite(Acti, LOW);

void sensorsA(){

sensorValue = analogRead(analogInPin);

sensorValue = map(sensorValue, 0, 1023, 0, 100);

//Serial.print("sensorValue =");

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

lcd.setCursor(0, 0);

lcd.print("SENSOR VAL ");

lcd.print(sensorValue);

lcd.setCursor(0, 1);

lcd.print("LIMIT ");

lcd.print(limit);

void doTask(){

sensorsA();

if (sensorValue > limit + 5){

digitalWrite(lights, LOW);

Serial.println("off");

if (sensorValue < (limit)){

digitalWrite(lights, HIGH);

Serial.println("on");

void sendingmsmend(){

inputString = "";

long dly = millis();

XTPORT.write(char(26));

delay(500);
XTPORT.write(char(26));

void reads(){

for (int i = 0; i < 4; i++) {

readb[i] = digitalRead(buton[i]);

void sensorsM(){

int prelimit = limit ;

reads();

if (readb[0] == LOW){

lcd.clear();

Serial.print("1");

while(readb[0] == LOW){

delay(700);

Serial.print("2");

reads();

Serial.print("3");

while((readb[0] == HIGH)&&(readb[1] == HIGH)){

sensorValue = analogRead(analogInPin);

sensorValue = map(sensorValue, 0, 1023, 0, 100);


if (readb[2] == LOW){

if (limit > 0){limit--; }

else if (readb[3] == LOW){

if (limit < 100){limit++; }

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("SENSOR VAL ");

lcd.print(sensorValue);

lcd.setCursor(0, 1);

lcd.print("CHANGE ");

lcd.print(limit);

delay(200);

sensorsA();

reads();

if (readb[0] == LOW){

EEPROM.write(200, limit);

lcd.clear();

lcd.setCursor(0, 0);

lcd.print(" SETTING");

lcd.setCursor(0, 1);
lcd.print(" SAVE ");

else if (readb[1] == LOW){

limit = prelimit;

lcd.clear();

lcd.setCursor(0, 0);

lcd.print(" SETTING ");

lcd.setCursor(0, 1);

lcd.print(" CANCEL ");

while((readb[0] == LOW)||(readb[1] == LOW)){

delay(1000);

reads();

sensorsA();

///////////////////////////////////////////////////////////////////////////////////////////////////////////

void GSMEVENT(){

XTPORT.listen();

if (XTPORT.available()) {

while(XTPORT.available()) {

inChar = (char)XTPORT.read();

inputString += inChar;

}
if (inChar == char(10)) {

stringComplete = true;

void sendingmsm(){

XTPORT.write("AT+CMGS=");

XTPORT.write(char(34));

XTPORT.write(char(48));

XTPORT.print(numb);

XTPORT.write(char(34));

XTPORT.write(char(13));

delay(500);

You might also like