I make a simple circuit with an:

  • Arduino Nano
  • HC-12 Long distance radio module
  • HC-12 Antenna
  • 1000 uF Capacitor
  • Buzzer
  • 220 Ohm Resistor

I need that the buzzer emits a noise when Arduino receives specific string from HC-12. Everything work as expected but I have a strange problem that I can't fix. During the data receiving phase, I hear a strange noise sound from the buzzer. Is something like the good old modem sound. Seem an interference or similar but is something different because I move the buzzer to 20 cm away from my board and the problem still exists.

Probably is some kind of error on my Arduino code or in my wiring, the sound can be heard before the warningTone() (that you can see inside the code) function that is the call that emits the correct sound.

Some background information: the string can be received more than one time in a single transmission, during the same transmission each string is separated by newline so I can have something like:

AL_S001

AL_S001

AL_S001

etc..

Even 100 time for same transmission (data come from an HC-SR501 with is trigger set to repeatable, the problem exists also with trigger set as "single trigger mode"), but I need to sound the speaker only once per event, if the event is repeated after 10 seconds then I need to sound again.

I did the tests to try to found a solution: - Move the buzzer 20cm away from the board - Create a var in the code that checks if the sound is currently emitted (something like a mutex), in this way I try to execute the warningTone() function only once per loop

How can I solve this problem? I already reach my target because the sound is loud and clear when produced.. but I want to understand what cause the strange sound for my own knowledge.

Below the schematic and code, please be patient with me. Probably my schematics is a nightmare, I know, but I'm a self-learner and everything I know on electronics field and English language came from my own self-study...

#include <SoftwareSerial.h>

//--- Begin Pin Declarations ---//
const byte buzzerPin = 8;

//pin HC-12 module
const byte HC12RxdPin = 2;
const byte HC12TxdPin = 3;
const byte HC12SetdPin = 4;
//--- End Pin Declarations ---//

//--- Begin variable declarations ---//
char byteIn;                                        // Temporary variable
String HC12ReadBuffer = "";                         // Read/Write Buffer 1 -- HC12 
String SerialReadBuffer = "";                       // Read/Write Buffer 2 -- Serial
boolean serialEnd = false;                          // Flag for End of Serial String
boolean HC12End = false;                            // Flag for End of HC12 String
boolean soundStart = false;                         // Flag that allow only one sound even if multiple events


// Create Software Serial Port for HC12
// Software Serial ports Rx and Tx must be inverted so HC12 Rx go as Tx and Tx go as Rx 
SoftwareSerial HC12Serial(HC12TxdPin,HC12RxdPin);

/////////////////////////////
//SETUP
void setup(){
  Serial.begin(9600);
  pinMode(buzzerPin, OUTPUT);                    // Set buzzer - pin 8 as an output

  HC12ReadBuffer.reserve(128);                   // Reserve 128 bytes for Serial message input

 //enable radio module
 Serial.println("Activate Radio Module"); 
 pinMode(HC12SetdPin, OUTPUT);                   // Output High for Transparent / Low for Command
 digitalWrite(HC12SetdPin, HIGH);                // Enter Transparent mode
 delay(80);
 HC12Serial.begin(9600);  
 HC12Serial.listen();

 //send sound to user for confirm system activation
 tone(buzzerPin, 1000);                         // Send 1KHz sound signal...
 delay(1000);                                   // ...for 1 sec
 noTone(buzzerPin);                             // Stop sound...
}

////////////////////////////
//LOOP
void loop(){
  while (HC12Serial.available()) {                  // If Arduino's HC12 rx buffer has data
    byteIn = HC12Serial.read();                     // Store each character in byteIn
    HC12ReadBuffer += char(byteIn);                 // Write each character of byteIn to HC12ReadBuffer
    Serial.println( char(byteIn));
    if (byteIn == '\n') {                           // At the end of the line
      HC12End = true;                               // Set HC12End flag to true.
    }
  }
     if(!soundStart){
 if (HC12End) {
    HC12ReadBuffer.trim();
    Serial.println("data:" + HC12ReadBuffer);        
    if( HC12ReadBuffer == "AL_S001"){
       soundStart = true;      
       warningTone();
       soundStart = false;
    }
    HC12ReadBuffer = "";                            // Empty Buffer
    HC12End = false;                                // Reset Flag
 } 
     }
}

