Hi all,
First time poster, hopefully I comprehended the posting instructions correctly.
I am using an Arduino MEGA 2560 R3 for a semi automated glass blowing machine.
It should be fairly simple; the bulk of what I need is to trigger relays on an off at various times, but not in consistent intervals. There is one sensor and a hope to add buttons that can adjust the times, but I'm not even close to getting to that part of code or what it would look like. I've attached a simple diagram of what needs to be turned on and turned off and when this occurs.
I am using an 8 relay module as all solenoids use 120v.
This program is a shot in the dark, but its what I've been able to cobble together over the past few days from tutorials and youtube videos. I can get the individual relays to turn on at different times(!), but I'm stumped how to get the to turn off at different times and how to structure it so it can accomplish what I need.
I'm sure there are some gapping holes in my explanation, but this is the best I can provide right now. Please ask questions! Let me know if this is enough to work with or if my explanation and diagram needs to be more thorough.
Thanks in advance!
const unsigned long event_1 = 2000;
const unsigned long event_2 = 4000;
const unsigned long event_3 = 6000;
const int relay1 = 2;
const int relay2 = 3;
const int relay3 = 4;
unsigned long previousTime_1;
void setup() {
Serial.begin(9600);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
}
void loop() {
unsigned long currentTime = millis();
if (millis() < event_1 ) {
digitalWrite(relay1, HIGH);
}
else {
digitalWrite(relay1, LOW);
}
if (millis() < event_2 ) {
digitalWrite(relay2, HIGH);
}
else {
digitalWrite(relay2, LOW);
}
if (millis() < event_3 ) {
digitalWrite(relay3, HIGH);
}
else {
digitalWrite(relay3, LOW);
}
}