The project is for activating and deactivating relays in a sequence after a switch is closing. Then deactivate the last relay when switch opens and standby for new sequence.
I have no schematics. I assume 4 pins, 1 for input and 3 for output.
I have no sketch either, as I have not understood at all how to make more things happen from one input.
Are you serious? The purpose is to activate and deactivate 2 outputs after defined delays, and to hold the third when input is closed. Then deactivate the third and standby when input opens.
To make it simple I use a 4ch relay board and an Arduino nano.
Why do I need to make a schematics? It's really simple: Input wired to one pin, output wired to three pins.
I haven't written much code before. That's why I ask here....
what should happen when the input switch gets deactivated before the other relays got activated?
Break the sequence or let it run and switch of relay 1 with relay2?
I only considered debouncing on the input to avoid clapping relays. If, for some reason input gets deactivated, all relays should be deactivated no matter where in the sequence.
This looks really nice, I see millis is even more complicated than I first thought. Just the look of it is still terrifying, but your example looks clean and understandable. I will give it a go on the breadboard after work today and post back. Thanks!
Agree we need a schematic - at least to show how you are powering things - get that wrong and you could damage the processor .
Have a lot at the ide examples - digital input , output, blink for guidance
see what the IDE Example "Blink Without Delay" is doing. It explains very well how to deal with millis.
it summarizes to
uint32_t current Millis = millis(); // get the current internal "time"
static uint32_t previousMillis = 0; // the time of last execution
if (currentMillis - previousMillis >interval) // check if interval is over
{
previousMillis = currentMillis; // remember "now" as last exececution
// do somthing
}
once you have learned that "Blink Without Delay" pattern, you can use this over and over again.
If not already mentioned, have a look at the IDE Example "Blink Without Delay" example.
Hi, @Eirik78
Have you written some basic code to prove you can control a relay?
This is important as some relay arrays are ACTIVE on LOW input and some are ACTIVE on high input.
So before chasing the various ways of configuring your project.
Just get a basic bit of code, a button and a relay connected to your Arduino.
What model Arduino are you using?
Can you please post a link to data/specs of your relay assembly, or at least some images of your relay assembly.
Can you please post link to, or image of your button?
These are the basic things we need to know.
So get your hardware out, your PC stoked up and start..
@Eirik78 I understand your frustration with the questions, but I also have to ask you - When were you going to tell us this? This information only came out through questioning, yet is central to the design of the code. Your 'tormentors' have long experience of having this kind of detail pop up after 20 or more postings, leading to considerable frustration all around. That's why the questions get asked.
Schematics are a communication tool, they greatly inform the discussion and lead to either great improvements in the design, or quick resolution of the original problem, and often both happen. A schematic isn't a tortuous exercise, a pencil sketch on a piece of paper, and a photo of it taken with a phone or camera, is all that's necessary most of the time.
Cheers, and hopefully you'll have a quick answer!
Hi! I only had time to wire for a quick test at lunchtime today, so I won't have time to look closer at it before tomorrow. But so far it looked good. Think I'll have two questions, but will look at it properly first
It looks good, and at this moment I'm not sure there is any more than to play with it and the code to better understand the millis-function, since my goal with this was to learn how to perform sequences and repeats. I appreciate how someone replies directly to questions asked with knowledge.
When first testing it on an Uno, the delays was as expected. But when putting it on a Nano, the times did not correspond with milliseconds. I have no idea of why, I haven't used Nano much.