SIM900d + Atmega328 Sending SMS(having problem with digital input pins) SOLVE :D

hi guys! i'm newbie here so please bare with me. and sorry for my bad english. hmmmmmmm. go back to the subject. i'm having a project where in i need to send 3 different sms messages with respect to 3 different inputs(HIGH or LOW, i guess) of my 2 sensors and 1 switch on my atmega328 digital i/o pins. i connected rx of my sim900d to tx of atmega328 and tx of the sim900d to the rx of atmega328. and no problem to power supply i guess. im using only 5v dc to power both boards and an output of 3-5v coming from my sensors and switch to input HIGH value to the input pins of atmega328. im also done with my codes but i don't know if it is really correct because im not getting the desired result. here's the code:

int pin3 = 8;
int pin4 = 9;
int pin5 = 10;

void setup()
{
Serial.begin(2400); //Baud rate of the GSM/GPRS Module
Serial.print("\r");
delay(1000);

pinMode(pin3,INPUT);
pinMode(pin4,INPUT);
pinMode(pin5,INPUT);

}

void loop()
{
if(digitalRead(pin3) == HIGH)
{
delay(500);
level1_text();
}
else if (digitalRead(pin4) == HIGH)
{
delay(500);
level2_text();
}

else if (digitalRead(pin5) == HIGH)
{
delay(500);
final_text();
}
else
{
Serial.print("AT\r");
}

}

void level1_text()
{
Serial.print("AT+CMGF=1\r");
delay(1000);

Serial.print("AT+CMGS="+639088667253"\r"); //Number to which you want to send the sms
delay(1000);

Serial.print("Water Sensor Level 1"); //The text of the message to be sent
delay(1000);

Serial.write(0x1A);
delay(2000);
}

void level2_text()
{
Serial.print("AT+CMGF=1\r");
delay(1000);

Serial.print("AT+CMGS="+639088667253"\r"); //Number to which you want to send the sms
delay(1000);

Serial.print("Water Sensor Level 2"); //The text of the message to be sent
delay(1000);

Serial.write(0x1A);
delay(2000);
}

void final_text()
{
Serial.print("AT+CMGF=1\r");
delay(1000);

Serial.print("AT+CMGS="+639088667253"\r"); //Number to which you want to send the sms
delay(1000);

Serial.print("Final"); //The text of the message to be sent
delay(1000);

Serial.write(0x1A);
delay(2000);
}

i've tried other input pins but still same result. what's the real problem is that, every time i connect a connector pin to the declared input pins of atmega328 on my codes. as in only connector pins, no other connections, just connector pins, it sends an sms. and based on my code, it will just send an sms if there's an input of a HIGH value. but i don't get it. i didn't give any supply for it to sense a HIGH value just connector pins :frowning: i don't know if i have a wrong codes or it is a board problem or i miss any connections on the both boards. so please help me. and another problem, i bought another atmega328 to test if i have bad board or not but my program is not uploading. i waited for how many minutes but it didn't finish uploading the codes or sometimes i got an error. not sync.. something like that. what should i do? thanks for having a time reading my post. and hope you can help me. it will be much appreciated. thanks again and God Bless you!

Your pins are floating I guess.
You don't have any pull down resistor to set it's default state as low (as you wanted high level to trigger an event)?

Thanks for replying in my post sir. :slight_smile: hmmmm. i dont have any pull down resistor. i will try to it later and post the result sir. but i'm really wondering, how come it recognizes a high value in the input pins of my atmega328 even though i didn't connect any supply? just a connector pin or wire, the other side of it is not connected to any circuit or supply. when i insert the wire into the pins, it sends an sms messages which telling me that it sense a high value.

akosionin:
Thanks for replying in my post sir. :slight_smile: hmmmm. i dont have any pull down resistor. i will try to it later and post the result sir. but i'm really wondering, how come it recognizes a high value in the input pins of my atmega328 even though i didn't connect any supply? just a connector pin or wire, the other side of it is not connected to any circuit or supply. when i insert the wire into the pins, it sends an sms messages which telling me that it sense a high value.

I don't know witch shield you have but you should connect it to a power supply , when the shield is sending the SMS it need more power so it can make you problems
also I would like to suggest you to use the gsm library it worked great for me..
are you using arduino buttons or some thing home made ?

Thanks sir for the reply. I have fix this problem last night. :slight_smile: