help with my code

i used the code below and it did not work well after uploading. is there something i should do before uploading? and is the code ok.

#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
SoftwareSerial mySerial(9, 10);

int sensor=7;
int pirsensor=8;
int tempsensor=A1;
int speaker=0;
int push_switch=6;
int gas_value,Gas_alert_val, Gas_shut_val;
int Gas_Leak_Status;
float temp_read,Temp_alert_val,Temp_shut_val;
int sensor_value; //variable to hold read sensor value
int Motion_Scan_Status;
int gassms_count=0;
int firesms_count=0;
int pirsms_count=0;
int Fire_Set;

void setup()
{

pinMode(sensor,INPUT);
pinMode(pirsensor,INPUT);
pinMode(push_switch,INPUT);
pinMode(tempsensor,INPUT);
pinMode(speaker,OUTPUT);
mySerial.begin(9600);
Serial.begin(9600);
lcd.begin(20,4);
delay(500);

}

void loop()
{
CheckGas();
CheckShutDown();
CheckFire();
CheckFireShutDown();
Check_Burglar();// subroutine to check sensor status and activation of outputs
Check_Reset();
}

void CheckGas()
{

lcd.setCursor(0,0);
lcd.print(“Gas Scan - ON”);
Gas_alert_val=ScanGasLevel();
if(Gas_alert_val==LOW)
{
SetAlert(); // Function to send SMS Alerts
}}

int ScanGasLevel()
{
gas_value=digitalRead(sensor); // reads the sensor output (Vout of LM35)

return gas_value; // returns temperature value in degree celsius
}

void CheckFire()
{
lcd.setCursor(0,1);
lcd.print(“Fire Scan - ON”);
Temp_alert_val=CheckTemp();
if(Temp_alert_val>45)
{
SetFireAlert(); // Function to send SMS Alerts
}
}

float CheckTemp()
{
temp_read=analogRead(tempsensor); // reads the sensor output (Vout of LM35)
temp_read=temp_read*5; // converts the sensor reading to temperature
temp_read=temp_read/10; // adds the decimal point
return temp_read; // returns temperature value in degree celsius
}

void Check_Burglar()
{
lcd.setCursor(0,2);
lcd.print(“Motion Scan - ON”);
sensor_value=digitalRead(pirsensor); // Reading sensor value from pin 7
if(sensor_value==HIGH) // Checking if PIR sensor sends a HIGH signal to Arduino
{
SetMotionAlert();
}
}

void SetMotionAlert()
{
digitalWrite(speaker,HIGH); // Activating the buzzer
while(pirsms_count<1) //Number of SMS Alerts to be sent limited at 3
{
SendMotionTextMessage(); // Function to send AT Commands to GSM module
}
Motion_Scan_Status=1;
lcd.setCursor(0,3);
lcd.clear();
lcd.print(“Intrusion Alert! SMS Sent!”);
delay(1000);
}

void SetAlert()
{
digitalWrite(speaker,HIGH);
while(gassms_count<1) //Number of SMS Alerts to be sent
{
SendTextMessage(); // Function to send AT Commands to GSM module
}
Gas_Leak_Status=1;
lcd.setCursor(0,3);
lcd.clear();
lcd.print(“Gas Alert! SMS Sent!”);
delay(1000);
}
void SetFireAlert()
{
digitalWrite(speaker,HIGH);
while(firesms_count<1) //Number of SMS Alerts to be sent
{
SendFireTextMessage(); // Function to send AT Commands to GSM module
}
Fire_Set=1;
lcd.setCursor(0,3);
lcd.clear();
lcd.print(“Fire Alert! SMS Sent!”);
delay(1000);
}

void CheckShutDown()
{
if(Gas_Leak_Status==1)
{

Gas_shut_val=ScanGasLevel();
if(Gas_shut_val==HIGH)
{

lcd.setCursor(0,3);
lcd.print(“No Gas Leaking”);
digitalWrite(speaker,LOW);
gassms_count=0;
Gas_Leak_Status=0;
}}}

