Coffee Grinder Relay with timer controls

Hi I’m new to the forums and arduino in general. Im trying to create a project for a coffee grinder at work that as of right now is only on or off based on a switch that is manually turned on or off. Im trying to create a relay circuit that turns the grinder on and off based on a timer program in arduino that can be adjusted with 4 buttons and an LED display.

THe first button should increment the timer(5 seconds by default) up by 0.5 seconds.

The second button increments the timer down by 0.5 sec.

The third button switches the relay for the time shown on the timer.

The fourth button is just a bypass that will turn the relay on as long as the button is held down.

I havent even gotten to the led display yet but im having trouble with the buttons working the way they are supposed to. I use an LED as a stand in for the relay and It turns on and off with for no apparent reason.

Any advice would be great. Like I said I have almost no experience with arduino. My code is based on a few things i found by searching but clearly Im missing something.

Grinder-code.txt (1.37 KB)

How are the switches wired?

Each switch is connected to the pin they are assigned to on the board with the other lead going to the gnd pin on the arduino.

You look for a button to be high, but that can never be. You initialise them as 0, the keep them low by grounding them when pressed.

What I did to get it working was :

  • Change the pinMode()s to INPUT_PULLUP to force the pins HIGH when UNpressed
  • Reverse the logic to look for buttons being LOW and old ones as HIGH

Once you've sorted that out you need to make sure you turn the grinder off after an untimed "D" run.

OH man, thank you so much! I've been trying to figure this out for the longest time. I still need to figure out how to display the time on an LED display but this is a huge hurdle overcome. THank you.