Those who worked with Arduino and built any GPRS or IoT project, are familiar with Adafruit_FONA Library. This library is handy for the Arduino platform to build any GSM, GPRS, or related project. But unfortunately, this library doesn’t work with ESP32 directly. And I had awful experiences with this issue. Here is my solution, which you can follow.
⚠️ Disclaimer ⚠️
Working with electricity involves serious risk. Ensure you have the necessary skills and take proper safety precautions before attempting any electrical projects. Proceed at your own risk — the author assumes no responsibility for any damage, injury, or issues resulting from the use or misuse of the information provided.
All content on this website is original and protected by copyright. Please do not copy or reproduce content without permission. While most of the resources shared here are open-source and freely accessible for your learning and benefit, your respect for our intellectual effort is appreciated.
If you find our tutorials helpful, consider supporting us by purchasing related materials or sharing our work — it helps keep the content flowing.
Need help or have questions? Leave a comment below — the author is always happy to assist!
Table of Contents
Configure your IDE for ESP32:
Adafruit_FONA library is very useful and there are many features included in it. But this works fine with Arduino UNO, Mega, etc., not with ESP32 ICs. So, if you really want to use this library, then you must configure your ESP in the right way.
First, select the right ESP board. And if you do not have the board installed, then copy this link “https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json” into preference and search for the ESP32 board and install the ESP board.
After installation, select the right board. In my case, it was the ESP32 wrover module.
Start code:
Now, use the following code:
//Easy wash data logging part with the board named 'ESP32 wrover module' #include"Arduino.h" // as you are using arduino libraries, so its important to include #include "Adafruit_FONA.h" //if you use Software Serial #include <SoftwareSerial.h> SoftwareSerial fonaSS; SoftwareSerial *fonaSerial = &fonaSS; //if you want to use hardware serial //HardwareSerial fonaSS(1); //HardwareSerial *fonaSerial = &fonaSS; #define FONA_RST 32 char replybuffer[255]; Adafruit_FONA fona = Adafruit_FONA(~FONA_RST); //for 3G //Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST); void setup() { Serial.begin(115200); Serial.println("Hano?");//as my kid called hello... dly(1000); Serial.println(F("Initializing GSM")); fonaSerial->begin(4800, SWSERIAL_8N1, 33, 25, false);//for hardware serial use: fonaSerial->begin(115200,SERIAL_8N1,16,17, false); if (! fona.begin(*fonaSerial)) { Serial.println(F("Couldn't find FONA")); while (1); } Serial.println(F("FONA is OK")); fonaSerial->print("AT+CNMI=2,1\r\n"); //set up the FONA to send a +CMTI notification when an SMS is received Serial.println("FONA Ready"); GSM_ON(); } void loop() { } int net_status; uint16_t statuscode; void GSM_ON() { // make it slow so its easy to read! again: delay(1); fonaSerial->begin(4800, SWSERIAL_8N1, 33, 25, false); if (! fona.begin(*fonaSerial)) { Serial.println(F("Couldn't find FONA")); digitalWrite(FONA_RST, LOW); delay(100); digitalWrite(FONA_RST, HIGH); delay(300); goto again; while (1); } Serial.println(F("FONA is OK")); delay(1000); net_status = fona.getNetworkStatus(); while (net_status != 1) { net_status = fona.getNetworkStatus(); delay(1000); } Serial.println(F("Registered ok")); delay(1000); } //
Here, the only important and different thing is the
“fonaSerial->begin(4800, SWSERIAL_8N1, 33, 25, false);” line. Unlike Arduino UNO or mega, we need to configure the serial port in detail like this for ESP32.
Now, you can use your fona library as you need. If anywhere, there is any initialization, you need to replace it with the detail one. That’s it.
My result:
My result was satisfactory and worked immediately.

After this, I used the code for GPRS data posting which worked fine. Just like Arduino. No restarting or failure. I think you can use it now for your project.
Conclusion:
I had been having trouble configuring the ESP32 for fona library and ESP was restarting. Now it’s all solved and works smoothly. I Hope, your’s one will also work fine. See you in the next article, thanks!
You can read my other articles here:
- INA219 interfacing with STM32
- Logging Data to Excel from Arduino
- STM32 as USB Device
- Send SMS from Raspberry Pi using the GSM module
- Not Enough ROM/RAM error with micro-controllers
- Read ThingSpeak Channel using ESP8266 and Arduino
- Caller ID detection using Arduino
- Digital Clock with DS3231 & PIC microcontroller
Liked this article? Subscribe to our newsletter:
or,
Visit LabProjectsBD.com for more inspiring projects and tutorials.
Thank you!
0 Comments