Introduction: Vintage Phone (mobile)

About: Hello I am George's I am now retired after working in the maintenance of phone exchanges all over the world I have always been interested in the new things and began building HIFI amplifier in the old time a…

Hello,

My name is Georges from France

This is my first instructables so please forgive me:

first for my english

and also for my C code which could look bad for the experts.

I already done many projects based on Arduino boards,

I am now retired and have been working for 42 years in the phone universe

So my idea , here, was to create an old vintage wooden phone with dialing disk and a list of recorded numbers (10 numbers dialed via the corresponding switch) as a summary (short!!! )of my working life.

This phone is "mobile" (I mean with a Sim card and battery)

Let's have a look to the equipment required........

Step 1: Required Equipment

  • The project is based on a SIM800L GSM module

As I wanted to have both handset and hanfree options I choose the ADAFRUIT FONA 800 µFl module

The advantage of this module is to have a 4 pole 3.5 mm jack to connect a standard headset equipment and also to have an external audio channel able to drive directly a small HP.

Another advantage is to have its own power supply with a 4;2 V LIPO battery which can face the high peaks of current (2A) generated by the SIM800 especially when sending radio bursts to the BTS (local GSM station)

the battery allows to have a "normal" power supply instead of a 3A power supply.

A loading circuitry is supplied by the FONA.

  • Power supply:

A MC7805 will provide the 5 Volt, 1 Amp required.

A 12 Volt DC 2 Amp power supply is enough for the power supply

3 diods are used to manage the power supply, the charging of the battery and the swich to either power supply or battery (see electric scheme next step).

8 AAA batteries ensure the 12 volt DC battery supply

A 4.2 ,2000 mAmp ensure the SIM800 supply

A triple power button ensure the complete switch off/on of the phone.

  • Micro-controller:

An Arduino nano will drive all the equipments.

the narrow memory space was a bit a challenge, this forced me to work on the optimisation of the code...

  • Dial Disk:

I found the dial disk with ETSY in Ukrain!!! it was used for phoneset in Russia , the duty cycle is a bit different as in France but nothing impossible for Arduino!

Only to wires of the disk are used (5 wires wereused in the phoneset), I used only the 2 wires corresponding to the contact generating the dialing pulses (10 for 0,1 for 1,.......)

Duty cycle is around 60/40 ms (60 open , 40 close) this will be verified during the coding

  • recorded numbers:

10 push buttons are used for dialing the recorded numbers

to save the pins of the nano I used a tension divider bridge with 10X680 Ohm resistors and one 6;8 KOhm resistor

The voltage measured on a analog pin will allow the calculation of the number to dial

10 LED's display the number dialed (or the calling number when it's part of the 10 recorded subscribers)

Again, to save nano pins I use a BCD to Decimal decoder/driver 74LS145 and therefore 4 digital pins are enough to drive the ten LED's

  • The Bell:

As I could'nt find an allready built bell (the phone bells are usually powered with 48 volts) I had to build it

2 bicycle bells and a 12V solenoid are doing the stuff.

The solenoid is driven by a 555 astable vibrator triggering a D882 darlington transistor.

  • The hook:

Home made with some pieces of iron and a spring to push a switch with the weight of the handset .

  • The handset:

From an authentic telephone set from the 50's bought for 5 € at a flea market

AS the speakers and the microphone are designed for 48 Volt I replaced them with two 32 Ohm speakers and an electret microphone.

A remark regarding the electret microphone:

Maybe I am the only one but I had always problems connecting a microphone to the SIM800 (I already built other projects with this device)

There is a lot of strange noises and not only due to the GSM process noise . I guess this is coming from the fact that the bias voltage provided by the SIM800L is only 2 volt which looks not enough for some microphones requiring min 3 Volt bias. Once again the microphone proposed by ADAFRUIT for the FONA works perfectly (in fact the need is a 1.5 volt bias electret microphone).

I added also a ring on the handset to hang it to the hook.

  • Hand free system:

A 8 Ohm speaker directly driven by the Fona and a 1;5 volt bias electret microphone is just what is required to get a good sound level for the handfree mode.

Of course all the audio devices are wired with shielded cables and with the shortest length without shielding.

Let's have a look now to the circuit............

Step 2: The Electric Scheme

Be indulgent this is my first Fritzing........

Maybe it seems a bit misty but in fact it is only differents basic electronic schemes gathered on a single scheme.

There are more information in the code listing...............

Step 3: The Arduino Code

A bit long but I tried to put as much information I could, so it should be understandable..

As the memory space is small in the nano I hade to use a lot the EEprom to store permanent and also temporary data's

And I used AT commands directly for SIM800L unstead of the fona library (read the SIM800 At commands manuel it's 380 pages but full of good informations)

I used the reserve() function for the strings (as I am not very comfortable with the char arrays)

For the time being the pre-recorded numbers must be once stored in the EEPROM at address 0-100 by a short code using the 10 strings of numbers(10 digits) and the subroutine put_num()

This will be achieved in a near future via the smartphone.

With this code I am near of the limit of the nano's memory .

I guess the experts will surely give me some tips to optimize it.

I need a bit more memory space to perform the numbers recording via smartphone and also the alarm mode as , in a next step it will be also an alarm with a PIR sensor and some code lines..............

***********************************************************************************************************
#include <softwareserial.h><SoftwareSerial.h><br>#include <EEPROM.h><eeprom.h>
/* prog for counting number on old rotary dial
pin2 count_pin is where we count the pukses
pulses count determines the phone number digit 
10=0
1=1
...........
a pulse is around 60ms high level signal
for opened dialing (first 2 digits are 00) a tempo_dialing set to 5 seconds establishes the end of dialing
*************************pin assignement******************
*hook=2
*hand_free=3
*dialing disk=4
*RX fona=5
*TX fona=6
*led display pins =7,8,9,10
*Ring=11;
*measurement analog pin for buttons=6
*/
/* EEPROM addresses:
 *  0-100 pre_recorded phone numbers
 *  volumes:
 *    102-104 mic0
 *    105-107 mic1
 *    108-110 spk0
 *    111-113 spk1
 *  115-128 last calling number
 *  129     address of black_pointer
 *  130-.......... black list
 */
/***************************common flags*********************/
int phone_state=0;
/***********phone_state***********
 * 0=> idle                      *
 * 1=> ready for dialing         *
 * 2=> dialing complete          *        
 * 3=> set call                  *
 * 4=> distant answer            *
 * 5=> call on going             *
 * 6=> incoming call             *
 * 7=> call stopped by distant   *
 * 8=>                           *
 * 9=> hang up                   *
 * ******************************/
/************************recorded numbers, data used only for first init*********************/
/*************************dial_disk**************************/
int count_pin=4;
int nb_pulse=0;
int nb_digit=0;
int nb_op_dial=0;
boolean dialing=false;
boolean flg_digit=false;
boolean flg_pulse=false;
boolean open_dial=false;// opened or closed dialing
boolean num_complete;
boolean sttone=false;
unsigned long temp_pulse;
unsigned long temp_low;
unsigned long temp_op_dial;// for opened dialing
String tel_num;
/*************************disp_led***************************/
int pin1=7;
int pin2=8;
int pin3=9;
int pin4=10;
int i;
int k;
int j;
int pin[]={0,0,0,0};//int array for led display
int numled=0;
/*************************num_but********************/
int pin_mess=6;
unsigned long val;
byte numbut;
unsigned long conf_val;
boolean start_val=false;
/*************************outgoing call*********************/
boolean hand_free=false;
boolean offhook=false;
boolean stop_dsp=false;
boolean check_hangup=false;
unsigned long debounce_up;
unsigned long debounce_down;
unsigned long temp_hook;
int hook=3;
int hand=2;
/****************************rec tel numbers**************************/
int num_pointer;
byte valc;
char h[9];
/***************************Ring**************************************/
int pin_ring=11;
unsigned long temp_ring;
unsigned long ack_ring;
/**************************mobile phone*******************************/
SoftwareSerial fona(5,6);
int buf1;
String sread;
unsigned long tempo_read;
boolean net_ok=false;
boolean gsmb=false;// gsm accept incoming calls
int hangup_state=0;//0= iddle,1=hangup,2=handfree,3=both)
char c;
/*************************ring****************************************/
unsigned long tempo_ring;
boolean flag_ring=false;
boolean start_ring=false;
/*************************incoming call*******************************/
boolean flag_clip=false;
String clip;
int numclip=11;
int ringingtone=19;
/************************led display*****************************/
int netpin=12;
int batmod=A2;
int power=A3;
int power_pin=A1;
String cur_time;
int cur_hour;
int prev_hour;
boolean green_num=false;
boolean time_ok=false;
boolean secteur=false;
boolean battery=false;
boolean alarmon=false;
unsigned long temp_mes;
byte temp_net=0;
/************************SMS management*****************************/
byte black_pointer;
String sms_number;
String mess_sms;
String sms_phone="\"+33xxxxxxxx\""; \\your smartphone number
String number;
String mic;
String spk;
String channel;
String time_fona;
//**********************************************************************
void setup() 
{
  sms_number.reserve(3);
  tel_num.reserve(10);
  cur_time.reserve(22);
  mic.reserve(3);
  spk.reserve(3);
  channel.reserve(2);
  number.reserve(15);
  mess_sms.reserve(30);
  sread.reserve(80);
  time_fona.reserve(23);
  pinMode(count_pin,INPUT_PULLUP);
  pinMode (hook,INPUT_PULLUP);
  pinMode (hand,INPUT_PULLUP);
  Serial.begin(115200);
  //setup display led
  pinMode(pin1,OUTPUT);
  pinMode(pin2,OUTPUT);
  pinMode(pin3,OUTPUT);
  pinMode(pin4,OUTPUT);
  pinMode(netpin,OUTPUT);
  pinMode(batmod,OUTPUT);
  pinMode(power,OUTPUT);
  pinMode(pin_ring,OUTPUT);
  digitalWrite(pin_ring,LOW);
  numled=-1;
  displed();
  EEPROM.get(129,black_pointer);
  //black_pointer=0;*****************to be used to reset blacklist***************************
  //EEPROM.put(129,black_pointer);
  fona.begin(57600);
  delay(400);
  //**************************init Sim800*********************************
  fona.println("AT+CMGF=1");// set SMS mode to text mode
  read_fona();
  fona.println("AT+CFUN=1");//set phone to normal mode
  read_fona();
  fona.println("AT+CMICBIAS=1");// set electret bias on
  read_fona(); 
  fona.println("AT+CLIP=1");//display calling party numbe
  read_fona();
  fona.println("AT+COLP=1");//display distant number
  read_fona();
  fona.println("AT+CRSL=00");//set ringing level
  read_fona();
  i=102;
  k=2;
  get_num();
  fona.println("AT+CMIC=0,"+number);
  read_fona();
  i=105;
  k=2;
  get_num();
  fona.println("AT+CMIC=1,"+number);
  read_fona(); 
  fona.println("ATS0=0");//no automatic answering
  read_fona();        
  check_net_fona();
  //********************* test power supply*******************************
  sys_mes(); 
}
void loop() 
{
  //*********************look for messages from Sim800*********************
  if (fona.available()>0)
  {
    read_fona();    
  }
  if (phone_state==0 && gsmb)// if phone state is iddle then accept incoming calls
  {
    gsmb=false;
    gsmbusy();
  }
  //*********************1 minute cycling task*****************
  if (millis()-temp_mes>60000)
  {
    //************power level measurement**************
    temp_mes=millis();
    sys_mes();
    //************time**************
    fona.println("AT+CCLK?");
    read_fona();
    temp_net+=1;//checknetwork will be lounched every 10 mn
    //*********************periodical network measurement  every 10 minutes*****************
    if (temp_net==10)
    {
      temp_net=0;
      check_net_fona();
    }
  }
  //*********************look for message from monitor*********************
  if (Serial.available()>0)
  {
    rec_message();
    if (sread!="")
    {
      if (sread.indexOf("T+")>0)// AT message to SIM800
      {
        fona.println(sread);
        read_fona();
      }
      else
      {
        // internal message from monitor
        decode_message();       
      }
    }
  }
  //*********************offhook*************
  if (digitalRead(hook)==LOW && !offhook && millis()-debounce_down>1000 )
  {
    offhook=true;
    debounce_up=millis();
  }
  if (digitalRead(hook)==HIGH && millis()-debounce_up>1000 && offhook)
  {
    offhook=false;
    debounce_down=millis();     
  }
  //**************************hand free***********
  if (digitalRead(hand)==LOW && !hand_free && millis()-debounce_down>1000)
  {
    hand_free=true;
    debounce_up=millis();     
  }
  if (digitalRead(hand)==HIGH && millis()-debounce_up>1000 && hand_free)
  {
    hand_free=false;
    debounce_down=millis();      
  }
  if ((hand_free || offhook)&& phone_state==0)
  {
    phone_state=1;
  }
  //********************************** statement of hook*****************
  if (hand_free && offhook && hangup_state!=3)
  {
    hangup_state=3;
    run_hand_free();    
  }  
  if (hand_free && !offhook && hangup_state!=2)
  {
    hangup_state=2;
    run_hand_free();    
  }
  if (!hand_free && offhook && hangup_state!=1)
  {
    hangup_state=1;
    p_offhook();
    st_hand_free();
  }
  if (!hand_free && !offhook && hangup_state!=0)
  {
    hangup_state=0;
    //Serial.println("raccrochage");
    st_hand_free();
    p_hangup();   
  }     
  if( millis()-temp_hook>5000 && phone_state==8)
  {
    flash_led();
  }
  
  /**************************************************
  *                 Dialing phone state =1          *
  ***************************************************/
  if (phone_state==1 )
  {
    if (!gsmb)
    {
      gsmb=true;//if phone state is "dialing phase" then reject incoming calls
      gsmbusy();
    }
    val=analogRead(pin_mess);
    if(val<1000)
    {
      dialing=true;
      if(!start_val)
      {
        conf_val=millis();
        start_val=true;
      }
      if (millis()-conf_val>20)//debouncing
      {
        if (val>analogRead(pin_mess)-10 && val<analogread(pin_mess)+10)        ="" {=""          ="" value="" confirmed="" start_val="false;" num_but();="" i="numbut*10;" k="9;" get_num();="" if="" (number.indexof("0000")="=-1)"            ="" numled="numbut;" displed();="" if(phone_state="=1)"              ="" phone_state="2;//1" pour="" essai************************="" }             =""  ="" }="" else="" flash_led();="" delay(3000);=""      =""    ="" } ="" dial_disk();="" **************************************************="" *                ="" send="" call=""> phone_state=3      *
  ***************************************************/
  if(phone_state==2)
  {
    // here tempo for dialing 
    phone_state=3;
    dialing=false;   
  }
  /**********************************************************************
  *                  start call=> phone_state=3        *
  ***********************************************************************/  
  if(phone_state==3)
  {
    fona.print("ATD0");
    fona.print(number);
    fona.println(";");       
    phone_state=4;     
  }
  /*************************************************************
  *                 waiting for distant answer=> phone_state=4 *
  **************************************************************/
  if (phone_state==4)
  {
    if(!sttone)
    {
      //fona.println("AT+STTONE=1,4,10000");
      sttone=true;
    }
    // waiting for remote answer (look for COLP in fona message)
    // remote answer => phone_state=5
  }
  /********************************************************
  *                 call set-up => phone_state=5          *
  *********************************************************/ 
  /*on call, just have to watch, either the local hang up, or "no carrier " from distant*/ 
  /**************************************************
  *                 incoming call => phone_state=6  *
  ***************************************************/ 
  if (phone_state==6)
  {
    if (offhook || hand_free)
    {
      fona.println("ATA");//answer
      // stop ringing
      flag_ring=false;
      start_ring=false;
      i=115;
      number=clip.substring(1,12);
      //Serial.println(number);
      put_num();
      clip="";
      numclip=11;
      digitalWrite(pin_ring,LOW);
      phone_state=5;// call set_up 
    }
    else
    {
      ring();
    }
    if(millis()-ack_ring>5000)
    {
      // distant caller has hungup => call missed
      mess_sms="Appel manque "+clip;
      send_sms();
      phone_state=0;
    }
  }
  /*****************************************************
  *                 distant hang up => phone_state=7   *
  *****************************************************/ 
  if (phone_state==7 && check_hangup)
  {
    temp_hook=millis();
    phone_state=8;
  }
  /*****************************************************
  *        waiting for local hangup => phone_state=8   *
  *****************************************************/ 
  if (!check_hangup && phone_state==8)
  {
    phone_state=9;
  }
  /**************************************************
  *                 hang up => phone_state=9        *
  **************************************************/
  if (phone_state==9)
  {
    fona.println("ATH");
    offhook=false;
    hand_free=false;
    raz_led();
    phone_state=0;  
  }
}
void dial_disk()
{
  /* this part of prog is to deal with the rotary disk dialing
   *  it consists in counting the pulses of each digit dialed
  */
  if(!dialing)
  {
    number="";
  }
  if (digitalRead(count_pin)==1 && !flg_digit)
  {
    //first pulse of a digit
    nb_pulse=0;
    flg_digit=true;
    flg_pulse=true;
    dialing=true;
    temp_pulse=millis();
  }
  if (digitalRead(count_pin)==1 && flg_digit && !flg_pulse)
  {
    //other pulse of the digit
    flg_pulse=true;
    temp_pulse=millis();
  }    
  if (digitalRead(count_pin)==0 && flg_digit && flg_pulse)
  {
    // end of pulse, we need to measure the length of it
    if (millis()-temp_pulse>50 and millis()-temp_pulse<120)
    {
      //this is a dialing pulse
      nb_pulse+=1;// count it
      flg_pulse=false;
      temp_low=millis();
    }
  }
  if (millis()-temp_low>200 && digitalRead(count_pin)==0 && flg_digit &&!flg_pulse )
  {
    // this is the last pulse of the digit
    flg_digit=false;
    if (nb_pulse==10)
    {
      nb_pulse=0;
    }
    number +=char(48+nb_pulse);//save it
    if (nb_digit==0 && nb_pulse==0)
    {
      nb_op_dial+=1;
    }
    if (nb_digit==1 && nb_pulse==0)
    {
      nb_op_dial+=1;
    }        
    if (nb_op_dial==2)
    {
      open_dial=true;// if 2 first digits are 00 then this is opened dialing to foreign country       
    }
    nb_pulse=0;
    temp_op_dial=millis();
    nb_digit+=1;//and wait for the next one
    if (nb_digit==10 && !open_dial)
    { 
      //Serial.print("numero compose=");
      number=number.substring(1,number.length());
      //Serial.println(number);
      nb_digit=0; 
      dialing=false;
      phone_state=2; 
    }   
  }
  if (digitalRead(count_pin)==0 && open_dial && !flg_digit && nb_digit>10)
  {
    //in case of opened dialing we wait for 3 seconds to be sure that the dialing is complete
    if (millis()-temp_op_dial>3000)
    {
      nb_digit=0;
      open_dial=false;
      phone_state=2;   
    }
  }
}
void displed()
{
  for(j=0;j<4;j++)
  {
    pin[j]=(numled)& 1;
    numled=(numled)>>1;
  }
  digitalWrite(pin1,pin[0]);
  digitalWrite(pin2,pin[1]);
  digitalWrite(pin3,pin[2]);
  digitalWrite(pin4,pin[3]); 
}
void flash_led()
{
  for(i=0;i<10;i++)
  {
    numled=i;
    displed();
    delay(20);
  } 
  raz_led();
}
void num_but()
{
  numbut=9-((val*6800)/(1024-val))/680;
}
void raz_led()
{
  numled=-1;
  displed();
}
void read_fona()
/************************** read messages sent by Sim800************************/
{
  
  tempo_read=millis();
  while(millis()-tempo_read<2000 && !(fona.available()>0)) 
  {
  }
  sread="";
  buf1=fona.available(); 
  while(buf1>0)
  {
    sread+= char(fona.read());
    buf1=fona.available();
    if (buf1<4)
    {
      delay(5);
    }
  }
  if (sread !="")
  {     
    Serial.println(sread);  
    //********************analyse messages****************
    if (sread.indexOf("CCLK:")>0)// ***************** date given by fona************
    {
      val=sread.indexOf("LK:");
      cur_time=sread.substring(val+5,val+22);
      val=sread.indexOf(",");
      cur_hour=(sread.substring(val+1,val+3)).toInt();
      if (cur_hour!= prev_hour)
      {
        time_ok=false;
        prev_hour=cur_hour;
        if ((cur_hour>=8 && cur_hour<12) || (cur_hour>=16 && cur_hour<20))
        {
          time_ok=true; 
        }
      }     
    }
    if (sread.indexOf("RING")>0)//**************incoming call*************
    {
      clip="";
      green_num=false;
      if(sread.indexOf("+")<1)//no clip
      {
        numclip=12;
      }
      else
      {
        val=sread.indexOf("+CLIP");
        clip=sread.substring(val+8,val+20);
        numclip=0;
        for(i=0;i<100;i+=10)
        {
          k=9;
          get_num();
          if (clip.indexOf(number)>0)
          {           
            green_num=true;// 
            break;
          }
          numclip+=1;
        }
        numclip+=1;
        if (numclip==11)
        {
          //check in black numbers list
          for (i=130;i<130+(12*black_pointer);i+=12)
          {
            k=11;
            get_num();
            number=number.substring(2,number.length());
            if(clip.indexOf(number)>0)
            {
              numclip=12;
              break;
            }
          }
        }
        if (numclip==12)// black list
        {
         fona.println("ATH");
         start_ring=false;
        }
        else
        {
          if (green_num || time_ok) //known number or time to call
          {
           phone_state=6;// incoming call
           start_ring=true;
          }
          if (!green_num && !time_ok)// unknown number and not time to call
          {
             fona.println("ATH");
             start_ring=false;
          }
        }
      }
    }
    if(sread.indexOf("OLP")>0 && phone_state==4)//*****************answer from distant-****************
    {
      phone_state=5;//******in call***************
    }
    if(sread.indexOf("NO CARRIER")>0)//*****************hangup by distant-****************
    {
      //call stopped by called party
      fona.println("ATH");
      phone_state=7;
    }
    //incoming SMS message code +CMTI
    if (sread.indexOf("MTI:")>0)
    {
      //rg_number=sread.indexOf("SM")+4;// SMS number
      sms_number=sread.substring(sread.indexOf("SM")+4,sread.indexOf("SM")+6);
      //read the SMS
      fona.print("AT+CMGR=");
      fona.println(sms_number);// read SMS
    }
    /******************first check that message comes from authorized number*****************/
    if (sread.indexOf("MGR:")>0)// SMS content
    {
      if (sread.indexOf("xxxxxxx")>0)//authorized calling number (8 last digits of your smartphone)
      {
        mess_sms="message inconnu    ";//standard message if SMS is not decoded
        decode_message();//decode SMS or serial line messages       
        fona.println("AT+CMGDA=DEL INBOX");
        delay(200);
        send_sms();        
      } 
    }
     sread="";  
  }
}
void check_net_fona()
{
  net_ok=false;
  while( !net_ok)
  {   
    fona.println("AT+CREG?");
    tempo_read=millis();
    while(millis()-tempo_read<2000 && !(fona.available()>0)) 
    {
    }
    sread="";
    buf1=fona.available();
    while(buf1>0)
    {
      sread+=char(fona.read());
      buf1=fona.available();
      if (buf1<4)// kind of "flow control" to avoid empty buffer due to read speed too high
      {
        delay(5);
      }
    }
    Serial.println(sread);
    if (sread.indexOf("CREG:")>0 && sread.indexOf("0,5")>0)
    {
      net_ok=true;
      digitalWrite(netpin,HIGH);
    }
    if (!net_ok)
    {
      digitalWrite(netpin,LOW);
      for(i=0;i<8;i+=4)
      {
        numled=i;
        displed();
        delay(80);
      }
      raz_led();
    }
    clear_buffer();
    delay(400);
  }
}
void rec_message()
{
  sread="";
  while (Serial.available() > 0) //get the incoming string
  {
    sread += char(Serial.read());
    delay(2);
  }
  Serial.println(sread);
} 
void ring()
{
  if(start_ring)
  {
    if (!flag_ring)
    {
      tempo_ring=millis();
      flag_ring=true;
    }
    if(millis()-tempo_ring<2000 && flag_ring)
    {
      ack_ring=millis();
      digitalWrite(pin_ring,HIGH);
      numled=numclip;
      displed();
    }
    if(millis()-tempo_ring>2000 && flag_ring)
    {
      digitalWrite(pin_ring,LOW);
      flag_ring=false;
      start_ring=false;
      raz_led();
    }
  }
}
void sys_mes()
{
  val=analogRead(power_pin);
  if(val>650)
  {
  //power supply mode
    digitalWrite(power,HIGH);
    digitalWrite(batmod,LOW);
    if (!secteur)
    {
      mess_sms="mode secteur";
      send_sms();
      secteur=true;
      battery=false;
    }
  }
  else
  {
    //battery supply mode
    digitalWrite(power,LOW);
    digitalWrite(batmod,HIGH);
    if (!battery)
    {
      secteur=false;
      battery=true;
      mess_sms="mode secours";
      send_sms();
    }         
  }
}
void p_offhook()
{
  //*********Set Sim800 to headset mode*********** 
  fona.println("AT+CHFA=0");//headset audio
  read_fona();
  i=108;
  k=2;
  get_num();    
  fona.print("AT+CLVL=");
  fona.println(number);
  read_fona();
  check_hangup=true;    
}
void p_hangup()
{    
  if(hangup_state==0)
  {
    phone_state=9;
    check_hangup=false;
  }        
}
void run_hand_free()
{
  //*********Set Sim800 to external mode***********
  fona.println("AT+CHFA=1");//external audio
  read_fona();
  i=111;
  k=2;
  get_num();
  fona.print("AT+CLVL=");
  fona.println(number);
  read_fona();
  check_hangup=true; 
}
void st_hand_free()
{    
  if (hangup_state==0)
  {
    phone_state=9;
    check_hangup=false;
  }
}
void decode_message()
{        
  //************************* decoding incoming messages from monitor or SMS********************
  //**********************list volume values********************
  if (sread.indexOf("ol?")>0)
  {
    i=102;
    k=2;
    get_num();
    mess_sms=number;
    mess_sms+=",";       
    i=105;
    k=2;
    get_num();
    mess_sms+=number;
    mess_sms+=",";
    i=108;
    k=2;
    get_num();    
    mess_sms+=number;
    mess_sms+=",";
    i=111;
    k=2;
    get_num();    
    mess_sms+=number;
  }
  //************************* set mic volume********************
  if (sread.indexOf("ic")>0)
  {
    channel=sread.substring(sread.indexOf("ic")+2,sread.indexOf("ic")+3);
    number=sread.substring(sread.indexOf("ic")+4,sread.indexOf("*")); 
    fona.print("AT+CMIC=");
    fona.print(channel);
    fona.print(","); 
    fona.println(number);
    delay(20);
    i=102;        
    if (channel=="1")//hand free
    {
      i=105;   
    }
    put_num();
    mess_sms=number;
  }
  //************************* speaker volume********************
  if (sread.indexOf("pk")>0)
  {
    channel=sread.substring(sread.indexOf("pk")+2,sread.indexOf("spk")+3);
    number=sread.substring(sread.indexOf("pk")+4,sread.indexOf("*"));    
    fona.print("AT+CLVL=");
    fona.println(number);
    delay(20);
    i=108;
    if (channel=="1")// hand free
    {
      i=111;      
    }
    put_num(); 
    mess_sms=number;     
  }
  //************************* set date/time********************
  if (sread.indexOf("ime")>0 && sread.indexOf("ime?")<0)
  {
    time_fona=sread.substring(sread.indexOf("ime")+3,sread.indexOf("*"));
    fona.print("AT+CCLK=\"");
    fona.print(time_fona);
    fona.println("\"");
    read_fona();
    mess_sms="time OK";      
  }
  //************************* get date/time *********************
  if (sread.indexOf("ime?")>0)
  {
    mess_sms="time ="+cur_time;// time will be availbale only one minute after restart        
  }  
  //************************* display last calling number********************
  if (sread.indexOf("ast?")>0)
  {
    i=115;
    k=11;
    get_num();  
    mess_sms="dernier appelant  "+number;     
  }
  //************************* black_list********************
  if (sread.indexOf("lack")>0)
  {
    EEPROM.get(129,black_pointer);
    i=115;
    k=11;
    get_num();// last call
    i=130+(12*black_pointer);
    put_num();
    black_pointer+=1;
    mess_sms="Numero en black list: "+number;
    if (black_pointer>40)
    {
      black_pointer=40;
      mess_sms="black liste pleine";
    }
    EEPROM.put(129,black_pointer);           
  }
  if (sread.indexOf("az liste")>0)
  {
    black_pointer=0;
    EEPROM.put(129,black_pointer); 
    mess_sms="liste noire efface";    
  }
  if (sread.indexOf("lklst")>0)//list blocked numbers
  {
    if (black_pointer==0)
    {
    }
    else
    {
      for (i=130;i<130+(12*black_pointer);i+=12)
      {
        k=11;
        get_num();     
      }
    }   
  }
  if (sread.indexOf("eclst")>0)//list blocked numbers
  {
    for(i=0;i<100;i+=10)
    {
      k=9;
      get_num();
    } 
  }  
}
void send_sms()
{
  fona.print("AT+CMGS=");
  delay(100);
  fona.println(sms_phone);
  delay(200);
  fona.println(mess_sms);
  delay(100);
  fona.write(char(26));
  delay(100);
  fona.println();
  delay(100);
}
void clear_buffer()
{
  while(fona.available()>0)
  {
    c=fona.read();
  }
}
void get_num()
{
  // input i as EEPROM address,k as string.length, output number as string 
  number="";
  valc=0;
  for (j=i;j<=i+k;j++)
  {
    EEPROM.get(j,valc);
    if (valc>47 && valc<58)
    {
      number +=char(valc);
    }
  }  
}
void put_num()
{
  // input i as EEPROM address, number as string to store
  number.toCharArray(h,number.length()+1);
  for (j=0;j<number.length()+1;j++)  ="" {=""    ="" eeprom.put(i+j,h[j]);="" }="" void="" gsmbusy()="" if="" (gsmb)="" fona.println("at+gsmbusy="1");" else="" }<="" p=""></number.length()+1;j++)></analogread(pin_mess)+10)></eeprom.h></softwareserial.h>


Step 4: The Smartphone Remote Management

I wanted to be able to manage remotely the Retrophone

You can see in the code that a part is dedicated to SMS treatment

With a short set of commands sent by SMS it is possible to set the level of handset of handfree mode, to blacklist a number, to set the time of the telephone( as the time is reset when switched off)

The time is necessary as this phone is planned to reject the calls during given periods (here in afternoon and in the night)

I made a small smartphone app with MIT APP Inventor but not yet completed so it will be a next subject

The list of SMS commands are :

Audio command:

spkchannel,level* (channel=0-1, level=0-100)

micchannel,level* (channel=0-1, level=0-15)

Vol? (gives the level of speaker and mic of the 2 channel)

Time command:

timeDD/MM/YY,HH:mm:ss+08* (08 is time difference for France)

time? (.....)

there are also commands for black list and other that I let you discover in the code

Note that it is also possible to enter AT commands via a monitor (ie the smartphone)

The phone sends also an SMS when a call has not be answered ( even when it is a mobile, most of the time, it stays at home!!!)

The programm allows only entering calls with CLIP (calling party number available) to avoid to have to buy 10 kitchens and 20 refrigarators and many insurances a day!!!.

So we arrive now at the end of the presentation

Once again as it is my first instructables I am sure that I missed a lot of information , I am available to answers to all the questions that will surely rise .

See you for new future adventures !!!!!!

Step 5: