gsm900 programming problem....

Please i need help i m doing my final year project… what i want is when send sms “On” led should turn on and when i send sms “Off” led should turn off but when i send sms “Off” PIR sensor should start work… but i dont know its not working here is my code please anyone can help meee

#include “SIM900.h”
#include <SoftwareSerial.h>
//#include “inetGSM.h”
#include “sms.h”
SMSGSM sms;
int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];
int ledPin = 13; // led connected to control pin 13
int PIRSensor = 2; // the PIR sensor will be plugged at digital pin 2
int val=0;
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
pinMode(PIRSensor, INPUT); // declare the PIRSensor as as OUTPUT
Serial.begin(9600); // use the serial port
Serial.println(“GSM Shield testing.”);
//Start configuration of shield with baudrate.
//For http uses is raccomanded to use 4800 or slower.
if (gsm.begin(2400)){
Serial.println("\nstatus=READY");
started=true;
}
else Serial.println("\nstatus=IDLE");

if(started){
//Enable this two lines if you want to send an SMS.
//if (sms.SendSMS(“3471234567”, “Arduino SMS”))
//Serial.println("\nSMS sent OK");
}

};
void PIRON(){

if(digitalRead(PIRSensor==HIGH)){ // read the input pin
digitalWrite(ledPin, HIGH); // sets the LED to the button’s value
delay(1000);
digitalWrite(ledPin, LOW); // delay in milisecond. 3000 = 3 second
}

}

void loop() {
if(started){
//Read if there are messages on SIM card and print them.
if(gsm.readSMS(smsbuffer, 160, “On”, 20))
{
digitalWrite(ledPin, HIGH);
Serial.println(n);
Serial.println(smsbuffer);

}
if(gsm.readSMS(smsbuffer, 160, “Off”, 20))
{

digitalWrite(ledPin, LOW);

PIRON();
Serial.println(n);
Serial.println(smsbuffer);

}
delay(1000);

}

}

f(digitalRead(PIRSensor==HIGH)){   // read the input pin

Wrong Wrong! Wrong!

You are comparing PIRSensor to HIGH, and then reading from pin 0 or pin 1, depending on whether 2 equals 1, or not. That is most certainly NOT what the digitalRead() reference page told you was correct usage.

PaulS: f(digitalRead(PIRSensor==HIGH)){   // read the input pin

Wrong Wrong! Wrong!

You are comparing PIRSensor to HIGH, and then reading from pin 0 or pin 1, depending on whether 2 equals 1, or not. That is most certainly NOT what the digitalRead() reference page told you was correct usage.

Should i use like this ???? f(digitalRead(PIRSensor=HIGH)){

Should i use like this ?

No. You should go look at the digitalRead() page to see how to use the function. The function takes one argument, a pin number, and returns a value - the state of the pin. It is the returned value that you want to test, using ==, not anything to do with the input argument, That is a fixed value.

PaulS:

Should i use like this ?

No. You should go look at the digitalRead() page to see how to use the function. The function takes one argument, a pin number, and returns a value - the state of the pin. It is the returned value that you want to test, using ==, not anything to do with the input argument, That is a fixed value.

then i have to use like this right? val = digitalRead(PIRSensor); // read the input pin digitalWrite(ledPin, val);

then i have to use like this right?

Or like:

if(digitalRead(somePin) == HIGH) // Pay attention to where the parentheses are.

PaulS:

then i have to use like this right?

Or like:

if(digitalRead(somePin) == HIGH) // Pay attention to where the parentheses are.

its still not working …

void PIRON(){

if(digitalRead(PIRSensor)==HIGH)){   // read the input pin
  digitalWrite(ledPin, HIGH);      // sets the LED to the button's value
  delay(1000);    
digitalWrite(ledPin, LOW);   // delay in milisecond. 3000 = 3 second
  }

}



void loop(){
 if(started){
    //Read if there are messages on SIM card and print them.
    if(gsm.readSMS(smsbuffer, 160, "On", 20))
    {
       digitalWrite(ledPin, HIGH);
      Serial.println(n);
      Serial.println(smsbuffer);

    }
     if(gsm.readSMS(smsbuffer, 160, "Off", 20))
    {

  digitalWrite(ledPin, LOW);
      
       PIRON();
 Serial.println(n);
      Serial.println(smsbuffer);
    }

when i send sms “Off” led turn on and led remain turn on it wont turn off again

Moderator edit: [code][/code] tags added. (Nick Gammon)

That doesn’t even compile. If you want help, post code that compiles. And use code tags.

You can do that by hitting the # button above the posting area.

if(digitalRead(PIRSensor)==HIGH)){   // read the input pin

Putting) random)) parentheses(( in the(( co))de is not proper((. Pay real attention(((to))where they(need(to))be.