Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino UNO GSM-Controlled Melody Player

Image of Arduino UNO GSM-Controlled Melody Player

Circuit Documentation

Summary of the Circuit

This circuit consists of an Arduino UNO microcontroller, a GSM SIM900 module, and a Piezo Speaker. The Arduino UNO is used as the central processing unit, controlling the GSM module for SMS communication and driving the Piezo Speaker to play a melody when a specific SMS message is received. The GSM module is responsible for cellular communication, allowing the circuit to send and receive SMS messages. The Piezo Speaker is an output device that produces sound in response to an electrical signal from the Arduino UNO.

Component List

Arduino UNO

  • Description: A microcontroller board based on the ATmega328P.
  • Purpose: Acts as the central controller for the circuit, interfacing with the GSM module and driving the Piezo Speaker.
  • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0-A5, SCL, SDA, AREF, D0-D13.

Piezo Speaker

  • Description: An electronic device that emits sound when an electrical signal is applied.
  • Purpose: To produce a sound or melody when triggered by the Arduino UNO.
  • Pins: pin1, pin2.

GSM SIM900

  • Description: A GSM/GPRS module that allows cellular communication.
  • Purpose: To enable SMS communication for the circuit.
  • Pins: A5, A4, A3, A2, A1, A0, 5V, GND, 3.3V, RESET, D0-D13, AREF.

Wiring Details

Arduino UNO

  • 5V: Connected to the 5V pin of the GSM SIM900 module.
  • GND: Connected to the GND pin of the GSM SIM900 module and pin1 of the Piezo Speaker.
  • D8: Connected to pin2 of the Piezo Speaker.
  • D1: Connected to D0 of the GSM SIM900 module (TX -> RX).
  • D0: Connected to D1 of the GSM SIM900 module (RX -> TX).

Piezo Speaker

  • pin1: Connected to GND of the Arduino UNO.
  • pin2: Connected to D8 of the Arduino UNO.

GSM SIM900

  • 5V: Connected to the 5V pin of the Arduino UNO.
  • GND: Connected to the GND pin of the Arduino UNO.
  • D0: Connected to D1 of the Arduino UNO (RX -> TX).
  • D1: Connected to D0 of the Arduino UNO (TX -> RX).

Documented Code

/*
 * This Arduino Sketch communicates with a GSM module to receive an SMS message.
 * When a specific message is received, it triggers the piezo speaker connected
 * to pin D8 and GND of the Arduino UNO to play a melody.
 */

#include <SoftwareSerial.h>

// Pin connected to the piezo speaker
const int speakerPin = 8;

// GSM module pins
const int rxPin = 0;
const int txPin = 1;

// Create a software serial port for GSM communication
SoftwareSerial gsmSerial(rxPin, txPin);

// Notes of the melody (frequencies in Hz)
int melody[] = {
  262, 196, 196, 220, 196, 0, 247, 262
};

// Note durations: 4 = quarter note, 8 = eighth note, etc.
int noteDurations[] = {
  4, 8, 8, 4, 4, 4, 4, 4
};

void setup() {
  // Initialize serial communication with the GSM module
  gsmSerial.begin(9600);
  // Wait for the GSM module to initialize
  delay(1000);
  // Set the GSM module to text mode
  gsmSerial.println("AT+CMGF=1");
  delay(100);
  // Set the GSM module to show new messages
  gsmSerial.println("AT+CNMI=1,2,0,0,0");
  delay(100);
}

void loop() {
  // Check if there is any data from the GSM module
  if (gsmSerial.available()) {
    String message = gsmSerial.readString();
    // Check if the message contains the trigger word
    if (message.indexOf("PLAY") >= 0) {
      playMelody();
    }
  }
}

void playMelody() {
  // Iterate over the notes of the melody
  for (int thisNote = 0; thisNote < 8; thisNote++) {
    // Calculate the note duration
    int noteDuration = 1000 / noteDurations[thisNote];
    tone(speakerPin, melody[thisNote], noteDuration);
    // Pause for the note's duration plus 30% to distinguish notes
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // Stop the tone playing
    noTone(speakerPin);
  }
  // Add a delay before repeating the melody
  delay(1000);
}

This code is designed to run on the Arduino UNO microcontroller. It sets up a software serial connection to communicate with the GSM SIM900 module. Upon receiving an SMS containing the word "PLAY", the Arduino triggers the Piezo Speaker to play a predefined melody. The melody and its timing are defined by arrays, and the playMelody function controls the duration and pitch of each note played by the speaker.