GSM Software Serial ERROR

#include <SoftwareSerial.h>
#include <Adafruit_Fingerprint.h>
#include <Wire.h>
#include <Adafruit_Thermal.h>
#include <LiquidCrystal_I2C.h>
#include <GSM.h>

// I2C LCD Display
LiquidCrystal_I2C lcd(0x27, 20, 4);
SoftwareSerial mySerial(2, 3);

// Define fingerprint sensor and pins
#define FINGERPRINT_RX 2
#define FINGERPRINT_TX 3
SoftwareSerial fingerSerial(4, 5); // RX, TX
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&fingerSerial);

// Define button pins and buzzer pin
#define BUTTON_CANDIDATE_1 4
#define BUTTON_CANDIDATE_2 5
#define BUTTON_CANDIDATE_3 6
#define BUZZER_PIN 7

// Define thermal printer and printer pin
#define PRINTER_RX 8
#define PRINTER_TX 9
SoftwareSerial printerSerial(6, 7); // RX, TX
Adafruit_Thermal printer(&printerSerial);

// GSM module pins
#define GSM_RX 10
#define GSM_TX 11

// Define GSM object
SoftwareSerial gsmSerial(GSM_RX, GSM_TX);
GSM gsmAccess;

// GSM related variables
char gsmPhoneNumber1[] = "+923012345678";  
char gsmPhoneNumber2[] = "+923022345678";
char gsmPhoneNumber3[] = "+923032345678";
GSM_SMS sms;

#define ADMIN_FINGERPRINT_ID 1

// Candidate names
const char* candidateNames[] = {
  "PTI",
  "PPP",
  "ANP"
};

// Candidate votes counters
int votesCandidate1 = 0;
int votesCandidate2 = 0;
int votesCandidate3 = 0;


void setup() {
  // Initialize serial communication with Arduino IDE
  Serial.begin(9600);
  
 // initialize the lcd
  lcd.begin();
 // Turn on the Backlight
  lcd.backlight();
  Serial.println("LCD initialized");
  Serial.begin(9600);
  while (!Serial);  // For Yun/Leo/Micro/Zero/...
  delay(100);
  
  // Initialize fingerprint sensor
  finger.begin(57600);
  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1);
  }
  
  finger.getTemplateCount();
  Serial.print("Sensor contains ");
  Serial.print(finger.templateCount);
  Serial.println(" templates");
  Serial.println("Waiting for valid finger...");
    lcd.clear(); 
  // Set cursor (Column, Row)
  lcd.setCursor(0, 0);  
  lcd.print("Digital Electronic"); 
  lcd.setCursor(0,1);
  lcd.print("Voting Machine");
  delay(3000);

  // Initialize buttons and buzzer
  pinMode(BUTTON_CANDIDATE_1, INPUT);
  pinMode(BUTTON_CANDIDATE_2, INPUT);
  pinMode(BUTTON_CANDIDATE_3, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);

  // Initialize thermal printer
  printer.begin();

  // Initialize GSM module
  gsmAccess.begin();
}

void loop() {
  // Wait for a finger to be detected
  if (finger.getImage()) {
    // Finger detected, search fingerprint database
    int fingerprintID = finger.fingerID;
    
    if (fingerprintID == 0) {
      // No fingerprint match found
      invalidVote();
    } else if (fingerprintID == ADMIN_FINGERPRINT_ID) {
      // Admin fingerprint detected
      adminMode();
    } else {
      // Valid voter fingerprint detected
      castVote(fingerprintID);
    }
  }
}

void castVote(int fingerprintID) {
  // Enable voting buttons and activate buzzer once
  enableVotingButtons();
  activateBuzzerOnce();

  // Wait for voter to select a candidate
  int selectedCandidate = waitForCandidateSelection();

  // Disable voting buttons
  disableVotingButtons();

  // Print the selected candidate's vote
  printVote(fingerprintID, selectedCandidate);

}

void invalidVote() {
  // Display invalid vote message
  Serial.println("Invalid Vote");
  
  // Activate buzzer three times
  for (int i = 0; i < 3; i++) {
    activateBuzzerOnce();
    delay(500);
  }
}

void adminMode() {
  // Calculate total voter turnout
  int totalVotes = votesCandidate1 + votesCandidate2 + votesCandidate3;
  
  // Determine winner based on votes
  int winner = determineWinner();
  
  // Print winner and voter turnout
  Serial.print("Winner: Candidate ");
  Serial.println(winner);
  Serial.println(candidateNames[winner - 1]); // winner - 1 to access array index
  Serial.print("Total Voter Turnout: ");
  Serial.println(totalVotes);
  
  // Print winner and voter turnout to thermal printer
  printAdminResults(winner, totalVotes);
}

void activateBuzzerOnce() {
  digitalWrite(BUZZER_PIN, HIGH);
  delay(100);
  digitalWrite(BUZZER_PIN, LOW);
}

void enableVotingButtons() {
  // Enable voting buttons for candidates
  pinMode(BUTTON_CANDIDATE_1, INPUT);
  pinMode(BUTTON_CANDIDATE_2, INPUT);
  pinMode(BUTTON_CANDIDATE_3, INPUT);
}

void disableVotingButtons() {
  // Disable voting buttons for candidates
  pinMode(BUTTON_CANDIDATE_1, OUTPUT);
  pinMode(BUTTON_CANDIDATE_2, OUTPUT);
  pinMode(BUTTON_CANDIDATE_3, OUTPUT);
}