void CheckFireShutDown()
{
if(Fire_Set==1)
{

Temp_shut_val=CheckTemp();
if(Temp_shut_val<28)
{
lcd.setCursor(0,3);
lcd.print(“Fire Shut! SAFE NOW”);
digitalWrite(speaker,LOW);
firesms_count=0;
Fire_Set=0;
}}}

void Check_Reset()
{
if(digitalRead(push_switch==HIGH))// Checking if pushbutton was pressed
{
lcd.setCursor(0,3);
lcd.print(“No Motion Detected”);
digitalWrite(speaker,LOW); // turning OFF the buzzer
pirsms_count=0; // Reactivating the SMS Alert Facility
Motion_Scan_Status=0;
}}

void SendTextMessage()
{
mySerial.println(“AT+CMGF=1”); //To send SMS in Text Mode
delay(1000);
mySerial.println(“AT+CMGS=”+2348097701968"\r"); // change to the phone number you using
delay(1000);
mySerial.println(“Gas Leaking!”);//the content of the message
delay(200);
mySerial.println((char)26);//the stopping character
delay(1000);
mySerial.println(“AT+CMGS=”+2348110188925"\r"); // change to the phone number you using
delay(1000);
mySerial.println(“Gas Leaking!”);//the content of the message
delay(200);
mySerial.println((char)26);//the message stopping character
delay(1000);
gassms_count++;
}

void SendFireTextMessage()
{
mySerial.println(“AT+CMGF=1”); //To send SMS in Text Mode
delay(1000);
mySerial.println(“AT+CMGS=”+2348097701968"\r"); // change to the phone number you using
delay(1000);
mySerial.println(“Fire in THE ROOM!”);//the content of the message
delay(200);
mySerial.println((char)26);//the stopping character
delay(1000);
mySerial.println(“AT+CMGS=”+2348110188925"\r"); // change to the phone number you using
delay(1000);
mySerial.println(“Fire in THE ROOM!”);//the content of the message
delay(200);
mySerial.println((char)26);//the message stopping character
delay(1000);
firesms_count++;
}

void SendMotionTextMessage()
{
mySerial.println(“AT+CMGF=1”); //To send SMS in Text Mode
delay(1000);
mySerial.println(“AT+CMGS=”+2348097701968"\r"); // change to the phone number you using
delay(1000);
mySerial.println(“MOTION DETECTED!”);//the content of the message
delay(200);
mySerial.println((char)26);//the stopping character
delay(1000);
mySerial.println(“AT+CMGS=”+2348110188925"\r"); // change to the phone number you using
delay(1000);
mySerial.println(“MOTION DETECTED!”);//the content of the message
delay(200);
mySerial.println((char)26);//the message stopping character
delay(1000);
pirsms_count++;
}

my lcd displays funny unstable characters and buzzer did not sound

thank you

if(digitalRead(push_switch==HIGH))// Checking if pushbutton was pressed

Oops

(Please remember to use code tags when posting code. "Suggestions for the Arduino project" was not a good choice of forum for this thread)

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks... Tom.. :slight_smile:

@koughjahdon, please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum Your code is too long to study quickly without copying to a text editor.

Also “it did not work well” provides no useful information from which to help you. Please describe in detail what the program does and what you want it to do.

…R

I hope they're not your real phone numbers.
If they are, you might want to change them when you edit to add the [code]code tags[/code] that you forgot. :wink:

ok let me do it

int ScanGasLevel()
{
gas_value=digitalRead(sensor); // reads the sensor output (Vout of LM35)

return gas_value; // returns temperature value in degree celsius
}

I don't understand this - why bother with the assignment to a global?

int ScanGasLevel()
{
  return digitalRead(sensor); // returns one or zero.
}
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
SoftwareSerial mySerial(9, 10);

