Go Down

Topic: Serial Communication between a cell phone and Arduino Mega 2560 (Read 1 time) previous topic - next topic

sanowar

I have connected the Rx, Tx and Gnd pins from the cell phone to that of the microcontroller...Now how do i program so that a particular relay is turned on that is a digital output pin is set to a 'high'' value upon receving a call from a paricular number or a particular sms.

I know i will have to use AT command sets but how do i write the code so that the microcontroller and the phone can communicate with each other?
Thank You.
S.Ashraf

PaulS

Crossposting all over the place won't help.

The key is right there in your post title. Use the Serial.print() command to send the AT commands to the phone, and the Serial.available() and Serial.read() commands to get the response (or any phone initiated communication).

Once you have data coming from the phone, it is up to you to parse and act on that data.

sanowar

S.Ashraf

sanowar

Could someone please tell me how to use these serial.print() serial.available() and serial.read() functions so that a relay gets turned on when i call the the phone whose rx and tx are connected to the arduino Mega 2560.

Thanks
S.Ashraf

zoomkat

Quote
Could someone please tell me how to use these serial.print() serial.available() and serial.read() functions so that a relay gets turned on when i call the the phone whose rx and tx are connected to the arduino Mega 2560.


The first thing to do is work on your code using the serial monitor until it is working. Then move into attaching your phone to the arduino. Simple serial on/off code.

Code: [Select]

// zoomkat 8-6-10 serial I/O string test
// type a string in serial monitor. then send or enter
// for IDE 0019 and later

int ledPin = 13;
String readString;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  Serial.println("serial on/off test 0021"); // so I can keep track
}

void loop() {

  while (Serial.available()) {
    delay(1); 
    char c = Serial.read();
    readString += c;
  }

  if (readString.length() >0) {
    Serial.println(readString);

    if (readString == "on")     
    {
      digitalWrite(ledPin, HIGH);
    }
    if (readString == "off")
    {
      digitalWrite(ledPin, LOW);
    }

    readString="";
  }
}


Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

Go Up