[136] | 1 | /*
|
---|
| 2 | Make Voice Call
|
---|
| 3 |
|
---|
| 4 | This sketch, for the Arduino GSM shield, puts a voice call to
|
---|
| 5 | a remote phone number that you enter through the serial monitor.
|
---|
| 6 | To make it work, open the serial monitor, and when you see the
|
---|
| 7 | READY message, type a phone number. Make sure the serial monitor
|
---|
| 8 | is set to send a just newline when you press return.
|
---|
| 9 |
|
---|
| 10 | Circuit:
|
---|
| 11 | * GSM shield
|
---|
| 12 | * Voice circuit.
|
---|
| 13 | With no voice circuit the call will send nor receive any sound
|
---|
| 14 |
|
---|
| 15 |
|
---|
| 16 | created Mar 2012
|
---|
| 17 | by Javier Zorzano
|
---|
| 18 |
|
---|
| 19 | This example is in the public domain.
|
---|
| 20 | */
|
---|
| 21 |
|
---|
| 22 | // libraries
|
---|
| 23 | #include <GSM.h>
|
---|
| 24 |
|
---|
| 25 | // PIN Number
|
---|
| 26 | #define PINNUMBER ""
|
---|
| 27 |
|
---|
| 28 | // initialize the library instance
|
---|
| 29 | GSM gsmAccess; // include a 'true' parameter for debug enabled
|
---|
| 30 | GSMVoiceCall vcs;
|
---|
| 31 |
|
---|
| 32 | String remoteNumber = ""; // the number you will call
|
---|
| 33 | char charbuffer[20];
|
---|
| 34 |
|
---|
| 35 | void setup()
|
---|
| 36 | {
|
---|
| 37 |
|
---|
| 38 | // initialize serial communications and wait for port to open:
|
---|
| 39 | Serial.begin(9600);
|
---|
| 40 | while (!Serial) {
|
---|
| 41 | ; // wait for serial port to connect. Needed for Leonardo only
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | Serial.println("Make Voice Call");
|
---|
| 45 |
|
---|
| 46 | // connection state
|
---|
| 47 | boolean notConnected = true;
|
---|
| 48 |
|
---|
| 49 | // Start GSM shield
|
---|
| 50 | // If your SIM has PIN, pass it as a parameter of begin() in quotes
|
---|
| 51 | while (notConnected)
|
---|
| 52 | {
|
---|
| 53 | if (gsmAccess.begin(PINNUMBER) == GSM_READY)
|
---|
| 54 | notConnected = false;
|
---|
| 55 | else
|
---|
| 56 | {
|
---|
| 57 | Serial.println("Not connected");
|
---|
| 58 | delay(1000);
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | Serial.println("GSM initialized.");
|
---|
| 63 | Serial.println("Enter phone number to call.");
|
---|
| 64 |
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | void loop()
|
---|
| 68 | {
|
---|
| 69 |
|
---|
| 70 | // add any incoming characters to the String:
|
---|
| 71 | while (Serial.available() > 0)
|
---|
| 72 | {
|
---|
| 73 | char inChar = Serial.read();
|
---|
| 74 | // if it's a newline, that means you should make the call:
|
---|
| 75 | if (inChar == '\n')
|
---|
| 76 | {
|
---|
| 77 | // make sure the phone number is not too long:
|
---|
| 78 | if (remoteNumber.length() < 20)
|
---|
| 79 | {
|
---|
| 80 | // let the user know you're calling:
|
---|
| 81 | Serial.print("Calling to : ");
|
---|
| 82 | Serial.println(remoteNumber);
|
---|
| 83 | Serial.println();
|
---|
| 84 |
|
---|
| 85 | // Call the remote number
|
---|
| 86 | remoteNumber.toCharArray(charbuffer, 20);
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | // Check if the receiving end has picked up the call
|
---|
| 90 | if (vcs.voiceCall(charbuffer))
|
---|
| 91 | {
|
---|
| 92 | Serial.println("Call Established. Enter line to end");
|
---|
| 93 | // Wait for some input from the line
|
---|
| 94 | while (Serial.read() != '\n' && (vcs.getvoiceCallStatus() == TALKING));
|
---|
| 95 | // And hang up
|
---|
| 96 | vcs.hangCall();
|
---|
| 97 | }
|
---|
| 98 | Serial.println("Call Finished");
|
---|
| 99 | remoteNumber = "";
|
---|
| 100 | Serial.println("Enter phone number to call.");
|
---|
| 101 | }
|
---|
| 102 | else
|
---|
| 103 | {
|
---|
| 104 | Serial.println("That's too long for a phone number. I'm forgetting it");
|
---|
| 105 | remoteNumber = "";
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 | else
|
---|
| 109 | {
|
---|
| 110 | // add the latest character to the message to send:
|
---|
| 111 | if (inChar != '\r')
|
---|
| 112 | remoteNumber += inChar;
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
| 116 |
|
---|