Using ESP-01 module with Google Sheets

I am doing a RFID based attendance system project. I want to show the attendance as a list in Google Sheets and I think in order to do that my project needs to have access to the internet. Therefore, I get a ESP-01 to do that but every one that I saw online uses Nod Ncu board. I have to use Arduino mega and I could not find a way to use ESP-01 with Google Sheets. All projects use #include and #include library but i could not find them properly or the ones that I found do not work. Thank you in advance!

This is my code

// Adding Libraries
#include <SoftwareSerial.h>
#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystalTr.h>
#include <Keypad.h>
#include <Wire.h>
//Wifi

String agAdi = "Emirhan";                 //Ağımızın adını buraya yazıyoruz.    
String agSifresi = "********";
int rxPin = 11,txPin = 10;

#define DEBUG true    

SoftwareSerial esp(rxPin, txPin); 

const String sheet_url = "my url";

String ip = {"06:FE:EE:38:F8:72:25:AA:12:CF:D6:DC:2B:BD:4E:97"};

// Creating RFID
#define RST_PIN         8         
#define SS_PIN          9 

MFRC522 mfrc522(SS_PIN, RST_PIN);

MFRC522::MIFARE_Key key;

//KEYPAD
const byte ROWS = 4; 
const byte COLS = 4; 

char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {37, 36, 35, 34}; 
byte colPins[COLS] = {33, 32, 31, 30}; 

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 

bool captureInput = false; 
String capturedInput = "";

//LCD

const int rs = 6, en =7, d4 =2, d5 = 3, d6=4, d7=5;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

int wb = 11;
int wa = 0;


//Students and Teacher

byte cardID[4];
int ID[4];
int a = 0;


byte Tcard[4] = {0xc3, 0xc1, 0x90, 0xa5};

char Tname[] = "Mahmut Ağan";

char Tid[] = "6546";


byte card[7][4] = {{0x63, 0x96, 0x15, 0x34}, {0x63, 0x95, 0xa1, 0x34}, {0xa1, 0x05, 0xd3, 0x1d}, {0x91, 0xaa, 0x92, 0x1d}, {0x23, 0x5D, 0x18, 0x16}, {0x93, 0x75, 0x27, 0x16}, {0x50, 0x15, 0xCA, 0x80}};

char name[7][30] = {" Charlotte Taylor-Smith  ", " Elizabeth Woolridge Grant  ", " Kağan Akgün", "Jesper Fahey", "Emre Göğer", "Murathan Hatay", "Emirhan Çoban"};

char id[7][4] = {"7849", "5925", "2858", "9298", "9132", "2201", "4234"};

bool att[7] = {0, 0, 0, 0, 0, 0, 0};

bool te = 0;

//Fun Card

byte fun[4] = {0xe3, 0x72, 0x13, 0xad};

//

int timer = 0;
int ntimer = 0;
int stimer = 0;
int ctimer = 0;

char * start = " Scan card or Press 'A'  ";
char * attendance = " Attendance has already been taken   ";

int iLineNumber = 1;  
int LineNumber = 0;                                                                 // Line number to show your string (Either 0 or 1)

int iCursor = 0;

int place;

//

void setup() {
  
  Serial.begin(9600);
  SPI.begin();
  mfrc522.PCD_Init();
  lcd.begin(16, 2);
  Serial.println("Started");
  esp.begin(115200);                                          //ESP8266 ile seri haberleşmeyi başlatıyoruz.
  esp.println("AT");                                          //AT komutu ile modül kontrolünü yapıyoruz.
  Serial.println("AT has been send");
  while(!esp.find("OK")){                                     //Modül hazır olana kadar bekliyoruz.
    esp.println("AT");
    Serial.println("ESP8266 can not be find.");
  }
  Serial.println("OK order has been received");
  esp.println("AT+CWMODE=1");                                 //ESP8266 modülünü client olarak ayarlıyoruz.
  while(!esp.find("OK")){                                     //Ayar yapılana kadar bekliyoruz.
    esp.println("AT+CWMODE=1");
    Serial.println("Settings....");
  }
  Serial.println("Client");
  Serial.println("Connecting...");
  esp.println("AT+CWJAP=\""+agAdi+"\",\""+agSifresi+"\"");    //Ağımıza bağlanıyoruz.
  while(!esp.find("OK"));                                     //Ağa bağlanana kadar bekliyoruz.
  Serial.println("Connected.");
  delay(1000);
}     



void loop() { 

  esp.println("AT+CIPSTART=\"TCP\",\""+ip+"\",80");

  String veri = "GET https://api.thingspeak.com/update?api_key=73N0W23NT8T81AB3"; 

  for(int i = 0; i < 4; i++){
    ID[i] = 0;
  }

  
  lcd.setCursor(4,0);
  lcd.print("EEE1002");
  lcd.setCursor(0,1);
  Scroll(start);
  
  stimer = 0;
  while(stimer < 8){
    delay(50);
    stimer++;
    char key = customKeypad.getKey();

    //Starts the ID taking from keypad if 'A' is pushed

    if(key){
      
      if(key == 'A'){

        lcd.clear();
        lcd.print("Please enter ID:");

        while(1){

          key = customKeypad.getKey();

          if(key){

            //Takes the written ID

            if(a<=3 && a>=0 && key != 'A' && key != 'B' && key != 'C' && key != 'D' && key != '#' && key != '*'){
              ID[a]= key;
              lcd.setCursor(a,1);
              lcd.print(key);
              a++;
            }

            //Deletes one character while writing the ID

            if(key == 'C'){
              if(a>0&&a<=4){
                a=a-1;
                lcd.setCursor(a,1);
                lcd.print(" ");
              }
            }
            
            //Cancels the operation

            if(key == 'D'){
              a=0;
              break;
            }

            //Accepts the written ID

            if(key == 'B'){
              lcd.clear();
              Wait();
              lcd.clear();
              
              //ID Part
              
              if(ID[0] == Tid[0] && ID[1] == Tid[1] && ID[2] == Tid[2] && ID[3] == Tid[3] && te == 0){ //Activets Lesson from teacher's id
                te=1;
                if(strlen(Tname) > 16){
                  while(ntimer < 30){
                    Scroll(Tname);  
                    delay(280);
                    ntimer++; 
                  }
                }else{
                  place = floor((16 - strlen(Tname))/2);
                  lcd.setCursor(place,0);
                  lcd.print(Tname);
                }
                ntimer = 0;
                iCursor = 0;
                while(ntimer < 30){
                  Scroll(" Attendance taking has been started  ");
                  delay(300);
                  ntimer++;
                }
                lcd.clear();
                timer = 0;
                ntimer = 0;
                iCursor = 0;
                lcd.clear();
                a=0;
                return;
              }
              else if(ID[0] == Tid[0] && ID[1] == Tid[1] && ID[2] == Tid[2] && ID[3] == Tid[3] && te == 1){ //Deactivets Lesson from teacher's id
                te=0;
                for(int b = 0; b < 7; b++){
                  att[b] = 0;
                }
                if(strlen(Tname) > 16){
                  while(ntimer < 30){
                  Scroll(Tname);  
                  delay(280);
                  ntimer++; 
                  }
                }else{
                  place = floor((16 - strlen(Tname))/2);
                  lcd.setCursor(place,0);
                  lcd.print(Tname);
                }
                ntimer = 0;
                iCursor = 0;
                while(ntimer < 30){
                  Scroll(" Attendance taking has been over  ");
                  delay(280);
                  ntimer++;
                }
                lcd.clear();
                a=0;
                timer = 0;
                iCursor = 0;
                return;
              }

              for(int i = 0; i < 7; i++){
                if(ID[0] == id[i][0] && ID[1] == id[i][1] && ID[2] == id[i][2] && ID[3] == id[i][3] && te == 1 && att[i] == 0){ //Takes the attendance if the lesson is activated
                  iCursor = 0;
                  lcd.setCursor(4, 0);
                  lcd.print("Welcome");
                  if(strlen(name[i]) > 16){
                    while(ntimer < 30){
                    Scroll(name[i]);
                    delay(280);
                    ntimer++; 
                    }
                  }else{
                    place = floor((16 - strlen(name[i]))/2);
                    lcd.setCursor(place,1);
                    lcd.print(name[i]);
                    delay(4000);
                  }
                  lcd.clear();
                  att[i] = 1;
                  timer = 0;
                  ntimer = 0;
                  return;
                }
                else if(ID[0] == id[i][0] && ID[1] == id[i][1] && ID[2] == id[i][2] && ID[3] == id[i][3] && te == 1 && att[i] == 1){ //Does not take attendance because the attendance is already taken
                  iCursor = 0;
                  while(ntimer < 30){
                    Scroll1(attendance);
                    delay(280);
                    ntimer++;
                  }
                  lcd.clear();
                  timer = 0;
                  ntimer = 0;
                  iCursor = 0;
                  return;
                  return;
                }
                else if(ID[0] == id[i][0] && ID[1] == id[i][1] && ID[2] == id[i][2] && ID[3] == id[i][3] && te == 0){ //Does not take attendance because the lesson is deactive 
                iCursor = 0;
                lcd.setCursor(0,0);
                lcd.print("Wait the Teacher");
                while(ntimer < 30){
                  Scroll(" Attendance taking has not been started  ");
                  delay(280);
                  ntimer++;
                }
                ntimer = 0;
                iCursor = 0;
                  lcd.clear();
                  a=0;
                  return;
                }
              }

              //ID is not in the class list
              iCursor = 0;
      

      while(ntimer < 35){
       Scroll1(" You are not a participant in this course  ");
       delay(280);
       ntimer++;
      }
      ntimer = 0;
      iCursor = 0;
              lcd.clear();

              a=0;
              return;
            }
          }
        }
      }
    }
    
  }

  if ( ! mfrc522.PICC_IsNewCardPresent()) {

      if(te == 1){
        timer++;
        delay(50);//0.05 seconds
      }

      if(timer == 8000){// about 11 minutes
        timer = 0;
        te = 0;
        for(int b = 0; b < 7; b++){
          att[b] = 0;
        }
        lcd.clear();
        lcd.print("Time is over");
        delay(2000);
        lcd.clear();

      }
  }
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    lcd.clear();
    return;
  }
  

  lcd.clear();
  Wait();
  lcd.clear();

  //Get the UID of the scaned card 

  for (byte i = 0; i < mfrc522.uid.size; i++) {
     cardID[i]=mfrc522.uid.uidByte[i];
  }

  //Fun Card

  if(cardID[0] == fun[0] && cardID[1] == fun[1] && cardID[2] == fun[2] && cardID[3] == fun[3]){
    lcd.print("how do you have");
    lcd.setCursor(0,1);
    lcd.print("this card");
    delay(3000);
    lcd.clear();
  }

  // CARD

  if(cardID[0] == Tcard[0] && cardID[1] == Tcard[1] && cardID[2] == Tcard[2] && cardID[3] == Tcard[3] && te == 0){ //Activets Lesson from teacher's card
    te=1;
    if(strlen(Tname) > 16){
      while(ntimer < 30){
        Scroll(Tname);  
        delay(280);
        ntimer++; 
      }
    }else{
      place = floor((16 - strlen(Tname))/2);
      lcd.setCursor(place,0);
      lcd.print(Tname);
    }
    ntimer = 0;
    iCursor = 0;
    while(ntimer < 30){
      Scroll(" Attendance taking has been started  ");
      delay(300);
      ntimer++;
    }
    lcd.clear();
    timer = 0;
    ntimer = 0;
    iCursor = 0;
    lcd.clear();
    a=0;
    return;
  }
  else if(cardID[0] == Tcard[0] && cardID[1] == Tcard[1] && cardID[2] == Tcard[2] && cardID[3] == Tcard[3] && te == 1){ //Deactivets Lesson from teacher's card
    te=0;
    for(int b = 0; b < 7; b++){
      att[b] = 0;
    }
    if(strlen(Tname) > 16){
    while(ntimer < 30){
      Scroll(Tname);  
      delay(280);
      ntimer++; 
    }
    }else{
      place = floor((16 - strlen(Tname))/2);
      lcd.setCursor(place,0);
      lcd.print(Tname);
    }
    ntimer = 0;
    iCursor = 0;
    while(ntimer < 30){
      Scroll(" Attendance taking has been over  ");
      delay(280);
      ntimer++;
    }
    lcd.clear();
    a=0;
    timer = 0;
    iCursor = 0;
    return;
  }

  for(int i = 0; i < 7; i++){

    if(cardID[0] == card[i][0] && cardID[1] == card[i][1] && cardID[2] == card[i][2] && cardID[3] == card[i][3] && te == 1 && att[i] == 0){ //Takes the attendance if the lesson is activated
      iCursor = 0;
      lcd.setCursor(4, 0);
      lcd.print("Welcome");
      if(strlen(name[i]) > 16){
        while(ntimer < 30){
          Scroll(name[i]);  
          delay(280);
          ntimer++; 
        }
      }else{
        place = floor((16 - strlen(name[i]))/2);
        lcd.setCursor(place,1);
        lcd.print(name[i]);
        delay(4000);
      }
      lcd.clear();
      att[i] = 1;
      timer = 0;
      ntimer = 0;
      iCursor = 0;
      return;
    }
    else if(cardID[0] == card[i][0] && cardID[1] == card[i][1] && cardID[2] == card[i][2] && cardID[3] == card[i][3] && te == 1 && att[i] == 1){ //Does not take attendance because the attendance is already taken
     iCursor = 0;
      while(ntimer < 30){
       Scroll1(attendance);
       delay(280);
       ntimer++;
      }
      lcd.clear();
      timer = 0;
      ntimer = 0;
      iCursor = 0;
      return;
    }
    else if(cardID[0] == card[i][0] && cardID[1] == card[i][1] && cardID[2] == card[i][2] && cardID[3] == card[i][3] && te == 0){ //Does not take attendance because the lesson is deactive 
      iCursor = 0;
      lcd.setCursor(0,0);
      lcd.print("Wait the Teacher");
      while(ntimer < 30){
       Scroll(" Attendance taking has not been started  ");
       delay(280);
       ntimer++;
      }
      ntimer = 0;
      iCursor = 0;
      lcd.clear();
      a=0;
      return;
    }
  }
  
  //Card is not in the class list
  iCursor = 0;
      

  while(ntimer < 35){
    Scroll1(" You are not a participant in this course  ");
    delay(280);
    ntimer++;
  }
  ntimer = 0;
  iCursor = 0;
  lcd.clear();

  a=0;
              

}


