After running, leave HIGH for 30 minutes and then back to LOW. How to make such a timer?
if (mosfet == 1)
{
digitalWrite(MOSFETpin, HIGH); // only 30 minutes
}
After running, leave HIGH for 30 minutes and then back to LOW. How to make such a timer?
if (mosfet == 1)
{
digitalWrite(MOSFETpin, HIGH); // only 30 minutes
}
(deleted)
Using a serial line (SoftwareSerial = toESP), when I send mosfeton, I need to get HIGH on mosfet via pin A1, but only 30 minutes. Then I need to give LOW automatically.
I also have the option to manually turn off the mosfetoff.
But now it's about the on timer for only 30 minutes.
#include <SoftwareSerial.h>
SoftwareSerial toESP(12, 11);
#define MOSFETpin A0
int mosfet;
void setup() {
Serial.begin(9600);
delay(300);
toESP.begin(9600);
delay(300);
pinMode(MOSFETpin, OUTPUT);
}
void loop() {
if(toESP.available() > 1)
{
String value;
value = toESP.readStringUntil('\n');
value.trim();
Serial.println(value);
if(value == "mosfeton")
{
Serial.println("ON mosfet");
mosfet = 1;
}
if(value == "mosfetoff")
{
Serial.println("OFF mosfet");
mosfet = 0;
}
}
if (mosfet == 1)
{
digitalWrite(MOSFETpin, HIGH); // only 30 minutes
}
if (mosfet == 0)
{
digitalWrite(MOSFETpin, LOW); // manual shutdown
}
}
Hi, can anyone advise me Thank you very much
When mosfet goes true , IDE -> file/examples/digital/statechangedetection, set a boolean true. Use the boolean value to enable a timer to run. When the timer reaches preset, set the boolean to false and do whatever else happens when the timer runs out.
blink without delay also shows you how to use millis() in a way that lets you time things