Kitchen Timer Woes

I have built a simple kitchen countdown timer which comes on when you hit a big red button on top and counts down the seconds to zero from a set time. Set time is increased with one push button and decreased with another.
The big red button has two NO contacts and two NC contacts. There is no common.
The NO function of the big red button energises the gate of a MOSFET which grounds the Arduino, the Arduino comes on, and an output pin goes high to keep the MOSFET gate open.
The NC function of the big red button starts or restarts the countdown sequence. When the count reaches zero and the timer is not reset for ten seconds the pin to the MOSFET gate goes low and the Arduino turns off.
This all works very well until I introduce a buzzer into the mix.
It should beep when the count reaches zero and does, but it causes everything to shut down.
The activation of the buzzer seems to cut the power to the MOSFET gate.
I cannot figure out why and help will be much appreciated.

Don

//  Don Van Akker 2021/09/27
#include "TM1637Display.h"
#include <EEPROM.h>
#define buzzer 11
#define CLK 6
#define DIO 7
#define MOSFET 5

TM1637Display display = TM1637Display(CLK, DIO); // Create display object of type TM1637Display

int setTime = EEPROM.read(10);  //read set time from eeprom
int downPin = 2;
int upPin = 3;
int buttonPin = 4;  //starts timer
int t = 0;
int timeRemaining;  //time remaining until setTime is reached
boolean startTiming;
boolean switchState = false;

void setup() {
  //Serial.begin(9200);
  display.clear();
  display.setBrightness(5);
  pinMode (MOSFET, OUTPUT); //MOSFET gate
  digitalWrite (MOSFET, HIGH); //activate the MOSFET gate
  pinMode (upPin, INPUT_PULLUP);
  pinMode (downPin, INPUT_PULLUP);
  pinMode (buttonPin, INPUT_PULLUP);
  pinMode (buzzer, OUTPUT);
  display.showNumberDecEx(setTime, 0b10100000, false, 4, 0);
}

void changeSetTimeUpDown()  //change set time with up or down buttons
{
  for (long i = 0; i < 20002; i++)  // increments i to establish set time increment speed
  {
    if ((digitalRead(upPin) == LOW) && (i > 20000))  //read up button until i reaches 20000
    {
      startTiming = false;                                                      //increment setTime up
      setTime = setTime + 1;
      i = 0;
      //Serial.println(setTime);
      display.showNumberDecEx(setTime, 0b10100000, false, 4, 0);
      timeRemaining = setTime;
    }

    if ((digitalRead(downPin) == LOW) && (i > 20000))  //read down button until i reaches 20000
    {
      startTiming = false;                                                     //increment setTime down
      setTime = setTime - 1;
      i = 0;
      display.showNumberDecEx(setTime, 0b10100000, false, 4, 0);
      timeRemaining = setTime;
    }
  }
}

void readButtonPin()   //closing Normally Open side of Big Red Button starts timer
{
  if ((digitalRead (buttonPin) == HIGH))
  {
    startTiming = true;
    timeRemaining = setTime;
  }
}

void loop()
{

  readButtonPin();

  if (startTiming == true)
  {
    if (timeRemaining >= 0)
    {
      display.showNumberDecEx(timeRemaining, 0b10100000, false, 4, 0);
    }
    if (timeRemaining == 0)
    {
      tone(buzzer, 3000, 100);
    }
    if (timeRemaining < 0)
    {
      display.showNumberDecEx(setTime, 0b10100000, false, 4, 0);
    }
    if (timeRemaining == -10) //negative time remaining is idle time
    {
      startTiming = false;
      digitalWrite(MOSFET, LOW); //deactivate the MOSFET gate when idle time reaches 10 seconds and turn off Arduino
    }
    delay (1000);
    timeRemaining --;
  }
  changeSetTimeUpDown();
  EEPROM.update(10, setTime);  //writes setTime to eeprom if changed
}

"The activation of the buzzer seems to cut the power to the MOSFET gate."

Give us a link to the Buzzer.


Showing us a good image of the actual wiring and a schematic (hand drawn is fine) helps us help you.

If that's 6V going to the NANO Vin pin, it is very near the minimum required voltage for Vin.

In your image, it appears the MOSFET Drain and Source are both connected to GND, please check your wiring.

As a LOW side switch it should be:


A logic level P MOSFET HIGH side switch is a better choice for this application.

P-Channel-Same-Voltage-with-Pull-Up

Sometimes, reversing a diode across a buzzer is a good idea to limit back EMF. The data sheet may explicitly state this.

Thanks for this, Larry. The Mosfet end of my circuit works as intended though and it keeps the Arduino on until the control pin goes low.
The problem happens when I connect the little piezo buzzer. When the buzzer is activated everything goes dead which I don't understand because the two aren't linked.

Thanks 6v6gt.

Just tried it but no joy.

Depending on the power consumption of the buzzer, you may need to drive it with a transistor. An Arduino pin can supply around 30mA only.
Also, buzzers can be polarity sensitive. Ensure it is correctly wired.

I did try it with a transistor and had the same problem. The buzzer chirps and the power goes off.

What is the resistance of the buzzer ?

You either have to produce a link to the data sheet for the buzzer or take some measurements. Try to measure the current when the buzzer is wired directly to the battery and/or measure the voltage drop across the battery when the buzzer is connected.

If the buzzer doesn’t even work directly across the battery, it could be a passive type transducer which has to be driven at its resonant frequency, say using the tone() function.

I am driving buzzer using the tone function but putting 5 volts to it does produce a tone. It draws 23ma and the resistance is 5 mega ohms.
The voltage of my four AA cell battery is 5.91V and when connected to the buzzer 5.87V.
This led my to try two things both sort of successful.
I connected to my bench top power supply set to output 6V. The buzzer sounds and the Arduino stays on and finishes running my sketch.
I connected my battery to the 5V pin of the Uno. Again, the buzzer sounds and the Arduino stays on.
It was mentioned that 4 AA cells is barely enough voltage for the vcc input of the Arduino. It would seem even that small voltage drop is enough to make it shut down. It is too much voltage for that 5V pin however (5.5V max).
A buck converter perhaps?
What do you think?

I am copying this to LarryD who has also been working on this with me.

Don

This has been sent to 6v6gt who has also been working on this with me.
I am driving the buzzer using the tone function but putting 5 volts to it does produce a tone. It draws 23ma and the resistance is 5 mega ohms.
The voltage of my four AA cell battery is 5.91V and when connected to the buzzer 5.87V.
This led my to try two things both sort of successful.
I connected to my bench top power supply set to output 6V. The buzzer sounds and the Arduino stays on and finishes running my sketch.
I connected my battery to the 5V pin of the Uno. Again, the buzzer sounds and the Arduino stays on.
It was mentioned that 4 AA cells is barely enough voltage for the vcc input of the Arduino. It would seem even that small voltage drop is enough to make it shut down. It is too much voltage for that 5V pin however (5.5V max).
A buck converter perhaps?
What do you think?

Don

Do not connect more than 5.1v to the Arduino 5v pin.


Many here connect a 6v battery to a combo Boost/Buck converter to get 5v for the Arduino 5v pin.


You can also feed 6v to a Boost converter (set to 7-9v), connected to the Arduino Vin pin.

Thankyou Larry. I have a few minutes buck converters in my kit so I'll use one of those tomorrow.
Thanks much for your help. I'm not very knowledgeable with this stuff and help from people like you makes it possible for me to do things I could never manage on my own.

You should use Boost/Buck converter when the battery voltage is 6v.
image|r79x453

A buck converter would best work for a 9-12v battery.
image

A boost converter works nicely with a 3v or 4.5v battery.


image

Thanks Larry. I have just been tinkering with both my 6V battery, a 9V battery and a buck converter and have discovered that you are absolutely right.

Don

If the buzzer produces a tone when fed from 5V, then I don't think that there is any benefit of using the tone function.