void Scroll(const char * text) {
  int iLenOfLargeText = strlen(text);                                            // Calculate lenght of string.
  if (iCursor == (iLenOfLargeText - 1) )                                              // Reset variable for rollover effect.
  {
    iCursor = 0;
  }
  //lcd.clear();
  lcd.setCursor(0,iLineNumber);
  
  if(iCursor < iLenOfLargeText - 16)                                                  // This loop exicuted for normal 16 characters.
  {
    for (int iChar = iCursor; iChar < iCursor + 16 ; iChar++)
    {
      lcd.print(text[iChar]);
    }
  }
  else
  {
    for (int iChar = iCursor; iChar < (iLenOfLargeText - 1) ; iChar++)                //  This code takes care of printing charecters of current string.
    {
      lcd.print(text[iChar]);
    }
    for (int iChar = 0; iChar <= 16 - (iLenOfLargeText - iCursor); iChar++)           //  Reamining charecter will be printed by this loop.
    {
      lcd.print(text[iChar]);   
    }
  }
  iCursor++;
}

void Scroll1(const char * text) {
  int iLenOfLargeText = strlen(text);                                            // Calculate lenght of string.
  if (iCursor == (iLenOfLargeText - 1) )                                              // Reset variable for rollover effect.
  {
    iCursor = 0;
  }
  //lcd.clear();
  lcd.setCursor(0,LineNumber);
  
  if(iCursor < iLenOfLargeText - 16)                                                  // This loop exicuted for normal 16 characters.
  {
    for (int iChar = iCursor; iChar < iCursor + 16 ; iChar++)
    {
      lcd.print(text[iChar]);
    }
  }
  else
  {
    for (int iChar = iCursor; iChar < (iLenOfLargeText - 1) ; iChar++)                //  This code takes care of printing charecters of current string.
    {
      lcd.print(text[iChar]);
    }
    for (int iChar = 0; iChar <= 16 - (iLenOfLargeText - iCursor); iChar++)           //  Reamining charecter will be printed by this loop.
    {
      lcd.print(text[iChar]);   
    }
  }
  iCursor++;
}

