How to ? - Buzzer & serial plotter

Hello,
I have a buzzer that buzzes every second the thing is i want to print the signal sent to that buzzer on both serial plotter and monitor but i'm not really sure on how to show the "input" of a sensor.
Also, if you guys have an idea on printing the time with it that would be nice

i'm on arduino nano btw and here's my code :

int buzzer = 9;
const int tempsBip = 100;
const int periode = 1000;
unsigned long periodePrecedente;
int val = 0;

void setup () {
  pinMode(buzzer, OUTPUT);
  Serial.begin(115200);
}

void loop () {
  val = analogRead(buzzer);
  if (millis() - periodePrecedente >= periode) {
    periodePrecedente += periode;
    tone(buzzer, 200, tempsBip);
    Serial.println(val);
  }
}

what i currently see :

Your post was MOVED to its current location as it is more suitable.

Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you also take a few moments to [url=https://forum.arduino.cc/index.php?topic=710766.0]Learn How To Use The Forum[/url].

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Hi, @galixou

Unfortunately you cannot display BOTH plotter and monitor screen at the same time.
The IDE can only do one or the other, not both together.

What does your monitor screen display?

What is the aim of your project?
What buzzer are you using?
If you connect the buzzer to 5V and gnd does it "buzz"?

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

Hi,
i wasn't talking about displaying the monitors at the same time.. thank you for your reply even though i resolved part of my problem
To answer your questions :

  • my monitor screen displays the same as the serial plotter but numerically (0 or 1) accordingly to the 3sec delay between buzzes
  • my project is to build and code a small HRM and the buzz function is just a part of it
  • i'm using a piezo buzzer
  • yes why ?

But if you have some info on printing the time on the serial plotter, i'm always listening.

Thanks again.. Galixou... :grinning: :+1: :coffee: :fr:

Then you don't need tone, the buzzer makes its own sound.
5V ON buzzzzzzzz or beeeeeeepp, 0V OFF

"HRM"? SO many acronyms these days.

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

haha :slight_smile: ... but i do have to use tone if i want to input what frequency i want the buzzer to buzz right ? also HRM stands for heart rate monitor..
Thanks for answering tom :+1:

No. There are two things that look very much alike.

One is an active beeper, just apply 5 volts and ground or an i/o pin output and it will make sound.

The other is a passive component. Call it what you want, but for it to make sound an alternating voltage must be applied, the frequency of that is what tone you hear. The waveform is created for you by calling tone().

You can send tone to an active buzzer or beeper, but you get some odd effects as you are essentially turning the one tone it is meant to make off and on very rapidly. Can't imagine dancing to that.

Test your beeper with 5 volts briefly. If it beeps, not tunable, don't use tone, just HIGH and LOW. If it clicks with each brief contact it is a speaker and should be driven with tone, where you can select the frequency.

HTH

a7