void warningTone(){ 
        tone(buzzerPin, 1000); // Send 1KHz sound signal...
        delay(1000);        // ...for 1 sec
        tone(buzzerPin, 1500); // Send 1KHz sound signal...
        delay(1000);        // ...for 1 sec
        tone(buzzerPin, 1000); // Send 1KHz sound signal...
        delay(1000);        // ...for 1 sec
        tone(buzzerPin, 1500); // Send 1KHz sound signal...
        delay(1000);        // ...for 1 sec
        noTone(buzzerPin);     // Stop sound...  

}

2017-11-10 - Last version of my breadboard: Following all suggestion I change some routing: 1- Move the 1000 uF capacitor closer as possible to the radio module 2- Change buzzer pin to be farther as possible from the capacitor 3- Move the buzzer GND to another pin from the pin used by the radio module

Also, I update the firmware with the changes suggested.

Still no luck.. the strange "transmission" sound is still here :(

enter image description here

06-12-2017 UPDATE - Hi-Res image of the breadboard and video with the strange sound

enter image description here

This is the video, the only sound that I expect is the dual tone starting around second 3 the previous sound is unexpected and seem some sort of noise

  • what is the voltage across the buzzer when it is quiet? – jsotola Nov 5 '17 at 1:13
  • the HC-12 module probably draws a lot of current and it is feeding into the buzzer because of the resulting voltage drop. ... try powering the HC-12 from a separate power supply, such as a batttery. ... or put a bigger cap across the HC-12 power pins ... note: your HC-12 module power pins appear to be reversed. – jsotola Nov 5 '17 at 1:17
  • Hi, thank you very much for you reply, you are right in schematics i make a mistake about vcc and gnd but in my own real board all connection are placed in the right way... the image was wrong because i did some change for finding a better placement for capacitor. Currently i use a 1000uF Capacitor, what is the size that you suggest for try to solve the problem? i prefer to have only one power source to maintain the assembly smallest as possibile! – Marco Nov 5 '17 at 14:41
  • Please connect one wire the buzzer through the resistor to output Arduino. Connect another wire to the ground. Use separate wires to connect buzzer and HC-12 to a power supply. – AltAir Nov 5 '17 at 15:02
  • @AltAir hi, the D8 pin that control the buzzer is already connected through a 220 ohm resistor.. i did something wrong? – Marco Nov 5 '17 at 15:47

Please try the following code:

#include <SoftwareSerial.h>

const byte buzzerPin = 8;
const byte HC12RxdPin = 2;
const byte HC12TxdPin = 3;
const byte HC12SetdPin = 4;

char byteIn;                                     // Temporary variable
String HC12ReadBuffer = "";                      // Read/Write Buffer 1 -- HC12

SoftwareSerial HC12Serial(HC12TxdPin, HC12RxdPin);

void setup() {
  Serial.begin(9600);
  pinMode(buzzerPin, OUTPUT);                    // Set buzzer - pin 8 as an output
  HC12ReadBuffer.reserve(128);                   // Reserve 128 bytes for Serial message input
  pinMode(HC12SetdPin, OUTPUT);                  // Output High for Transparent / Low for Command
  digitalWrite(HC12SetdPin, HIGH);               // Enter Transparent mode
  delay(80);
  HC12Serial.begin(9600);
  Serial.println("Radio Module Activated");
  //send sound to user for confirm system activation
  tone(buzzerPin, 1000);                         // Send 1KHz sound signal...
  delay(1000);                                   // ...for 1 sec
  noTone(buzzerPin);                             // Stop sound...
}

void loop() {
  HC12ReadBuffer = "";                            // Empty Buffer
  while (HC12Serial.available()) {                // If Arduino's HC12 rx buffer has data
    byteIn = HC12Serial.read();                   // Store each character in byteIn
    HC12ReadBuffer += char(byteIn);               // Write each character of byteIn to HC12ReadBuffer
  }
  HC12ReadBuffer.trim();
  Serial.println("data:" + HC12ReadBuffer);
  if ( HC12ReadBuffer == "AL_S001") {
    HC12Serial.stopListening();
    warningTone();
    HC12Serial.listen();
  }
}

void warningTone() {
  tone(buzzerPin, 1000); // Send 1KHz sound signal...
  delay(1000);        // ...for 1 sec
  tone(buzzerPin, 1500); // Send 1KHz sound signal...
  delay(1000);        // ...for 1 sec
  tone(buzzerPin, 1000); // Send 1KHz sound signal...
  delay(1000);        // ...for 1 sec
  tone(buzzerPin, 1500); // Send 1KHz sound signal...
  delay(1000);        // ...for 1 sec
  noTone(buzzerPin);     // Stop sound...
}

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.