void Wait(){
  lcd.print("Please Wait");
  while(wa <9){
    if(wb % 3 == 2){
      lcd.setCursor(12, 0);
      lcd.print("  ");
      lcd.setCursor(11, 0);
      lcd.print(".");
    }
    else if(wb % 3 == 0){
      lcd.setCursor(11, 0);
      lcd.print(" ");
      lcd.setCursor(13, 0);
      lcd.print(" ");
      lcd.setCursor(12, 0);
      lcd.print(".");
    }
    else if(wb % 3 == 1){
      lcd.setCursor(11, 0);
      lcd.print("  ");
      lcd.setCursor(13, 0);
      lcd.print(".");
    }
    delay(300);
    wa++;
    wb++;
  }
  wa = 0;
  wb = 11;
}

That probably won't work on the Mega. SoftwareSerial usually work OK for baudrates up to 19200 baud. everything above that is a lottery and proved to not being reliable. But good news: the Mega has 4 hardware serial interfaces of which only one is used by default (for the connection to the PC). Use one of the hardware serial interfaces and try again.

The ESP runs on 3.3V and according to it's datasheet is not 5V tolerant. So connecting it directly to the Mega might damage it. I know that some people do connect them directly (and make tutorials about it) but going beyond the specification is nothing you should do for the long term. So put a level converter in-between the two boards.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.