Hot answers tagged

6

There is two kinds of buzzers - active and passive Passive buzzer means they can be operated by applying just logic high to + and low to ground. Digitalwrite function will do this job Active buzzers needs pulses to make sound. Sound produced depends on the frequency. Your buzzer might be a passive one. You can make a symphony by applying different ...


4

You connected the piezo to pin 1? Chose other pin. Pin 1 is Serial TX. You 'pump' PWM to USB. tone() function will make sound no matter if you have a delay there. You set 1 sec with 1000 as third parameter. It will sound 1 sec and the turn of. You do not need the delay() and noTone(). 500 is low frequency. If it sounds only one second, can you catch it? ...


4

An int can't hold 1000000. It is a signed 16-bit variable, which means it can only hold between -32768 and +32767. To store larger numbers you need to use long, or unsigned long which are signed and unsigned 32-bit variables.


3

You have a distinct set of requirements that you could turn into a sketch yourself. I'm guessing you have never written a program before, in which case the problem really is you don't know how to do what you want to. So, break the problem down into small chunks. The less complex a problem the more likely you are to find a generic solution on the web that ...


3

you will need to implement a edge sensor. Add a previousTouchsensorState to the globals and replace the if where you check the sensor state with: if(previousTouchsensorState == LOW && touchsensorState == HIGH) { // check if the touch sensor is pressed and wasn't the last time though the loop. // If it is, the ...


3

You can just have a variable that remembers whether the alarm is supposed to be on or off. Let's call it alarm_on. Then: bool alarm_on; static void start_alarm() { alarm_on = true; } static void stop_alarm() { noTone(); alarm_on = false; } void loop() { if (alarm_on) alarm(); if (some_condition()) start_alarm(); if (some_other_condition()) ...


3

To sound a passive buzzer, use Arduino tone() function. If you set the pin HIGH the piezo surfaces are pulled together (or pulled away). It is what makes one click but nothing more. To make a tone the input must oscillate at right frequency. PWM is one way how to do a beep. Use tone() function to generate tones of desired frequency. Your analogWrite(255) is ...


3

Exactly as @MichelKeijzers wrote the issue is caused by "IRremote" using same timer as "Tone" and the solution to this problem is a little dirty. Since Tone is included in ArduinoCore (and compiled) we can't easilly modify it so the only thing that worked for me is to modify boarddefs.h file of IRremote library. Since it's code is easilly available after ...


3

You can use the output of your regulator as the reference voltage for your analog readings. That way, no matter what the voltage you voltage divider for the thermistor uses, the "upper" voltage that the ADC uses is always the same as the thermistor's voltage. Simply connect the output of the regulator to the AREF pin, and set the ADC to use the external ...


2

Both the IRRemote library and the tone command use the same timer. You can't use them both together without modifying one of them to use a different timer. And that means looking at the source code for them both.


2

A more low-tech solution might be better. For example, a couple of light beams across the doorway to the kitchen. An human would block both of them as they passed, and a dog only the lower one. You could sound an alarm if the lower one is broken, and the upper one is not broken (within a second). Or do something with infra-red transmitters / receivers. ...


2

First things first: do you know that a GPS can locate your dog accurately enough in your home? Basically, even with a good GPS receiver, the best accuracy you can expect (using off-the-shelf receivers, non-military or DGPS) is maybe 3 m. Typical performance is maybe 4 m, and indoors it will be even worse. The point is, your dog could be 5 m away from your ...


2

It's very hard to know from your question what you are having trouble with. I have a piano and I can hit the keys, but it takes me a long time to hit them in the right order and with the right timings to create a new symphony. Anyway, if creating the sounds is the problem, have you looked at the Tone library? Different alarms have different sounds. I ...


2

We have done it. Thanks for the help Harper Shelby. We combined the Blink Without Delay example with our original code: int buzzerPin = 9; // the number of the buzzer pin const int BlueLEDpin = 5; const int RedLEDpin = 7; float sinVal; // Define a variable to save sine value int toneVal; // Define a variable to save sound frequency ...


2

Your problem is the delay() in your BlueLED() and RedLED() calls. To get more "simultaneous" activities, you'd need to use timer interrupts to implement those delays. It's a lot more complex conceptually, but the right way to do it.


2

What you want is not to check the distance but to check that the distance condition changed. static boolean present = false; Inside loop: if (present == false && distance <= 150){ personPresent(); present = true; } else if(present == true && distance > 150) { personAbsent(); present = false; }


2

You set a timestamp = millis() when the button is pushed and then you disable the buzzer only when millis() - timestamp > timeout if (touchsensorState == HIGH) { // buzzer will emit sound: digitalWrite(buzzer, HIGH); timestamp = millis(); } if(millis() - timestamp > timeout) { // buzzer will not sound: digitalWrite(buzzer, LOW); }...


2

While there are better ways to do this, as pointed out by other posters, for what you're trying to learn right now, your program (almost!) works just fine. You'll need the more advanced techniques as you progress to more complex programs. But for now, I made a couple of edits to your program to get you going: The most important one was to use analogWrite() ...


2

As it sounds like you do not own the buzzer (it is part of the appartment), someone may not like you directly connecting to it. If this is a classic buzzer with an electromagnet, consider using a Hall Effect Sensor. The magnetic field generated by the buzzer may be able to activate the Hall Effect Sensor and inform the Arduino the buzzer has been activated....


2

The piezo element acts like a capacitor, not like a more-or-less resistive element as in a conventional speaker. You need to discharge the capacitor during the 'off' time or you just get a click and little sound after that. That's why your resistor helps. Push-pull would be much better, and an H-bridge would give you much more output (maybe too much for the ...


2

In addition to Majenko's answer (an int on this platform can't hold a number greater than 32767) you have a second problem. You are evidently trying to make a middle C tone (261.6 Hz) by toggling a pin with a period of 1/261.6 seconds. However your Serial.println takes time. In particular at 9600 baud each byte you send will take 1/960 of a second (because ...


2

When I have a state-machine problem such as this, I diagram it first - here's mine, based on how I understand your requirements: Most state machines are only activated when an external event happens, so not much happens inside the state-boxes. But since your application only does this one thing, you can actually do your testing inside the states. This is ...


2

The tone() command uses Timer2 to generate the square wave (it triggers an interrupt which toggles an IO pin). However Timer2 is also used to generate the PWM signal on pins 3 and 11. Thus you cannot use tone() and PWM on pins 3 or 11 simultaneously. The simple fix: use PWM from pins 5, 6, 9 or 10 to control your fan.


2

Take the regulator output to another analog input. Read that just before you read the thermistor. Use that voltage in your voltage divider calculation. The buzzer activity should be the same (ideally, off) during both readings.


2

To pack the comments into a proper answer to the question: As Majenko stated in the comments, Tinkercad is a simulation. The codes doesn't get compiled and uploaded to hardware. Instead Tinkercad interprets the code on the fly. Simulations are not perfect clones of the real hardware, so you cannot expect the same performance from it as from the real Arduino....


1

Have a look here, on how you can use different peripherals in a non-blocking manner. The following code is from the link: // These variables store the flash pattern // and the current state of the LED int ledPin1 = 12; // the number of the LED pin int ledState1 = LOW; // ledState used to set the LED unsigned long previousMillis1 = 0; ...


1

There are different kinds of buzzers. The simplest one is just a piezoelectric transducer in a plastic casing. You can drive it directly by an arduino pin since its impedance is high. It will work fairly well for high frequencies, but don't expect any bass from it. Another type of buzzer is a piezoelectric transducer connected to a simple oscillator circuit ...


1

Firstly, congratulations! you've taken your first step into the very rewarding world of micro-controllers. I teach robotics at a local university, so it's always nice to see when the light-bulb goes on and people start understanding. As mentioned above, the blink without delay code is a good start. Good code should also be expandable in case later you ...


1

If you're not specifically trying to make the arduino itself do the decoding and playback, you can get something like the Mini DFPlayer which would let you do essentially what you're asking for and offloads the decoding and playback so your arduino can do something else while the audio is playing.


1

static boolean didItAlready = false; if(distance > 50 && !didItAlready){ doIt(); didItAlready = true; } You simply need a variable to keep track of whether or not it has been done. If and when you want to do the action again then set your variable back to false.


Only top voted, non community-wiki answers of a minimum length are eligible