Hello, I am looking to use a relay to run a fog horn on my boat. The parameters are to turn on a switch to close the relay for 5 seconds every two minutes and loop until a switch is turned off. Now the trick here is if I turn on a different switch i want a different timing of the relay for a different sound signal. My plan is to have a rotary switch with three positions for the three possible sound signals.
have a look at arduino-rotary-encoder - you press the switch to start/stop the fog horn - rotate to set the timing
what microcontroller are you going to use?
This is a straightforward sketch to create using only simple statements.
Even adding the three different timings is not difficult.
If this is your very first step, you might want to just code it literally, as the code will not be your only issue.
What parts have you in hand? What have you done with them so far?
I googled and found this
The minimal sketch that is presented boils down to
int led = 13;
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}
which I boiled from the linked tutorial just so you can see simple.
If you use your imagination, the LED might be the fog hat going on and off; the times which are expressed in milliseconds can be adjusted for any frequency and length of a toot.
A larger or side problem will be actually driving the fog hat, for that you'll need some external circuitry. Again the easiest would be to use an inexpensive relay module like this one
You'll get plenty of advice about how this is a naive and simple and dead-end approach, but it won't hurt to get one timed LED blinking, and then one fog hat tooting, using the sketch and the relay module. Nothing you learn will be wasted, no time spent wasted either, and if all you want ultimately is three different blinkers or tooters, the simple approach can still suffice.
Then worry about doing it the way we all hope you will want to and then be able to do one day. Or not. If you don't take up the hobby in any serious way, you can take the win and your device will function for the rest of its life, if not yours.