Home
About Us
Achievement
Home
Raspberry-Pi Projects
_Raspberry Pi 4 Complete Guide
Arduino Project
_All Projects
Esp8266 Project
_All Projects
Esp32 Project
_Automation-with-feedback
Arduino And Gsm Based Mobile Phone
Just Do Electronics
April 08, 2020
Circuit Diagram :-
Code :-
//Prateek //www.prateeks.in #include
SoftwareSerial Serial1(2, 3); // RX, TX #include
LiquidCrystal lcd(9,8,7,6,5,4); byte back[8] = { 0b00000, 0b00000, 0b11111, 0b10101, 0b11011, 0b11111, 0b00000, 0b00000 }; String number=""; String msg=""; String instr=""; String str_sms=""; String str1=""; int ring=0; int i=0,temp=0; int sms_flag=0; char sms_num[3]; int rec_read=0; int temp1=0; #include
const byte ROWS = 4; //four rows const byte COLS = 4; //four columns char hexaKeys[ROWS][COLS] = { {'1','2','3','A'}, {'4','5','6','B'}, {'7','8','9','C'}, {'*','0','#','D'} }; byte rowPins[ROWS] = {10, 11, 12, 13}; //connect to the row pinouts of the keypad byte colPins[COLS] = {14, 15, 16, 17}; //connect to the column pinouts of the keypad //initialize an instance of class NewKeypad Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); String ch="1,.?!@abc2def3ghi4jkl5mno6pqrs7tuv8wxyz90 "; void setup() { Serial1.begin(9600); lcd.begin(16,2); lcd.createChar(1, back); lcd.print("Simple Mobile "); lcd.setCursor(0,1); lcd.print("System Ready.."); delay(1000); gsm_init(); lcd.clear(); lcd.print("System Ready"); delay(2000); } void loop() { serialEvent(); if(sms_flag==1) { lcd.clear(); lcd.print("New Message"); int ind=instr.indexOf("+CMTI: \"SM\","); ind+=12; int k=0; lcd.setCursor(0,1); lcd.print(ind); while(1) { while(instr[ind]!= 0x0D) { sms_num[k++]=instr[ind++]; } break; } ind=0; sms_flag=0; lcd.setCursor(0,1); lcd.print("Read SMS --> D"); delay(4000); instr=""; rec_read=1; temp1=1; i=0; } if(ring == 1) { number=""; int loc=instr.indexOf("+CLIP: \""); if(loc > 0) { number+=instr.substring(loc+8,loc+13+8); } lcd.setCursor(0,0); lcd.print("Incomming... "); lcd.setCursor(0,1); lcd.print(number); instr=""; i=0; } else { serialEvent(); lcd.setCursor(0,0); lcd.print("Call --> C "); lcd.setCursor(0,1); lcd.print("SMS --> B "); if(rec_read==1) { lcd.write(1); lcd.print(" "); } else lcd.print(" "); } char key=customKeypad.getKey(); if(key) { if(key== 'A') { if(ring==1) { Serial1.println("ATA"); delay(5000); } } else if(key=='C') { call(); } else if(key=='B') { sms(); } else if(key == 'D' && temp1==1) { rec_read=0; lcd.clear(); lcd.print("Please wait..."); Serial1.print("AT+CMGR="); Serial1.println(sms_num); int sms_read_flag=1; str_sms=""; while(sms_read_flag) { while(Serial1.available()>0) { char ch=Serial1.read(); str_sms+=ch; if(str_sms.indexOf("OK")>0) { sms_read_flag=0; //break; } } } int l1=str_sms.indexOf("\"\r\n"); int l2=str_sms.indexOf("OK"); String sms=str_sms.substring(l1+3,l2-4); lcd.clear(); lcd.print(sms); delay(5000); } delay(1000); } } void call() { number=""; lcd.clear(); lcd.print("After Enter No."); lcd.setCursor(0,1); lcd.print("Press C to Call"); delay(2000); lcd.clear(); lcd.print("Enter Number:"); lcd.setCursor(0,1); while(1) { serialEvent(); char key=customKeypad.getKey(); if(key) { if(key=='C') { lcd.clear(); lcd.print("Calling........"); lcd.setCursor(0,1); lcd.print(number); Serial1.print("ATD"); Serial1.print(number); Serial1.println(";"); long stime=millis()+5000; int ans=1; while(ans==1) { while(Serial1.available()>0) { if(Serial1.find("OK")) { lcd.clear(); lcd.print("Ringing...."); int l=0; str1=""; while(ans==1) { while(Serial1.available()>0) { char ch=Serial1.read(); str1+=ch; if(str1.indexOf("NO CARRIER")>0) { lcd.clear(); lcd.print("Call End"); delay(2000); ans=0; return; } } char key=customKeypad.getKey(); if(key == 'D') { lcd.clear(); lcd.print("Call End"); delay(2000); ans=0; return; } if(ans==0) break; } } } } } else { number+=key; lcd.print(key); } } } } void sms() { lcd.clear(); lcd.print("Initilising SMS"); Serial1.println("AT+CMGF=1"); delay(400); lcd.clear(); lcd.print("After Enter No."); lcd.setCursor(0,1); lcd.print("Press D "); delay(2000); lcd.clear(); lcd.print("Enter Rcpt No.:"); lcd.setCursor(0,1); Serial1.print("AT+CMGS=\""); while(1) { serialEvent(); char key=customKeypad.getKey(); if(key) { if(key=='D') { //number+='"'; Serial1.println("\""); break; } else { //number+=key; Serial1.print(key); lcd.print(key); } } } lcd.clear(); lcd.print("After Enter MSG "); lcd.setCursor(0,1); lcd.print("Press D to Send "); delay(2000); lcd.clear(); lcd.print("Enter Your Msg"); delay(1000); lcd.clear(); lcd.setCursor(0,0); alfakey(); } void alfakey() { int x=0,y=0; int num=0; while(1) { lcd.cursor(); char key=customKeypad.getKey(); if(key) { if(key=='1') { num=0; lcd.setCursor(x,y); lcd.print(ch[num]); for(int i=0;i<3000;i++) { lcd.noCursor(); char key=customKeypad.getKey(); if(key=='1') { num++; if(num>5) num=0; lcd.setCursor(x,y); lcd.print(ch[num]); i=0; delay(200); } } x++; if(x>15) { x=0; y++; y%=2; } msg+=ch[num]; } else if(key=='2') { num=6; lcd.setCursor(x,y); lcd.print(ch[num]); for(int i=0;i<3000;i++) { lcd.noCursor(); char key=customKeypad.getKey(); if(key=='2') { num++; if(num>9) num=6; lcd.setCursor(x,y); lcd.print(ch[num]); i=0; delay(200); } } x++; if(x>15) { x=0; y++; y%=2; } msg+=ch[num]; } else if(key=='3') { num=10; lcd.setCursor(x,y); lcd.print(ch[num]); for(int i=0;i<3000;i++) { lcd.noCursor(); char key=customKeypad.getKey(); if(key=='3') { num++; if(num>13) num=10; lcd.setCursor(x,y); lcd.print(ch[num]); i=0; delay(200); } } x++; if(x>15) { x=0; y++; y%=2; } msg+=ch[num]; } else if(key=='4') { num=14; lcd.setCursor(x,y); lcd.print(ch[num]); for(int i=0;i<3000;i++) { lcd.noCursor(); char key=customKeypad.getKey(); if(key=='4') { num++; if(num>17) num=14; lcd.setCursor(x,y); lcd.print(ch[num]); i=0; delay(200); } } x++; if(x>15) { x=0; y++; y%=2; } msg+=ch[num]; } else if(key=='5') { num=18; lcd.setCursor(x,y); lcd.print(ch[num]); for(int i=0;i<3000;i++) { lcd.noCursor(); char key=customKeypad.getKey(); if(key=='5') { num++; if(num>21) num=18; lcd.setCursor(x,y); lcd.print(ch[num]); i=0; delay(200); } } x++; if(x>15) { x=0; y++; y%=2; } msg+=ch[num]; } else if(key=='6') { num=22; lcd.setCursor(x,y); lcd.print(ch[num]); for(int i=0;i<3000;i++) { lcd.noCursor(); char key=customKeypad.getKey(); if(key=='6') { num++; if(num>25) num=22; lcd.setCursor(x,y); lcd.print(ch[num]); i=0; delay(200); } } x++; if(x>15) { x=0; y++; y%=2; } msg+=ch[num]; } else if(key=='7') { num=26; lcd.setCursor(x,y); lcd.print(ch[num]); for(int i=0;i<3000;i++) { lcd.noCursor(); char key=customKeypad.getKey(); if(key=='7') { num++; if(num>30) num=26; lcd.setCursor(x,y); lcd.print(ch[num]); i=0; delay(200); } } x++; if(x>15) { x=0; y++; y%=2; } msg+=ch[num]; } else if(key=='8') { num=31; lcd.setCursor(x,y); lcd.print(ch[num]); for(int i=0;i<3000;i++) { lcd.noCursor(); char key=customKeypad.getKey(); if(key=='8') { num++; if(num>34) num=31; lcd.setCursor(x,y); lcd.print(ch[num]); i=0; delay(200); } } x++; if(x>15) { x=0; y++; y%=2; } msg+=ch[num]; } else if(key=='9') { num=35; lcd.setCursor(x,y); lcd.print(ch[num]); for(int i=0;i<3000;i++) { lcd.noCursor(); char key=customKeypad.getKey(); if(key=='9') { num++; if(num>39) num=35; lcd.setCursor(x,y); lcd.print(ch[num]); i=0; delay(200); } } x++; if(x>15) { x=0; y++; y%=2; } msg+=ch[num]; } else if(key=='0') { num=40; lcd.setCursor(x,y); lcd.print(ch[num]); for(int i=0;i<3000;i++) { lcd.noCursor(); char key=customKeypad.getKey(); if(key=='0') { num++; if(num>41) num=40; lcd.setCursor(x,y); lcd.print(ch[num]); i=0; delay(200); } } x++; if(x>15) { x=0; y++; y%=2; } msg+=ch[num]; } else if(key=='D') { lcd.clear(); lcd.print("Sending SMS...."); // Serial1.print("AT+CMGS="); // Serial1.print(number); // delay(2000); Serial1.print(msg); Serial1.write(26); delay(5000); lcd.clear(); lcd.print("SMS Sent to"); lcd.setCursor(0,1); lcd.print(number); delay(2000); number=""; break; } } } } void send_data(String message) { Serial1.println(message); delay(200); } void send_sms() { Serial1.write(26); } void lcd_status() { lcd.setCursor(2,1); lcd.print("Message Sent"); delay(2000); //lcd.setCursor() //lcd.print("") //return; } void back_button() { //lcd.setCursor(0,15); } void ok_button() { lcd.setCursor(0,4); lcd.print("OK"); } void call_button() { lcd.setCursor(0,4); lcd.print("CALL"); } void sms_button() { lcd.setCursor(0,13); lcd.print("SMS"); } void gsm_init() { lcd.clear(); lcd.print("Finding Module.."); boolean at_flag=1; while(at_flag) { Serial1.println("AT"); while(Serial1.available()>0) { if(Serial1.find("OK")) at_flag=0; } delay(1000); } lcd.clear(); lcd.print("Module Connected.."); delay(1000); lcd.clear(); lcd.print("Disabling ECHO"); boolean echo_flag=1; while(echo_flag) { Serial1.println("ATE1"); while(Serial1.available()>0) { if(Serial1.find("OK")) echo_flag=0; } delay(1000); } lcd.clear(); lcd.print("Echo OFF"); delay(1000); lcd.clear(); lcd.print("Finding Network.."); boolean net_flag=1; while(net_flag) { Serial1.println("AT+CPIN?"); while(Serial1.available()>0) { if(Serial1.find("+CPIN: READY")) net_flag=0; } delay(1000); } lcd.clear(); lcd.print("Network Found.."); delay(1000); lcd.clear(); } void serialEvent() { while(Serial1.available()) { char ch=Serial1.read(); instr+=ch; i++; if(instr[i-4] == 'R' && instr[i-3] == 'I' && instr[i-2] == 'N' && instr[i-1] == 'G' ) { ring=1; } if(instr.indexOf("NO CARRIER")>=0) { ring=0; i=0; } if(instr.indexOf("+CMTI: \"SM\"")>=0) { sms_flag=1; } } }
0 Comments
Newer
Older
ESP32 Interfacing With LDR Sensor
How To Make RFID & Keypad Based Door Lock
Ultrasonic Sensor as a Counter with Arduino
IoT Based Patient Health Monitoring System Using Blynk App
How to Make Gas Leak Detector & Auto Exhaust Fan Using Arduino
MLX90614 Non-Contact Infrared Thermometer With Arduino
Measure CO2 Level in Air Using Arduino
Esp32 Cam Based Face Unlock
ESP32 Led Blink With Push Button
Smart Street Light Using Arduino
YouTube
Like on Facebook
Follow on Twitter
Follow on Google+
Follow on Instagram
Subscribe on Youtube
Hi WelCome To My Website If you have a creative mind and want to learn Electronics even without studying it then FRIENDS this Website And Youtube Channel is for you, I am crazy creators who love making Electronics things. I have a bunch of more than 130 Tutorial Videos on My YouTube Channel and I upload a new Tutorial every Sunday.
Tags
Arduino Project
Esp32 Project
Esp8266 Project
0 Comments