int waitForCandidateSelection() {
  // Wait for user input from candidate buttons
  int candidateSelected = 0;

  while (candidateSelected == 0) {
    // Check each candidate button
    if (digitalRead(BUTTON_CANDIDATE_1) == HIGH) {
      candidateSelected = 1;
    } else if (digitalRead(BUTTON_CANDIDATE_2) == HIGH) {
      candidateSelected = 2;
    } else if (digitalRead(BUTTON_CANDIDATE_3) == HIGH) {
      candidateSelected = 3;
    }

    delay(100); // debounce delay or adjust as necessary
  }

  return candidateSelected;
}

void printVote(int fingerprintID, int selectedCandidate) {
  // Print the vote to the thermal printer
  printer.println("Voter ID: " + String(fingerprintID));
  printer.print("Vote: Candidate ");
  printer.println(candidateNames[selectedCandidate - 1]); // selectedCandidate - 1 to access array index
  printer.feed(2);

  // Determine which phone number to send SMS based on fingerprint ID
  char* phoneNumberToSend;
  if (fingerprintID == 2) {
    phoneNumberToSend = gsmPhoneNumber1;
  } else if (fingerprintID == 3) {
    phoneNumberToSend = gsmPhoneNumber2;
  } else if (fingerprintID == 4) {
    phoneNumberToSend = gsmPhoneNumber3;
  } else {
    // Handle other fingerprint IDs or errors
    return;
  }

  // Send SMS alert
  sendSMSAlert(phoneNumberToSend);
}

void sendSMSAlert(char* phoneNumber) {
  // Connect to GSM network
  Serial.println("Connecting to GSM network...");
  while (!gsmAccess.begin()) {
    Serial.println("Failed to connect to GSM network.");
    delay(700);
  }
  Serial.println("Connected to GSM network.");

  // Send SMS message
  char smsMessage[50];
  sprintf(smsMessage, "Your vote has been cast. Thank you.");
  sms.beginSMS(phoneNumber);
  sms.print(smsMessage);
  sms.endSMS();
  Serial.println("SMS sent.");

  // Disconnect from GSM network
  gsmAccess.shutdown();
}

void printAdminResults(int winner, int totalVotes) {
  // Print winner and total voter turnout to the thermal printer
  printer.println("Winner: " + String(candidateNames[winner - 1])); // winner - 1 to access array index
  printer.print("Total Voter Turnout: ");
  printer.println(totalVotes);
  printer.feed(2);
}

int determineWinner() {
  //Determine the candidate with the most votes
  int winner = 1; // Assume candidate 1 is initially the winner
  int maxVotes = votesCandidate1;

  // Check if candidate 2 has more votes
  if (votesCandidate2 > maxVotes) {
    winner = 2;
    maxVotes = votesCandidate2;
  }

  // Check if candidate 3 has more votes
  if (votesCandidate3 > maxVotes) {
    winner = 3;
    maxVotes = votesCandidate3;
  }

  return winner;

}

> GSM\GSM3SoftSerial.cpp.o: In function __vector_3':** **C:\Program Files (x86)\Arduino\libraries\GSM\src/GSM3SoftSerial.cpp:499: multiple definition of __vector_3'
SoftwareSerial\SoftwareSerial.cpp.o:C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SoftwareSerial/SoftwareSerial.cpp:227: first defined here
GSM\GSM3SoftSerial.cpp.o: In function GSM3SoftSerial::spaceAvailable()':** **C:\Program Files (x86)\Arduino\libraries\GSM\src/GSM3SoftSerial.cpp:487: multiple definition of __vector_4'
SoftwareSerial\SoftwareSerial.cpp.o:C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SoftwareSerial/SoftwareSerial.cpp:392: first defined here
GSM\GSM3SoftSerial.cpp.o: In function GSM3SoftSerial::spaceAvailable()':** **C:\Program Files (x86)\Arduino\libraries\GSM\src/GSM3SoftSerial.cpp:487: multiple definition of __vector_5'
SoftwareSerial\SoftwareSerial.cpp.o:C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SoftwareSerial/SoftwareSerial.cpp:392: first defined here
collect2.exe: error: ld returned 1 exit status

Welcome to the forum

You started a topic in the Uncategorised category of the forum when its description explicitly tells you not to

Your topic has been moved to a relevant category. Please be careful in future when deciding where to start new topics

Two of the libraries that you have #included are trying to use the same interrupt

In addition to that you are trying to use two instances of SoftwareSerial which I have never seen used successfully in anything except a trivial example

Which Arduino board are you using ?

Hi @adil3403. Please provide a detailed description of which GSM hardware you are using.

The "GSM" library you are using is for the long retired Arduino GSM Shield. It can't be used with other more common GSM radios. So if you aren't using the Arduino GSM Shield then there is no point in wasting time to fix the problem with the GSM library.

GSM 800L Module

Arduino Uno R3

4 instances!

That's the most I remember seeing, ever.

One of them isn't even used.

I stopped looking after I saw two

OK, so you can't use the "GSM" library. You can search the Arduino IDE Library Manager to find a nice collection of community created libraries for the SIMCom SIM800L GSM modem.

After installing the library that looks best to you, study the example sketches that are provided by the library author to learn how to correctly use the library. You will find them under the File > Examples menu in Arduino IDE.