I need code for arduino to make led on for 6 hour then turn it off for half an hour then repeat it again to turn it on for 6 hours then turn it off for half an hour and repeat it again and again for ever
Welcome to the group.
We can look at the sketch you have written and give you some pointers.
Good to see you!
If you have external hardware you might post a schematic, not a frizzy picture with links to technical information on each of the hardware items.
modify a blink sketch. if you find one
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
}
const unsigned long SECOND = 1000;
const unsigned long MINUTE = SECOND * 60;
const unsigned long HOUR = MINUTE * 60;
void loop()
{
digitalWrite(LED_BUILTIN, HIGH);
delay(HOUR * 6);
digitalWrite(LED_BUILTIN, LOW);
delay(MINUTE * 30);
}
Thanks but can i have the code with millis function not delay because there is another actions i need to add work at the same time
const unsigned long SECOND = 1000;
const unsigned long MINUTE = SECOND * 60;
const unsigned long HOUR = MINUTE * 60;
const unsigned long OFF_TIME = MINUTE * 30;
const unsigned long ON_TIME = HOUR * 6;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
static uint32_t timeCapture;
uint32_t now = millis();
if ((now - timeCapture) >= (digitalRead(LED_BUILTIN) ? ON_TIME : OFF_TIME)) {
timeCapture = now;
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
}
#1
I need code for arduino to make relay on for 6 hour while that happening turn blue led on then turn them off for half an hour while it turned off
Then repeat it again for ever
P. S
I need the code with millis not delay please
Thx
You need help or someone to write it? Help is free, custom coding is $75/hr - UPFRONT!
Your price is very good, I go for $250.00/hr + with a 1 week minimum guarantee if I am interested.
@ahmedk2, your topic has been moved to a more suitable location on the forum. Introductory Tutorials is for tutorials that e.g. you write, not for questions. Feel free to write a tutorial once you have solved your problem
Something to read:
- Using millis() for timing. A beginners guide
- Demonstration code for several things at the same time
- pinMode() - Arduino Reference and digitalWrite() - Arduino Reference
For time calculations, make sure that you use variables of type unsigned long.
Why?
You can get a timer in any department stores'.
Can they do multiple things "at the same time"? Or do you have to buy a few?
That fits the description. That's all that's required, isn't it?
There appear to be two actions required here, but the actual requirement is garbled.
I have requested this cross posting to be joined to the original for clarity. (Hopefully it will remain in this section as I do not routinely look at "Programming Questions" )
TOPIC MERGED.
Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.
Please do not keep posting the same question, if you do you will be banned from posting anything else.
you can adapt the blink example to do this.
It's in programming questions! Partly because it's a programming question and partly because that's where the original was.
If and when he returns - perhaps inside 11 days - I wanted to see whether he knows exactly why he does or does not need to use millis().