why i cant send a message when code have pinMode(pin#, INPUT)?
help please
why i cant send a message when code have pinMode(pin#, INPUT)?
help please
if this is your only line of code in your program, then that's why: because you don't send any message there
if you have other lines of code, then we would like to see them and possibly a drawing of how you connected things up... otherwise we can't help
frianne30:
why i cant send a message when code have pinMode(pin#, INPUT)?help please
If pin# is either 0 or 1 then you are interfering with Serial. Use a different pin number
If you don't post full details, we can only guess.
include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
#include "gsm.h"
SMSGSM sms;
char number[]="09057531200";
char Message[40];
char pos;
char *p;
int inPin = 5; // the number of the input pin
int inPin1 = 6;
int outPin = 11; // the number of the output pin
int outPin1=12;
int state = LOW; // the current state of the output pin
int state1 = LOW;
int reading; // the current reading from the input pin
int reading1;
int previous = HIGH; // the previous reading from the input pin
int previous1 = HIGH;
int in=INPUT;
int in1=INPUT;
long time = 0;
long debounce = 200;
boolean started=false;
int x=1;
void setup()
{
Serial.begin(9600);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(6,in);
pinMode(5,in1);
Serial.println("GSM Shield testing.");
}
void loop()
{
if(x==1)
{
if(sms.SendSMS(number,"asd"))
{
Serial.print("\nsent ok");}
}
reading = digitalRead(inPin);
reading1=digitalRead(inPin1);
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
if (state == HIGH)
{
state = LOW;}
else{
state = HIGH;
time = millis();
}
}
if (reading1 == HIGH && previous1 == LOW && millis() - time > debounce) {
if(state1==HIGH){
state1 = LOW;}
else{
state1=HIGH;
time=millis();}
sms.SendSMS(number,"sadsa");
}
digitalWrite(outPin, state);
digitalWrite(outPin1,state1);
previous = reading;
previous1 = reading1;
}
it just a test to send a sms..
and it doesn't work-.-
this code only print "sent ok"
and i didnt receive anything from the gsm
well you forgot the code to initialize your SIM900 in the setup.. (something like calling gsm.begin())
You never touch x
, so if(x==1)
will always be true and you will try to send an SMS at every loop, which is not really a good idea
why do you declare variables to hold pin numbers and don't use it
pinMode([color=red]11[/color],OUTPUT);
pinMode([color=red]12[/color],OUTPUT);
-->
pinMode([color=limegreen]outPin[/color],OUTPUT); // the pin name is not very descriptive...
pinMode([color=limegreen]outPin1[/color],OUTPUT);// the pin name is not very descriptive...
please edit your code above and add the code tags around your code. will be easier for everyone
void setup()
{
gsm.begin(2400); // if i used 9600 it doesnt work if 2400 my switch not woking-.-
Serial.begin(9600);
pinMode(outPin,OUTPUT);
pinMode(outPin1,OUTPUT);
pinMode(inPin,INPUT);
pinMode(inPin1,INPUT);
}
i used this as setup codes..
do this (assuming aSerialObject is connected to your PC/Mac)
if (gsm.begin(2400)) aSerialObject.println("\nstatus=READY");
else [i]aSerialObject.println[/i]("\nstatus=IDLE");
and check the return code.
How is your SIM900 connected? did you cross Tx/Rx ? do you have same ground?
are you on a Mega or a UNO or something else?
its working..thnks a lot. godbless!
great news