Bonjour
Je teste un code pour envoyer et recevoir un sms. Quand j’injecte le code par pc et je teste le programme fonctionne mais dés que je debranche la carte et j essaie avec une alimentation externe ca marche plus cad lorsque je fais le reset de la carte le prog ne marche plus
#include <SoftwareSerial.h>
SoftwareSerial SIM900A(10,11); // RX | TX
// Connect the SIM900A TX to Arduino pin 2 RX.
// Connect the SIM900A RX to Arduino pin 3 TX.
char c = ' ';
void setup()
{
// start th serial communication with the host computer
Serial.begin(19200);
while(!Serial);
Serial.println("Arduino with SIM900A is ready");
// start communication with the SIM900A in 9600
SIM900A.begin(19200);
Serial.println("SIM900A started at 9600");
delay(1000);
Serial.println("Setup Complete! SIM900A is Ready!");
}
void loop()
{
// Keep reading from SIM800 and send to Arduino Serial Monitor
if (SIM900A.available())
{ c = SIM900A.read();
Serial.write(c);}
// Keep reading from Arduino Serial Monitor and send to SIM900A
if (Serial.available())
{ c = Serial.read();
SIM900A.write(c);
}
}
Memr avec ce code tjr le meme probleme des que j utilise une alimentation externe
Code: [Select]
#include <SoftwareSerial.h>
SoftwareSerial SIM900A(10,11);
String textMessage;
// Create a variable to store Lamp state
String lampState = "HIGH";
// Relay connected to pin 7
const int relay = 7;
void setup()
{
// Set relay as OUTPUT
pinMode(relay, OUTPUT);
// By default the relay is off
digitalWrite(relay, HIGH);
SIM900A.begin(9600); // Setting the baud rate of GSM Module
Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
Serial.println ("SIM900A Ready");
delay(100);
Serial.println ("Type s to send message or r to receive message");
}
void loop()
{
if(SIM900A.available()>0){
textMessage = SIM900A.readString();
Serial.print(textMessage);
delay(10);
}
if(textMessage.indexOf("ON")>=0){
// Turn on relay and save current state
digitalWrite(relay, LOW);
lampState = "on";
Serial.println("Relay set to ON");
textMessage = "";
}
if(textMessage.indexOf("OFF")>=0){
// Turn off relay and save current state
digitalWrite(relay, HIGH);
lampState = "off";
Serial.println("Relay set to OFF");
textMessage = "";
}
if(textMessage.indexOf("STATE")>=0){
String message = "Lamp is " + lampState;
sendSMS(message);
Serial.println("Lamp state resquest");
textMessage = "";
}
}
// Function that sends SMS
void sendSMS(String message){
// AT command to set SIM900 to SMS mode
SIM900A.print("AT+CMGF=1\r");
delay(100);
// REPLACE THE X's WITH THE RECIPIENT'S MOBILE NUMBER
// USE INTERNATIONAL FORMAT CODE FOR MOBILE NUMBERS
SIM900A.println("AT+CMGS=\"+212662096718\"");
delay(100);
// Send the SMS
SIM900A.println(message);
delay(100);
// End AT command with a ^Z, ASCII code 26
SIM900A.println((char)26);
delay(100);
SIM900A.println();
// Give module time to send SMS
delay(5000);
}
void RecieveMessage()
{
Serial.println ("SIM900A Membaca SMS");
delay (1000);
SIM900A.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
delay(1000);
Serial.write ("Unread Message done");
}