Relay activation even if the circuit remains closed or open [Solved]

  I would like to do a small project at home and because I am new to arduino, I need a little help in programming it.
I would like to activate a relay from pin 13 twice for 2 seconds as long as the circuit is closed in pin 2 and to do the same thing when the circuit is opened. It is possible tu do so?

Hi,
welcome.
but please read the topic:

and remake your topic by clearly writing your project and your difficulty in building it.

I quote ursutvg:

I would like to do a small project at home and because I am new to arduino, I need a little help in programming it.
I would like to activate a relay from pin 13 twice for 2 seconds as long as the circuit is closed in pin 2 and to do the same thing when the circuit is opened. It is possible tu do so?

Basically, if you can articulate the project, you can program it. Can you try to restate your project logic? The "circuit" seems to be missing.

I'll pass this along to OP, ursutvg. Hey @ursutvg! You-got-mail!

Hello ursutvg

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++.

I apologize for my clumsy expression. I don't really know how to post a Sketch or a diagram. I will try to explain more clearly what I need and if it is still not understood I will try to post a diagram. So the project is as follows: I have a room thermostat that I set to, for example, 22 degrees. When the temperature in the room reaches 22 degrees, the thermostat opens the circuit. Well, after the circuit is opened I want the arduino to activate a relay for 1 second twice at an interval of 2 seconds and then do nothing until the temperature in the room drops to 21 degrees when the circuit closes after which to do exactly the same now, to activate the same relay for 1 second twice at an interval of 2 seconds. To better understand how I would like the relay to work, imagine an LED connected in its place that turns on and off twice and then remains off. I apologize for my English and I hope you understand this time :slight_smile:

You write about a thermostat and you write about a circuit. Are they different? Or are they ALL referring to a heating control system that has a thermostat and some heating device? Yes, a drawing is sort of necessary.

What you are trying to do would be pretty simple IF we knew WHICH Arduino you have and HOW it is connected to the thermostat. What is the voltage from the thermostat? Is it AC or DC?

This is what I would like to do. I used a switch because I couldn't find a room thermostat but the principle is the same

Hello ursutvg

Do you have real schematic too?

What do you mean by real?

I really don't know how to explain batter what I need. I have the circuit made on the table exactly as I posted the picture with the diagram and I want the arduino to control the relay as I posted above. Do you think this is possible?

There is NO reason to ask if we think it is possible or not. You have the circuit and you can test it and answer your question right there. Does it do what you want or does it not?

does the current to operate the relay coils comes from the Uno?

It doesn't work because I don't know how to write the code for the arduino to work the way I want

Yes, I want to program the arduino to activate it as I want, but I don't really know how :grinning:

You do not seem to have posted any code that shows you have tried. What does you code do and what is different from what you want?

Did you start with just a SINGLE component and code to get it to work?

Did you attempt to use words such as "arduino relay activation" on the internet to see what others have done?

Did you use this thing,


and words to see how others have done it before?