I am trying to activate piezo speaker using SMS but I am having problem with the code. The SMS is received but the piezo buzzer did not activate as supposed to. Hardware I am using is Arduino UNO, Botletics SIM7000G Shield and Hologram sim card. I doubled-checked the hardware and can confirm everything is attached correctly. Can you please help me with my code? I attach a copy as attachment below as the code is too long to post here.
I do not see any reference to a buzzer in your attached code. You could also throw away a ton of that code since it looks like a generic example for multiple platforms and it could be included rather than attached.
#include "Adafruit_FONA.h" // https://github.com/botletics/SIM7000-LTE-Shield/tree/master/Code
#if defined(ARDUINO_SAMD_ZERO) && defined(SERIAL_PORT_USBVIRTUAL)
// Required for Serial on Zero based boards
#define Serial SERIAL_PORT_USBVIRTUAL
#endif
#define SIMCOM_7000 // SIM7000A/C/E/G
// For SIM7000 shield
#define FONA_PWRKEY 6
#define FONA_RST 7
#define FONA_TX 10 // Microcontroller RX
#define FONA_RX 11 // Microcontroller TX
#include <SoftwareSerial.h>
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;
// Use this one for 3G modules
#elif defined(SIMCOM_3G)
Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST);
#elif defined(SIMCOM_7000) || defined(SIMCOM_7500)
Adafruit_FONA_LTE fona = Adafruit_FONA_LTE();
#endif
uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);
uint8_t type;
char imei[16] = {0}; // MUST use a 16 character buffer for IMEI!
void setup() {
// while (!Serial);
pinMode(FONA_RST, OUTPUT);
digitalWrite(FONA_RST, HIGH); // Default state
pinMode(FONA_PWRKEY, OUTPUT);
powerOn(); // See function definition at the very end of the sketch
Serial.begin(9600);
Serial.println(F("SMS Response Test"));
Serial.println(F("Initializing....(May take several seconds)"));
fonaSS.begin(115200); // Default SIM7000 shield baud rate
Serial.println(F("Configuring to 9600 baud"));
fonaSS.println("AT+IPR=9600"); // Set baud rate
delay(100); // Short pause to let the command run
fonaSS.begin(9600);
if (! fona.begin(fonaSS)) {
Serial.println(F("Couldn't find FONA"));
while(1); // Don't proceed if it couldn't find the device
}
type = fona.type();
Serial.println(F("FONA is OK"));
Serial.print(F("Found "));
switch (type) {
case SIM800L:
Serial.println(F("SIM800L")); break;
case SIM7000E:
Serial.println(F("SIM7000E (European)")); break;
case SIM7000G:
Serial.println(F("SIM7000G (Global)")); break;
default:
Serial.println(F("???")); break;
}
// Print module IMEI number.
uint8_t imeiLen = fona.getIMEI(imei);
if (imeiLen > 0) {
Serial.print("Module IMEI: "); Serial.println(imei);
}
// Set modem to full functionality
fona.setFunctionality(1); // AT+CFUN=1
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");
}
char fonaNotificationBuffer[64]; //for notifications from the FONA
char smsBuffer[250];
char callerIDbuffer[32]; //we'll store the SMS sender number in here
int slot = 0; //this will be the slot number of the SMS
void loop() {
char* bufPtr = fonaNotificationBuffer; //handy buffer pointer
if (fona.available()) //any data available from the FONA?
{
int charCount = 0;
//Read the notification into fonaInBuffer
do {
*bufPtr = fona.read();
Serial.write(*bufPtr);
delay(1);
} while ((*bufPtr++ != '\n') && (fona.available()) && (++charCount < (sizeof(fonaNotificationBuffer)-1)));
//Add a terminal NULL to the notification string
*bufPtr = 0;
//Scan the notification string for an SMS received notification.
// If it's an SMS message, we'll get the slot number in 'slot'
if (1 == sscanf(fonaNotificationBuffer, "+CMTI: " FONA_PREF_SMS_STORAGE ",%d", &slot)) {
Serial.print("slot: "); Serial.println(slot);
// Retrieve SMS sender address/phone number.
if (! fona.getSMSSender(slot, callerIDbuffer, 31)) {
Serial.println("Didn't find SMS message in slot!");
}
Serial.print(F("FROM: ")); Serial.println(callerIDbuffer);
// Retrieve SMS value.
uint16_t smslen;
if (fona.readSMS(slot, smsBuffer, 250, &smslen)) { // pass in buffer and max len!
Serial.println(smsBuffer);
// Maybe turn on a relay, send a reading only with this password,
// or send GPS coordinates! Use your imagination!
const int buzzerPin = 9; // declaring the PWM pin</p><p>void setup() {
// Buzzer Code
Serial.begin(8600);
pinMode(buzzerPin, OUTPUT); //addigning pin to Output mode</p><p>}</p><p>void loop() {
tone(buzzerPin, 50);
delay(50);
noTone(buzzerPin);
delay(100);
}
}
else (strstr(smsBuffer, magicPass) != NULL) { // Only check if the password is somewhere in the text
sendText("Opening door!");
// Do stuff like digitalWrite(door, HIGH); or something
}
// Power on the module
void powerOn() {
digitalWrite(FONA_PWRKEY, LOW);
// See spec sheets for your particular module
#if defined(SIMCOM_2G)
delay(1050);
#elif defined(SIMCOM_3G)
delay(180); // For SIM5320
#elif defined(SIMCOM_7000)
delay(100); // For SIM7000
#elif defined(SIMCOM_7500)
delay(500); // For SIM7500
#endif
digitalWrite(FONA_PWRKEY, HIGH);
}