Novice advice

Hi Guys very new to this wonderful world of arduino and need some advice. The project I want to make is with a Arduino nano and all I want to do is have a vibration sensor connected to it with a buzzer and when there is no vibration detected for 1 minute the buzzer should start beeping in one second intervals. can some of the gurus help me in the right direction regarding the programming and hardware setup for this project.

Thank you
Marco

For that to work you need to save the value of miils() every time there is a vibration and then base your decision on the interval after the most recent buzz. Like this pseudo code

if (buzz is detected) {
   buzzMillis = millis();
}

if (millis() - buzzMillis >= intervalMillis) {
   // there has been no buzz during the interval
}

...R

Thank you Robin at the moment everything look like Spanish to me but I'm sure I'll get there.

marcovanyken:
Thank you Robin at the moment everything look like Spanish to me but I'm sure I'll get there.

Hardware:
My vibration sensor accepts 5V of power and spits out analog data. If you have a sensor like mine, just read its analog value. When you vibrate the sensor, the output increases.

Software:
When the sensor analog output increases over a certain threshold, that then set "buzzMillis = mills()"

Then just compare buzzMillis to Millis() and see if enough time has passed to trigger a beep function! :smiley:

Take it one step at a time!!! Hook-up your buzzer and turn it on & off with a simple program similar to the Blink Example.

Then, hook-up your vibration sensor and write another simple program to can read it and watch the readings/results with the [u]serial monitor[/u].

There are two different kinds of "noise makers". A piezo "transducer" is a speaker. You send it a signal and it converts the signal to sound and it can produce different frequencies/pitches (or more than one sound at once, like a regular speaker). You can directly drive a piezo transducer with the arduino using the tone() function.

A "buzzer" or "beeper" has a built-in sound generating circuit (or mechanism). You apply power and it makes sound. A car horn works the same way... You apply power and it makes noise. And, you can't use a car horn to play music from your car stereo.) Most buzzers/beepers can't be directly driven from the Arduino and they require a driver circuit.

Be careful if you buy a "cheap" beeper/transducer on eBay because they are often mis-described and you don't know what you're getting.

There are also different kinds of vibrations sensors, some digital and some analog, and some may require some additional circuitry. It depends on what kind of vibrations you're trying to sense.

For your program logic, you'll need to understand basic [u]and & or logic[/u] because you are combining two conditions... time and vibration. And, you'll need to understand conditional execution ([u]if-statements[/u], etc.).

You'll also need to know how to make a timer. You'll probably need to use the method form The Blink Without Delay Example, because a simple delay() pauses your program and you can't read your vibrations sensor or do anything else during the delay() period.

...I'm thinking a [u]while() loop[/u]. The basic logic would be, while time has not expired, you sit in the loop reading the sensor and resetting your timer whenever there is a vibration. If time expires without a vibration, you exit the loop and start making sound.

Then, you'll have to decide what happens next... Do you just keep buzzing forever? do you want to keep checking for a vibration and re-start the main loop if you detect a vibration?

DVDdoug:
Take it one step at a time!!! Hook-up your buzzer and turn it on & off with a simple program similar to the Blink Example.

Then, hook-up your vibration sensor and write another simple program to can read it and watch the readings/results with the [u]serial monitor[/u].

There are two different kinds of "noise makers". A piezo "transducer" is a speaker. You send it a signal and it converts the signal to sound and it can produce different frequencies/pitches (or more than one sound at once, like a regular speaker). You can directly drive a piezo transducer with the arduino using the tone() function.

A "buzzer" or "beeper" has a built-in sound generating circuit (or mechanism). You apply power and it makes sound. A car horn works the same way... You apply power and it makes noise. And, you can't use a car horn to play music from your car stereo.) Most buzzers/beepers can't be directly driven from the Arduino and they require a driver circuit.

Be careful if you buy a "cheap" beeper/transducer on eBay because they are often mis-described and you don't know what you're getting.

There are also different kinds of vibrations sensors, some digital and some analog, and some may require some additional circuitry. It depends on what kind of vibrations you're trying to sense.

For your program logic, you'll need to understand basic [u]and & or logic[/u] because you are combining two conditions... time and vibration. And, you'll need to understand conditional execution ([u]if-statements[/u], etc.).

You'll also need to know how to make a timer. You'll probably need to use the method form The Blink Without Delay Example, because a simple delay() pauses your program and you can't read your vibrations sensor or do anything else during the delay() period.

...I'm thinking a [u]while() loop[/u]. The basic logic would be, while time has not expired, you sit in the loop reading the sensor and resetting your timer whenever there is a vibration. If time expires without a vibration, you exit the loop and start making sound.

Then, you'll have to decide what happens next... Do you just keep buzzing forever? do you want to keep checking for a vibration and re-start the main loop if you detect a vibration?

Thank you dvddoug and all the others for you valuable input, you are right I'm trying something to complicated for someone just starting out with arduino and will get all the components but like dvddoug suggest start off by getting one thing working at a time and understand that first before moving on to the next. as for what happens after the buzzer started sounding, I would like to cancel it with a press of a button which will reset everything and start the loop from the beginning. But let me get the buzzer and vibration sensor going first then i'll get back in here for that setup. Thanks again for the help and guidance.

I would like to cancel it with a press of a button

That means that you must write non-blocking code so that the program is not stuck waiting for a delay() and won't respond to the button press till the delay() does time out. The Blink Without Delay example in the IDE (File, Examples, Digital) and the several things at a time thread will show how to do timing without using the delay() function. This is one of the most important concepts to learn, in my opinion.