int sensor=7;
int pirsensor=8;
int tempsensor=A1;
int speaker=0;
int push_switch=6;
int gas_value,Gas_alert_val, Gas_shut_val;
int Gas_Leak_Status;
float temp_read,Temp_alert_val,Temp_shut_val;
int sensor_value; //variable to hold read sensor value
int Motion_Scan_Status;
int gassms_count=0;
int firesms_count=0;
int pirsms_count=0;
int Fire_Set;

void setup()
{

pinMode(sensor,INPUT);
pinMode(pirsensor,INPUT);
pinMode(push_switch,INPUT);
pinMode(tempsensor,INPUT);
pinMode(speaker,OUTPUT);
mySerial.begin(9600);
Serial.begin(9600);
lcd.begin(20,4);
delay(500);

}

void loop()
{
CheckGas();
CheckShutDown();
CheckFire();
CheckFireShutDown();
Check_Burglar();// subroutine to check sensor status and activation of outputs
Check_Reset();
}

void CheckGas()
{

lcd.setCursor(0,0);
lcd.print("Gas Scan - ON");
Gas_alert_val=ScanGasLevel();
if(Gas_alert_val==LOW)
{
 SetAlert(); // Function to send SMS Alerts
}}

int ScanGasLevel()
{
gas_value=digitalRead(sensor); // reads the sensor output (Vout of LM35)

return gas_value; // returns temperature value in degree celsius
}

void CheckFire()
{
lcd.setCursor(0,1);
lcd.print("Fire Scan - ON");
Temp_alert_val=CheckTemp();
if(Temp_alert_val>45)
{
 SetFireAlert(); // Function to send SMS Alerts
}
}

float CheckTemp()
{
temp_read=analogRead(tempsensor); // reads the sensor output (Vout of LM35)
temp_read=temp_read*5;    // converts the sensor reading to temperature
temp_read=temp_read/10;  // adds the decimal point
return temp_read; // returns temperature value in degree celsius
}

void Check_Burglar()
{
lcd.setCursor(0,2);
lcd.print("Motion Scan - ON");
sensor_value=digitalRead(pirsensor); // Reading sensor value from pin 7
if(sensor_value==HIGH) // Checking if PIR sensor sends a HIGH signal to Arduino
{
  SetMotionAlert();
}
}

void SetMotionAlert()
{
digitalWrite(speaker,HIGH); // Activating the buzzer
  while(pirsms_count<1) //Number of SMS Alerts to be sent limited at 3
    {
      SendMotionTextMessage(); // Function to send AT Commands to GSM module
    }
   Motion_Scan_Status=1;
lcd.setCursor(0,3);
lcd.clear();
lcd.print("Intrusion Alert! SMS Sent!");
delay(1000);
}

void SetAlert()
{
digitalWrite(speaker,HIGH);
while(gassms_count<1) //Number of SMS Alerts to be sent
{
SendTextMessage(); // Function to send AT Commands to GSM module
}
Gas_Leak_Status=1;
lcd.setCursor(0,3);
lcd.clear();
lcd.print("Gas Alert! SMS Sent!");
delay(1000);
}
void SetFireAlert()
{
digitalWrite(speaker,HIGH);
while(firesms_count<1) //Number of SMS Alerts to be sent
{
SendFireTextMessage(); // Function to send AT Commands to GSM module
}
Fire_Set=1;
lcd.setCursor(0,3);
lcd.clear();
lcd.print("Fire Alert! SMS Sent!");
delay(1000);
}

void CheckShutDown()
{
if(Gas_Leak_Status==1)
{

Gas_shut_val=ScanGasLevel();
if(Gas_shut_val==HIGH)
{

lcd.setCursor(0,3);
lcd.print("No Gas Leaking");
digitalWrite(speaker,LOW);
gassms_count=0;
Gas_Leak_Status=0;
}}}

void CheckFireShutDown()
{
if(Fire_Set==1)
{

Temp_shut_val=CheckTemp();
if(Temp_shut_val<28)
{
lcd.setCursor(0,3);
lcd.print("Fire Shut! SAFE NOW");
digitalWrite(speaker,LOW);
firesms_count=0;
Fire_Set=0;
}}}

void Check_Reset()
{
if(digitalRead(push_switch==HIGH))// Checking if pushbutton was pressed
{
  lcd.setCursor(0,3);
lcd.print("No Motion Detected");
digitalWrite(speaker,LOW); // turning OFF the buzzer
pirsms_count=0; // Reactivating the SMS Alert Facility
Motion_Scan_Status=0;
}}

void SendTextMessage()
{
  mySerial.println("AT+CMGF=1");    //To send SMS in Text Mode
  delay(1000);
  mySerial.println("AT+CMGS=\"+2348097*******\"\r"); // change to the phone number you using
  delay(1000);
  mySerial.println("Gas Leaking!");//the content of the message
  delay(200);
  mySerial.println((char)26);//the stopping character
  delay(1000);
   mySerial.println("AT+CMGS=\"+23481*********\"\r"); // change to the phone number you using
  delay(1000);
  mySerial.println("Gas Leaking!");//the content of the message
  delay(200);
  mySerial.println((char)26);//the message stopping character
  delay(1000);
  gassms_count++;
}

void SendFireTextMessage()
{
  mySerial.println("AT+CMGF=1");    //To send SMS in Text Mode
  delay(1000);
  mySerial.println("AT+CMGS=\"+23480977******\"\r"); // change to the phone number you using
  delay(1000);
  mySerial.println("Fire in THE ROOM!");//the content of the message
  delay(200);
  mySerial.println((char)26);//the stopping character
  delay(1000);
   mySerial.println("AT+CMGS=\"+2348110*****\"\r"); // change to the phone number you using
  delay(1000);
  mySerial.println("Fire in THE ROOM!");//the content of the message
  delay(200);
  mySerial.println((char)26);//the message stopping character
  delay(1000);
  firesms_count++;
}

void SendMotionTextMessage()
{
  mySerial.println("AT+CMGF=1");    //To send SMS in Text Mode
  delay(1000);
  mySerial.println("AT+CMGS=\"+23480977******\"\r"); // change to the phone number you using
  delay(1000);
  mySerial.println("MOTION DETECTED!");//the content of the message
  delay(200);
  mySerial.println((char)26);//the stopping character
  delay(1000);
   mySerial.println("AT+CMGS=\"+2348110****\"\r"); // change to the phone number you using
  delay(1000);
  mySerial.println("MOTION DETECTED!");//the content of the message
  delay(200);
  mySerial.println((char)26);//the message stopping character
  delay(1000);
  pirsms_count++;
}

actually it works fine on simulation but after uploading to my anduino uno, THE LCD Displays funny write ups.

image is attached below

Hi,
Are the wires soldered to the LCD PCB?

Tom... :slight_smile:

yes they are.

Image from Reply #7 so we don’t have to download it. See this Image Guide

9596e37e98ab10864f048d2b3b70d1568367754c.jpg

…R

I can't see that image sufficiently well to see what is wrong.

If you write a short program that just displays "hello world" on the LCD, does that work?

...R

Hi,
I count 11 wire to your LCD, I think there should be 12.
LCDConnections.jpg

http://web.cecs.pdx.edu/~eas199/B/howto/arduino/Arduino_programming_part6_notes.pdf
Tom… :slight_smile:

thank you to every body.

Hi,
Has your problem been solved, if so please tell us what it was.
Other forum users use these threads to help solve their problems, so it would be right to tell us how you fixed your problem.
Also if it is fixed, go back to the subject of this thread and edit it to ad [SOLVED]

Thanks.. Tom.. :slight_smile:

yes it was solved thank u guys so much

Hi,
What was the solution to the problem?
Please this thread could prove helpful to anyone with a similar probem.

Tom.. :slight_smile: