Emergency button code

Hi! If someone can help me this is the code I'm using to control 2 DC motors for opening swing gates.
But I need to use InputState = digitalRead(D1); as an emergency button is this possible??!

//4 channel EV1527/PT2262 Decoding module

int VCC = 13;//as power vcc
int D3 = 12;
int D2 = 11;
int D1 = 10;
int D0 = 9;
int VT = 8;

int Relay1 = 0;
int Relay2 = 3;
int Relay3 = 2;
int Relay4 = 1;

int InputState = 1; //variable for reading the input status

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin
pinMode(VCC, OUTPUT);
pinMode(D3, INPUT);
pinMode(D2, INPUT);
pinMode(D1, INPUT);
pinMode(D0, INPUT);
pinMode(VT, INPUT);
pinMode(3,OUTPUT);
pinMode(2,OUTPUT);

digitalWrite(VCC, HIGH);//AS VCC

Serial.begin(9600);

delay(2000);//Waiting for rf receiver module startup

}

// the loop routine runs over and over again forever:
void loop() {
InputState = digitalRead(VT);

if(InputState)
{
Serial.print("D3 D2 D1 D0 VT \n");
InputState = digitalRead(D3);
if(InputState) {digitalWrite (3, HIGH); delay(5000); digitalWrite(2, HIGH); delay(28000); digitalWrite(3, LOW); digitalWrite(2, LOW);}

InputState = digitalRead(D2);
if(InputState) {digitalWrite (2, HIGH); delay(5000); digitalWrite(3, HIGH); delay(28000); digitalWrite(2, LOW); digitalWrite(3, LOW);}

InputState = digitalRead(D1);
if(InputState)

InputState = digitalRead(D0);
if(InputState)

}

do{
InputState = digitalRead(VT);
}
while(InputState);
}

is this possible??!

Yes ??!

Of course, reading the switch state once every 33 seconds is kind of dumb.

Get rid of the delay()s and shut the motors off as soon as the switch becomes pressed (see the state change detection example).

Hi,
Your Emergency button should not just attempt to turn the motors off in software.
It should have the button hardwired to disconnect the power supply to the motors directly.

If this is a public project, you need to investigate the type of safety required.

Tom.... :slight_smile:

I'm sorry I didn't ask for the right question...

I changed some things in the code:

int VCC = 13;//as power vcc
int D3 = 12;
int D2 = 11;
int D1 = 10;
int D0 = 9;
int VT = 8;

int Relay1 = 0;
int Relay2 = 3;
int Relay3 = 2;
int Relay4 = 1;



int InputState = 1;   //variable for reading the input status


// the setup routine runs once when you press reset:
void setup() 
{      
 // initialize the digital pin

 pinMode(VCC, OUTPUT); 
 pinMode(D3, INPUT); 
 pinMode(D2, INPUT); 
 pinMode(D1, INPUT); 
 pinMode(D0, INPUT); 
 pinMode(VT, INPUT); 
 pinMode(3, OUTPUT);

 digitalWrite(VCC, HIGH);//AS VCC

Serial.begin(9600);

delay(2000);//Waiting for rf receiver module startup
 
}

// the loop routine runs over and over again forever:
void loop() {
  InputState = digitalRead(VT);

  if(InputState)
  {
    InputState = digitalRead(D3);
    if(InputState) digitalWrite(3, HIGH);
   
   InputState = digitalRead(D2);
    if(InputState) digitalWrite(3, LOW);
   
  }
   
 do{
     InputState = digitalRead(VT);
   }while(InputState);
   
}

Now I need this program to run for 30 sec when I push D3 button and I need the D2 button to stop whenever I push it...
Is this possible??
Thanks :smiley:

and I need the D2 button to stop whenever I push it...

What the heck does that mean? You want it to stop what? Stop being a button? What should it be, then? A zipper? Some velcro?

This is crazy

void loop() {
   InputState = digitalRead(VT);

   if(InputState)
   {
     InputState = digitalRead(D3);
     if(InputState) digitalWrite(3, HIGH);
   
    InputState = digitalRead(D2);
     if(InputState) digitalWrite(3, LOW);
   
   }
   
  do{
      InputState = digitalRead(VT);
    }while(InputState);
   
}

You are using the same variable for several different purposes. How can you hope to figure out code like that.

...R

Hi,

Welcome to the forums.

Please be so kind as to read the first post in any forum entitled how to use this forum.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html
about how to post your code.

There is a way this forum and all users want to see code.
Then come back to your posts and edit it (lower right of your post screen) add the code tags and make us happy.

What are you using Pin13 for? You have it as an output, called VCC.
You know that each output pin is limited to 40mA of load current, and pin13 depending on who manufacured it, may be even less as it is also connected to an on board LED.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

Hi

Guys don't be so rough to me I'm trying to explain this as good as I can...

I sent a pic of what I'm using

int VCC = 13;//as power vcc
int D3 = 12;
int D2 = 11;
int D1 = 10;
int D0 = 9;
int VT = 8;
 
int Relay1 = 0;
int Relay2 = 3;
int Relay3 = 2;
int Relay4 = 1;


 
int InputState = 1;   //variable for reading the input status
 
 
// the setup routine runs once when you press reset:
void setup() 
{      
  // initialize the digital pin

  pinMode(VCC, OUTPUT); 
  pinMode(D3, INPUT); 
  pinMode(D2, INPUT); 
  pinMode(D1, INPUT); 
  pinMode(D0, INPUT); 
  pinMode(VT, INPUT); 
  pinMode(3, OUTPUT);

  digitalWrite(VCC, HIGH);//AS VCC
 
 Serial.begin(9600);
 
 delay(2000);//Waiting for rf receiver module startup
  
}
 
// the loop routine runs over and over again forever:
void loop() {
   InputState = digitalRead(VT);

   if(InputState)
   {
     InputState = digitalRead(D3);
     if(InputState) digitalWrite(3, HIGH);
    
    InputState = digitalRead(D2);
     if(InputState) digitalWrite(3, LOW);
    
   }
    
  do{
      InputState = digitalRead(VT);
    }while(InputState);
    
}

Now when i push the remote button A (pin 3 HIGH) and when I push remote button B (pin 3 LOW)...
soo I would like to know is it possible that when I push button A the program must run for 28 sec.
When the program is running and I push button B the program stops..
I am sorry if I didn't explain it right

Hi,
Sorry, I don't think pin 13 is going to supply enough peak current for the tx/rx unit.
It needs to be connected to 5V supply directly.

Tom.... :slight_smile: