Requesting some guidance for programming relay's

Hello, I'm requesting some guidance with some programming for my arduino.

I currently can't make my relay work the way it should work. It's kind of hard to explain but let me try to explain it plain and simple.

My arduino is connected to 2 seperate switches(press and release, when pressed it's on. When released it's off). My arduino is also connected to 2 relay's that would drive a motor for given amount of time.

Here comes the hardest part >

When arduino turns on it should check if the button 1/2 is pressed. If yes then no action should be taken and the relays should be turned off.
If switch 1/2 turns off then a delay function for 40-50 seconds (that's not a defined time yet.)

After the delay (40-50 seconds the switch is turned off) then the relay should turn on automaticly even when button is not triggered. It would press both switches (1/2) on. Then there needs to be a delay before turning off. Around 30 seconds(not defined.)
After that the cycle repeats. It's important that it would check it's on funtion what the switch's mode is at certain cycles.

I tried programming the code above but I can't seem to get it working properly. Can any one please help me out?

Kind regards,

Tjarec van Hensbergen

Welcome to the forum

Please post your best effort at programming what you want and describe the problems that you have encountered

I think you will benefit from a short read that helps to collect and document the logic that must be expressed by coding:

https://create.arduino.cc/projecthub/gusgonnet/using-finite-state-machines-fdba04

... and welcome!

Your description is a bit hard to follow.

Perhaps if you said what the big idea is, it would make more sense.

What turns on the Arduino?

But this

is where I lost all hope of understanding. How are relays supposed to press switches?

Also referring to switches 1/2 always, does it mean there are two switches with identical functioning and wired in parallel?

A simple hand drawn diagram of you circuit will help greatly.

a7

Please post schematics . Relay trouble are often easily spotted from the wiring.

I've tried programming with delay's and if / when statements. After a day of failures I threw it out of the window haha. In the pictures you can clearly see that the 3D printed part triggers a switch when the tube runs thru the part. When the switch gets triggered it the motor that drives the tubes should turn off after a certain amount of time. When the tubes are removed from the 3D printed part the switches turn off. At that moment I need a delay for a certain amount of time and then it should automatically turn on untill the switch is pressed ( If switch is pressed then also the motor should run for a few more seconds to give the ability to have some work space for the tubes).

I know this is all a bit confusing but all help is Appreciated big time, I can't seem to work it out.

Picture2

Hello tjarec
Post your sketch, well formated, with comments and in so called code tags "</>" and schematic to see how we can help.
Have a nice day and enjoy coding in C++.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.