sir i make an egg automatic incubator for my universty project i use two relays and one dht11 sensor (sorry for my english) one relay i use for gear motor to rotate egg turner and the seccond relay i use for a light and fan for controling temperature i use delay for rotating the eggs so the dht11 also use that delay and dont show the temperature between delay time please help me how can i use multi tasking i mean i want to see the temperature and humidity during delay time please replay
Here is what I have. It works as intended but with one small quirk. When I press the reset button, relay 4 activates. Please check it and see what you think. // Push Button Relay Controller #define RELAY_ON 0 // The relays are active-LOW; on when LOW (0) #define RELAY_OFF 1 // and off when HIGH (1). These #defines just help keep track. const int RelayPin1 = 10; // Pin numbers for the relays const int RelayPin2 = 11; const int RelayPin3 = 12; const int RelayPin4 = 13; const int ButtonPin1 = 6; // Pin numbers for the push buttons const int ButtonPin2 = 7; const int ButtonPin3 = 8; const int ButtonPin4 = 9; const int Duration1 = 500; // Number of milliseconds that the relays run after the buttons are pressed const int Duration2 = 500; const int Duration3 = 500; const int Duration4 = 500; // variables byte State1 = RELAY_OFF; // Used to record whether the relays are on or off byte State2 = RELAY_OFF; // - default to HIGH/OFF - byte State3 = RELAY_OFF; byte State4 = RELAY_OFF; unsigned long currentMillis = 0; // Stores the value of millis() in each iteration of loop() unsigned long TimerMillis1 = 0; // Stores the times when the buttons were last pressed unsigned long TimerMillis2 = 0; unsigned long TimerMillis3 = 0; unsigned long TimerMillis4 = 0; void setup() { // Debug Serial.begin(9600); Serial.println("Starting Relay Controller.ino"); // Relays are active-LOW. Initialize relay pins high so the relays are inactive at startup/reset digitalWrite(RelayPin1, RELAY_OFF); digitalWrite(RelayPin2, RELAY_OFF); digitalWrite(RelayPin3, RELAY_OFF); digitalWrite(RelayPin4, RELAY_OFF); // Then set the pins as outputs pinMode(RelayPin1, OUTPUT); pinMode(RelayPin2, OUTPUT); pinMode(RelayPin3, OUTPUT); pinMode(RelayPin4, OUTPUT); // Set the float sensor pins as inputs and use the internal pullup resistors pinMode(ButtonPin1, INPUT_PULLUP); pinMode(ButtonPin2, INPUT_PULLUP); pinMode(ButtonPin3, INPUT_PULLUP); pinMode(ButtonPin4, INPUT_PULLUP); } void loop() { // Get the current clock count currentMillis = millis() + Duration1; // We add the countdown timer duration to // the clock to prevent the relay from // running at boto time, whele the clock // counter is still below the timer value // Call the cunctions that do the work readButtonPin1(); // Check each button and decide whether readButtonPin2(); // to start the relay and countdown timer readButtonPin3(); readButtonPin4(); triggerRelay(); // Actually toggles the relay pins based on // the data from the above functions } // ---Worker functions--- void readButtonPin1() { if (digitalRead(ButtonPin1) == LOW) // If the button is tripped (pulled low)... { State1 = RELAY_ON; // ...then trigger the relay pin TimerMillis1 = currentMillis; // and set the relay countdown timer to the current clock time } if (currentMillis - TimerMillis1 >= Duration1)//If the countdown timer has expired... { State1 = RELAY_OFF; // ...then turn off the relay pin TimerMillis1 = 0; // and reset the timer to 0 for the next trigger } } void readButtonPin2() { if (digitalRead(ButtonPin2) == LOW) { State2 = RELAY_ON; TimerMillis2 = currentMillis; } if (currentMillis - TimerMillis2 >= Duration2) { State2 = RELAY_OFF; TimerMillis2 = 0; } } void readButtonPin3() { if (digitalRead(ButtonPin3) == LOW) { State3 = RELAY_ON; TimerMillis3= currentMillis; } if (currentMillis - TimerMillis3 >= Duration3) { State3 = RELAY_OFF; TimerMillis3 = 0; } } void readButtonPin4() { if (digitalRead(ButtonPin4) == LOW) { State4 = RELAY_ON; TimerMillis4 = currentMillis; } if (currentMillis - TimerMillis4 >= Duration4) { State4 = RELAY_OFF; TimerMillis4 = 0; } } void triggerRelay() { digitalWrite(RelayPin1, State1); // Toggle the relay pins on and off based on digitalWrite(RelayPin2, State2); // the State from the readButton functions digitalWrite(RelayPin3, State3); digitalWrite(RelayPin4, State4); }
Samir Tawfik Thanks. It isn't a real big issue but if the application required no relays to be active at startup then that would have been an issue. Thanks!
Nice project, very similar to mine and I will modify mine based on yours, thank you.
Than you
Nice project. Very educational. Thanks for this!
sir i make an egg automatic incubator for my universty project i use two relays and one dht11 sensor
(sorry for my english)
one relay i use for gear motor to rotate egg turner
and the seccond relay i use for a light and fan for controling temperature
i use delay for rotating the eggs
so the dht11 also use that delay and dont show the temperature between delay time please help me how can i use multi tasking
i mean i want to see the temperature and humidity during delay time please replay
Just finished making this project. It works great. However, triggerRealy(); should read triggerRelay(); ;-)
Thanks again.
Thank you very much
can you make a class inorder to control different relays doing multi tasking. thank you
Great project! I can't find the code in here. Was it published?
Thank you please check this link
drive.google.com/file/d/10_XBbRTQdzAxBULgd-lTImhg6UdZRr1w/view?usp=sharing
What language is this?
Here is what I have. It works as intended but with one small quirk. When I press the reset button, relay 4 activates. Please check it and see what you think.
// Push Button Relay Controller
#define RELAY_ON 0 // The relays are active-LOW; on when LOW (0)
#define RELAY_OFF 1 // and off when HIGH (1). These #defines just help keep track.
const int RelayPin1 = 10; // Pin numbers for the relays
const int RelayPin2 = 11;
const int RelayPin3 = 12;
const int RelayPin4 = 13;
const int ButtonPin1 = 6; // Pin numbers for the push buttons
const int ButtonPin2 = 7;
const int ButtonPin3 = 8;
const int ButtonPin4 = 9;
const int Duration1 = 500; // Number of milliseconds that the relays run after the buttons are pressed
const int Duration2 = 500;
const int Duration3 = 500;
const int Duration4 = 500;
// variables
byte State1 = RELAY_OFF; // Used to record whether the relays are on or off
byte State2 = RELAY_OFF; // - default to HIGH/OFF -
byte State3 = RELAY_OFF;
byte State4 = RELAY_OFF;
unsigned long currentMillis = 0; // Stores the value of millis() in each iteration of loop()
unsigned long TimerMillis1 = 0; // Stores the times when the buttons were last pressed
unsigned long TimerMillis2 = 0;
unsigned long TimerMillis3 = 0;
unsigned long TimerMillis4 = 0;
void setup()
{
// Debug
Serial.begin(9600);
Serial.println("Starting Relay Controller.ino");
// Relays are active-LOW. Initialize relay pins high so the relays are inactive at startup/reset
digitalWrite(RelayPin1, RELAY_OFF);
digitalWrite(RelayPin2, RELAY_OFF);
digitalWrite(RelayPin3, RELAY_OFF);
digitalWrite(RelayPin4, RELAY_OFF);
// Then set the pins as outputs
pinMode(RelayPin1, OUTPUT);
pinMode(RelayPin2, OUTPUT);
pinMode(RelayPin3, OUTPUT);
pinMode(RelayPin4, OUTPUT);
// Set the float sensor pins as inputs and use the internal pullup resistors
pinMode(ButtonPin1, INPUT_PULLUP);
pinMode(ButtonPin2, INPUT_PULLUP);
pinMode(ButtonPin3, INPUT_PULLUP);
pinMode(ButtonPin4, INPUT_PULLUP);
}
void loop()
{
// Get the current clock count
currentMillis = millis() + Duration1; // We add the countdown timer duration to
// the clock to prevent the relay from
// running at boto time, whele the clock
// counter is still below the timer value
// Call the cunctions that do the work
readButtonPin1(); // Check each button and decide whether
readButtonPin2(); // to start the relay and countdown timer
readButtonPin3();
readButtonPin4();
triggerRelay(); // Actually toggles the relay pins based on
// the data from the above functions
}
// ---Worker functions---
void readButtonPin1()
{
if (digitalRead(ButtonPin1) == LOW) // If the button is tripped (pulled low)...
{
State1 = RELAY_ON; // ...then trigger the relay pin
TimerMillis1 = currentMillis; // and set the relay countdown timer to the current clock time
}
if (currentMillis - TimerMillis1 >= Duration1)//If the countdown timer has expired...
{
State1 = RELAY_OFF; // ...then turn off the relay pin
TimerMillis1 = 0; // and reset the timer to 0 for the next trigger
}
}
void readButtonPin2()
{
if (digitalRead(ButtonPin2) == LOW)
{
State2 = RELAY_ON;
TimerMillis2 = currentMillis;
}
if (currentMillis - TimerMillis2 >= Duration2)
{
State2 = RELAY_OFF;
TimerMillis2 = 0;
}
}
void readButtonPin3()
{
if (digitalRead(ButtonPin3) == LOW)
{
State3 = RELAY_ON;
TimerMillis3= currentMillis;
}
if (currentMillis - TimerMillis3 >= Duration3)
{
State3 = RELAY_OFF;
TimerMillis3 = 0;
}
}
void readButtonPin4()
{
if (digitalRead(ButtonPin4) == LOW)
{
State4 = RELAY_ON;
TimerMillis4 = currentMillis;
}
if (currentMillis - TimerMillis4 >= Duration4)
{
State4 = RELAY_OFF;
TimerMillis4 = 0;
}
}
void triggerRelay()
{
digitalWrite(RelayPin1, State1); // Toggle the relay pins on and off based on
digitalWrite(RelayPin2, State2); // the State from the readButton functions
digitalWrite(RelayPin3, State3);
digitalWrite(RelayPin4, State4);
}
Yes i am sorry for that when arduino first power or restart relay 4 trigger i will try to fix this error
HI Jared i fix it use pin 5 insted of pi 13 for relay 4 because it is float at start or rest
Samir Tawfik Thanks. It isn't a real big issue but if the application required no relays to be active at startup then that would have been an issue.
Thanks!
Yes but it is still bug in the program and i solved it by using pin 5 instead of pin 13 for realy 4 thank you Jared
Could you please explain what happens with pin 13 at startup and relay 4 activating? I don't understand it.
I love your video man!!! GREAT JOB... I started to make some arduino videos, could you come check it out and tell me what you think... thanks