Pages: [1]   Go Down
Author Topic: Serial Communication between a cell phone and Arduino Mega 2560  (Read 976 times)
0 Members and 1 Guest are viewing this topic.
Dhaka
Offline Offline
Newbie
*
Karma: 0
Posts: 44
I love to learn and engineering is my passion
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

S.Ashraf

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48569
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Dhaka
Offline Offline
Newbie
*
Karma: 0
Posts: 44
I love to learn and engineering is my passion
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks a lot!:)
Logged

S.Ashraf

Dhaka
Offline Offline
Newbie
*
Karma: 0
Posts: 44
I love to learn and engineering is my passion
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

S.Ashraf

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
// 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="";
  }
}


Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Pages: [1]   Go Up
Jump to: