Alarm with multiple triggers, buzzer and LEDs. Feasible?

Hi all!

My first post on this forum and a complete noob (from Sweden non the less), so please be gentle with me. :blush:

I had the ambition to start learning Arduino about a year ago but things got in the way. Now I really want to get going so I'm starting to think about fun projects.

One of these projects is monitoring system for my inboard boat engine. I'm writing this post looking for a "go-no go" from the collective knowledge of the forum. If I get a "Go" I will try to do my own research to solve the programming but if I get a "No-go" it will save me the hassle.

OK, so here is what I'd like to do with the Arduino:

The engine have three sensors:

  1. Oil pressure
  2. Water temperature
  3. Cooling water flow

All these are switches. NO/NC as follows:

  1. NC
  2. NO
  3. NC

When the ignition is turned on with engine not running the oil pressure and water flow is both 0 and the temperature is not over the limit. In this configuration I'd like a buzzer to sound and LEDs indicating oil pressure and water flow failure. The LED indicating temperature should be off.

As soon as the engine is started, and oil pressure and water flow is normal the buzzer and LEDs should be off.

During normal operation all switches are in open mode. If a problem occurs with one (or more) of the three parts the switch(es) closes and the buzzer and corresponding LED should activate.

I realise that the engine electrical system is 12V and that the Arduino uses 5V. I will adress that issue later if you guys think that the programming is possible. Just imagine that the engine electrical system is 5V for now. :slight_smile:

Thankful for all input and suggestions.

Best regards
/Fred

I can see no problem with this project. The Arduino on-board voltage regulator can connect to 12V, and the switches to Gnd and an input pin and pullup resistor to 5V.

Really?! That would totally be the easiest way to solve the wiring since the cables from the engine to the instrument panel is already there (at least most of them!).

I'm reading up on pull up resistors now...did I mention that I'm a total noob? :blush:

I'm thinking I need a relay for the buzzer, since I think it draws quite a bit of current. The LEDs can be non 12V ones so they can be powered by the Arduino.

So programming will not be a problem once I study some more?

careful with car 12 V. it can be more and 12 V is max for Arduino.

Juraj:
careful with car 12 V. it can be more and 12 V is max for Arduino.

This is a boat, but you are correct. The voltage with engine running and alternator charging is 14,4V, so I guess I need some kind of voltage regulator. One easy way would be to use a USB-carger in a cigarette lighter outlet hidden under the dash.

A loud buzzer can draw much current, so a relay is a good choice. But relay coils also can draw much current, get a relay module with a digital input.

Most Arduino voltage regulators accept more than 12V input, see the data sheets. Higher voltage limits the overall current, due to higher power dissipation. No problem with the current project, otherwise a Z-diode can reduce the voltage drop on the regulator. Did you already chose an Arduino board?

DrDiettrich:
A loud buzzer can draw much current, so a relay is a good choice. But relay coils also can draw much current, get a relay module with a digital input.

Most Arduino voltage regulators accept more than 12V input, see the data sheets. Higher voltage limits the overall current, due to higher power dissipation. No problem with the current project, otherwise a Z-diode can reduce the voltage drop on the regulator. Did you already chose an Arduino board?

I will check the specs for the buzzer before testing it with the Arduino.

I have an Arduino board, but I don't think I will use that one for this project. It's my first one, and it will be used as a test bench with a breadboard. Are there boards that are better suited for a project like this?

A Pro Mini or Nano will be sufficient.

I would look at protecting inputs to the Arduino in this sort of application , to give reliability - have a look at input circuits used in "ruggedunio" for example or use onto isolators.

Also have a look at using the watchdog timer to reboot it if it should "hang".

DrDiettrich:
A Pro Mini or Nano will be sufficient.

The smaller the better. I have seen that there are smaller boards (with less functionality?) that would be nice. I'll have to get a weather proof case with outside connectors somehow...but this is far in the future.

hammy:
I would look at protecting inputs to the Arduino in this sort of application , to give reliability - have a look at input circuits used in "ruggedunio" for example or use onto isolators.

Also have a look at using the watchdog timer to reboot it if it should "hang".

Thank you for the suggestions, I will look into that.

The dash of the boat have meters that show temperature and oil pressure, so this is more of a redundant/extra warning system. The audible signal is so I won't have to keep an eye on the dash all the time and the LEDs is just to help me to quickly identify which meter to check if I hear the buzzer go off.

Also, since two of the triggers will be tripped every time I start the engine it will be sort of self diagnostic. This is a pleasure craft so it will not run for hours after hours.

This is a good project to build up on a breadboard in order to ‘find your feet’.
All the small Arduino will do what you are looking for, but don’t go too small, or you’ll,run out of pins to add features.
Before you connect parts together, make sure you understand the matching of voltages, current limits - and ensure your grounds are tied together.

Thank you all for the confirmation that Arduino can handle what I'm thinking of doing and that it's a good project for me to progress from noob status. :slight_smile:

I'll try to do some connecting and programming on my own first...maybe (probably) I'll come back with more specific questions.

As anticipated I'm back! :smiley:

So far as I've been able to connect and program a simple test setup. This is compiled of one push button, one LED and a buzzer. When the button is pressed the LED lights up and the buzzer sounds.

I found the schematics and the sketch here: multiwingspan

Following that I got everything to work right away.

Next step is to incorporate one more push button and one more LED to get better understanding of how the code is constructed and what commands rule what happens.

I have gotten as far as I do understand what the three parts of the code are. "int" sets constants, "void setup" sets if the pins are inputs or outputs and "void loop" is the program itself. And this is where I get stuck.

The sketch in the link above is, lets call it, a "one layer" program. One button lights one LED and fires a buzzer. It's easy to follow the code to see what the different commands do. But how do I add another "layer" to this program?

In the attached sketch below I have added what I think I should do to incorporate one more button and one more LED in the "int"-section and the "void setup"-section (marked in blue). Is this the correct way of doing it?

If so, what should I do in the "void loop"-section? What I want is the two buttons to be independent from each other, light up their separate LED and sound the buzzer.

int buzzerPin = 13;
int buttonPin1 = 1;
int ledPin1 = 2;
[color=blue]int buttonPin2 = 3;
int ledPin2 = 4;[/color]
const int toneFreq = 523;

void setup()
{
pinMode(buzzerPin, OUTPUT);
pinMode(ledPin1, OUTPUT);
pinMode(buttonPin1, INPUT);
[color=blue]pinMode(ledPin2, OUTPUT);
  pinMode(buttonPin2, INPUT);[/color]
}

void loop()
{
int buttonState = digitalRead(buttonPin1);
if (buttonState==LOW)
{
  digitalWrite(ledPin1, HIGH);
  tone(buzzerPin, toneFreq);
} 
else
{
  digitalWrite(ledPin1, LOW);
  noTone(buzzerPin);
}
}

Never give up, right?! I managed to figure it out by googling similar projects. I found a "two button, two LEDs"-projekt and learned about the "else if"-command. I used this twice and now it seems to work as I wanted. Note that I have only tested this in TinkerCAD Circuits (I just love that site! :D), I have yet to test it IRL with my Arduino test rig. One thing I'm concerned about is what will happen if two buttons are pressed at the same time, and this isn't possible to test in TinkerCad.

EDIT: I did a test where I swapped one of the buttons with a jumper cable, and that showed that it doesn't work as I want with two of the buttons pressed. The jumper cable circuit lights its LED and the buzzer. When I pressed one of the other buttons its LED did not light up. Any suggestions?

This is what the code looks like now:

int buzzerPin = 13; //Set buzzer pin 13
int buttonPin1 = 1; //Set button 1 to pin 1
int ledPin1 = 2; //Set LED 1 to pin 2
int buttonPin2 = 3; //Set Button 2 to pin 3
int ledPin2 = 4; //Set LED 2 to pin 4
int buttonPin3 = 5; //Set button 1 to pin 5
int ledPin3 = 6; //Set LED 1 to pin 6
const int toneFreq = 523; //Set buzzer freqency to 523

void setup()
{
pinMode(buzzerPin, OUTPUT); //Set Buzzer pin to Output
pinMode(ledPin1, OUTPUT); //Set LED 1 pin to Output
pinMode(buttonPin1, INPUT); //Set Button 1 to input
pinMode(ledPin2, OUTPUT); //Set LED 2 pin to Output
pinMode(buttonPin2, INPUT); //Set Button 2 pin to input
pinMode(ledPin3, OUTPUT); //Set LED 3 pin to Output
pinMode(buttonPin3, INPUT); //Set Button 3 pin to input
}

void loop()
{
int buttonState1 = digitalRead(buttonPin1);
int buttonState2 = digitalRead(buttonPin2);
int buttonState3 = digitalRead(buttonPin3);
if (buttonState1==LOW)
{
 digitalWrite(ledPin1, HIGH);
 tone(buzzerPin, toneFreq);
}
else if (buttonState2==LOW){
 digitalWrite(ledPin2, HIGH);
 tone(buzzerPin, toneFreq);
}
else if (buttonState3==LOW){
 digitalWrite(ledPin3, HIGH);
 tone(buzzerPin, toneFreq);
} 
else{
 digitalWrite(ledPin1, LOW);
 digitalWrite(ledPin2, LOW);
 digitalWrite(ledPin3, LOW);
 noTone(buzzerPin);
 }
}

You’re doing well...
Your first post has a hint.
You want the buttons and LEDs to operate independently, so break the code for the second button/LED away from button #1
You can have two separate if/else conditions (not interdependent).

 if (button1) {
  do this 
else
  do this
}

if (button2) {
  do this 
else
  do this
}

In it simplest form, the processor runs faster than you’ll ever see, but as you grow more confident - you’ll see reasons to improve on this basic idea.

Hey hey! It works!! :smiley:

Now the three circuits are mostly independent from each other. Only thing that isn't is that the tone of buzzer varies depending on how many of the buttons are pressed/LED are lit.

This is not critical, since in the final version of this thing I will be using a relay to power the buzzer. However it would be interesting to know why this happens in the test rig. Is it that the output pin doesn't have the voltage it need to give the buzzer a stable "signal"?

I'd like to thank all of you guys for your help and patience in guiding me through this project. I wasn't sure I was going to be able to do this, and I know I wouldn't have been without your help! :smiley:

Next project I'm thinking about is doing a laser tripwire system to light up LED strips in the basement stairs. It will have two lasers (one on top of the stairs and one on the bottom), a time delay and ambient light sensor. I might be biting off more than I can chew! ;D

Oh, forgot to attach the final sketch:

int buzzerPin = 12; //Set buzzer pin 12
int buttonPin1 = 1; //Set button 1 to pin 1
int ledPin1 = 2; //Set LED 1 to pin 2
int buttonPin2 = 3; //Set Button 2 to pin 3
int ledPin2 = 4; //Set LED 2 to pin 4
int buttonPin3 = 5; //Set button 3 to pin 5
int ledPin3 = 6; //Set LED 3 to pin 6

void setup()
{
pinMode(buzzerPin, OUTPUT); //Set Buzzer pin to Output
pinMode(ledPin1, OUTPUT); //Set LED 1 pin to Output
pinMode(buttonPin1, INPUT); //Set Button 1 to input
pinMode(ledPin2, OUTPUT); //Set LED 2 pin to Output
pinMode(buttonPin2, INPUT); //Set Button 2 pin to input
pinMode(ledPin3, OUTPUT); //Set LED 3 pin to Output
pinMode(buttonPin3, INPUT); //Set Button 3 pin to input
}

void loop()
{
int buttonState1 = digitalRead(buttonPin1);
int buttonState2 = digitalRead(buttonPin2);
int buttonState3 = digitalRead(buttonPin3);
if (buttonState1==LOW){
digitalWrite(ledPin1, HIGH);
digitalWrite(buzzerPin, HIGH);
}
else
digitalWrite(ledPin1, LOW);{
 digitalWrite(ledPin2, LOW);
 digitalWrite(ledPin3, LOW);
 digitalWrite(buzzerPin, LOW);
 }

if(buttonState2==LOW){
 digitalWrite(ledPin2, HIGH);
 digitalWrite(buzzerPin, HIGH);
 }
else
digitalWrite(ledPin1, LOW);{
 digitalWrite(ledPin2, LOW);
 digitalWrite(ledPin3, LOW);
 digitalWrite(buzzerPin, LOW);

}
if (buttonState3==LOW){
 digitalWrite(ledPin3, HIGH);
 digitalWrite(buzzerPin, HIGH); 
} 
else
digitalWrite(ledPin1, LOW);{
 digitalWrite(ledPin2, LOW);
 digitalWrite(ledPin3, LOW);
 digitalWrite(buzzerPin, LOW);}
}

Can you show how your switches, LEDs and buzzer are wired to the micro.

I doubt it’s the buzzer, although isolating it from the micro is good practice.
It sounds like your choice of components around the buttons or LEDs may be pulling things down. One or two buttons should be drawing almost no current, same for the LEDs.

The buzzer is on or it’s not. Nothing changes there.
(Also post your code - it’s possible you’re turning the buzzer off each time around loop() which would make the sound become feeble when two inputs are true...)

Could it be the resistors? I just grabbed some that was included in the start kit I bought from Aliexpress...never checked what value they have.

Attached is a screen save of the TinkerCad graphic over how I hooked it all up. The resistor value on that is not representativ of the ones I used on the micro.

(How do I attach the picture into the post? Is it possible or do I have to upload it somewhere?)

Skärmavbild 2017-10-18 kl. 01.31.28.png

The resistor values CAN affect things, but HOW they’re wired may also affect things...

One important point.
Those piezo buzzers can cause serious problems if they’re not applied properly. (i.e. Kill the chip). At the very least, fit a reversed diode to prevent back EMF getting to the micro pin, but as you noted, a transistor is good form as well. Those transducers can ‘generate’ high-voltage spikes when they’re tapped - which can pop the I/O pin.

Check and post your updated code.
I suspect you may be about to learn about state changes, and logical OR
Good luck.