Timer relay with three buttons

Hello all,

I am currently planning a project with an relay a button and an arduino. What I want to do is the following.
There should be three buttons if I press first of it the relay should turn on for a time A and then shut off. If i press second button the relay should turn on for a time B and then shut off. The third button is an emergency cut. If this will be pressed the relay close without any delay. If I press button 1 or 2 after the relay opened nothing should happen. Only if I press button 3= shut off!

Hope you can understand. I don`t have that much coding skills. So if you know any project with same target I would be glad to have a link!

Thanks a lot for your help. It is always better for me to learn if I see how someone did it!

Thanks a lot

ArneDunio:
The third button is an emergency cut.

Hi,
What may seem an off topic: Is the project intended to manage something that "may cause damage to persons and/or things?
Regards

if you know any project with same target I would be glad to have a link!

Very unlikely.

Have you looked at the examples in the IDE ? They will show you how to read a button, set the state of an output and deal with timing.

NOTE : because of the requirement for an emergency stop button you will need to use millis() for timing and not delay() so it would be a good idea to read Using millis() for timing. A beginners guide and try the examples that it comtains

Hello all,

no it will not cause any danger to humans. It is just a filling machine! Emergency shut off just the bottles will not overflow.

Are there any projects out there? I am looking around for hours but can`t find anything.

Thanks guys

I am a beginner!

I am a beginner!

That is how you will remain until you jump in and try things

Hello all,

I am really appreciating your help. But this is not the easiest thing to start with. And the best way to learn is to observe and imitate. That would work the best if you can follow a ready made project. There are so many nice and brilliant people here so why not show a beginner how to set up the coding. The hardware side no problem at all. If i succeed I will also share it with all people here so other people like me can follow easily.

So if anyone knows a similar project please help me out.

Thanks

ArneDunio:
So if anyone knows a similar project please help me out.

Your project is not complicated, but you should try by yourself beginning, for instance, with just one relay and one press button (without delay), that seems to be one of the simplest projects you may afford. Then add delay and, then, add buttons and relays. Publish your attempts and everybody will help you.

(Even if your filling machine would not cause any harm, the emergency circuit should be cabled outside the arduino).

Regards

I use this code. But when I am uploading it the relay starts switching even the button is not pressed. Stays on for a while and then turns off. The button is doing nothing if i push it.

And how could I avoid the loop function. I just want to run trough the programm only if i press the button.

const int buttonPin = 2;
const int ledPin =  13;
int buttonState = 0;
 
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
 
void loop(){
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
}

Well, you look a bit green ...

Have a look on this and tell us if you understand it.

Regards

How is the button wired ?
Do you have a resistor in place to keep it in a known state at all times or is the input floating at an uncertain voltage ?

If you do not have a resistor in place then try

 pinMode(buttonPin, INPUT_PULLUP);

to turn on the built in pullup resistor and wire the switch to take the pin to GND when the button is pressed.

The button is wired directly to the PIN 2 no resistor yet

ArneDunio:
The button is wired directly to the PIN 2 no resistor yet

Implement a pullup or pulldown resistor, wire the switch accordingly and change the program logic to match. INPUT_PULLUP in the pinMode() is the easiest way.

I agree with vffgaston that the emergency stop should be hardwired separate to the arduino.

I am interested how you get on with this though as a have a totally different project but using similar principles.

Obsessionfatale:
I agree with vffgaston that the emergency stop should be hardwired separate to the arduino.

I am interested how you get on with this though as a have a totally different project but using similar principles.

Who: me?

Regards