Hi folks,
I need help about programming the arduino.
My project is arduino garage opener. My door has two wings, so I need two limit switches for closed door and two limit switches when a door is open.
I have two DC motors, and 4 relays for motors. I need 4 relays beacause I need to reverse polarity so I could open and close door.
I programmed arduino to wait for input from rf remote, then it should open A wing and then after 3sec open B wing. but when limit switch A is activate it need to stop wing A same for B wing.
My program activate relays but I try to make function for open and close but unsuccessful.
Please I need help
// constants won't change. They're used here to
// set pin numbers:
#define doorOpenSwitchAPin 2 // the number of the close door 1 safety switch
#define doorOpenSwitchBPin 3 // the number of the open door 1 safety switch
#define doorCloseSwitchAPin 4 // the number of the close door 2 safety switch
#define doorCloseSwitchBPin 5 // the number of the open door 2 safety switch
#define rfOpenPin 6 // the number of the RF Supra input OPEN pin
#define rfClosePin 7 // the number of the RF Supra input CLOSE pin
#define doorOpenAPin 8 // the number of output for door1
#define doorOpenBPin 9 // the number of output for door2
#define doorCloseAPin 10 // the number of output for door1
#define doorCloseBPin 11 // the number of output for door2
#define ledPin 13
// variables will change:
int doorOpenSwitchA = 0; // variable for reading the close door 1 safety switch
int doorOpenSwitchB = 0; // variable for reading the open door 1 safety switch
int doorCloseSwitchA = 0; // variable for reading the close door 2 safety switch
int doorCloseSwitchB = 0; // variable for reading the open door 2 safety switch
int rfOpen = 0; // variable for reading RF Supra input OPEN pin
int rfClose = 0; // variable for reading RF Supra input CLOSE pin
//int doorOpenA = 1; // variable for reading output for door1
//int doorOpenB = 1; // variable for reading output for door2
//int doorCloseA = 1; // variable for reading output for door1
//int doorCloseB = 1; // variable for reading output for door2
void setup()
{
pinMode(doorOpenSwitchAPin,INPUT); // Inicijalizuj pin kao ulaz
pinMode(doorOpenSwitchBPin,INPUT); // Inicijalizuj pin kao ulaz
pinMode(doorCloseSwitchAPin,INPUT); // Inicijalizuj pin kao ulaz
pinMode(doorCloseSwitchBPin,INPUT); // Inicijalizuj pin kao ulaz
pinMode(rfOpenPin,INPUT); // Inicijalizuj pin kao ulaz
pinMode(rfClosePin,INPUT); // Inicijalizuj pin kao ulaz
pinMode(doorOpenAPin,OUTPUT); // Inicijalizuj pin kao izlaz
pinMode(doorOpenBPin,OUTPUT); // Inicijalizuj pin kao izlaz
pinMode(doorCloseAPin,OUTPUT); // Inicijalizuj pin kao izlaz
pinMode(doorCloseBPin,OUTPUT); // Inicijalizuj pin kao izlaz
pinMode(ledPin,OUTPUT);
}
// Funkcija za otvaranje kapije
/*
void doorOpen()
{
do
{
digitalWrite(doorOpenAPin, LOW); // Pusti relej za otvaranje kapije A
} // sve dok
while (doorOpenSwitchA != 0); // kranji prekidac za otvaranje kapije A ne prekine funkciju
delay(2000); // sacekaj 2 sek
do
{
digitalWrite(doorOpenBPin, LOW); // Pusti relej za otvaranje kapije B
} // sve dok
while (doorOpenSwitchB != 0); // kranji prekidac za otvaranje kapije B ne prekine funkciju
}
// Funkcija za zatvaranje kapije
void doorClose()
{
do
{
digitalWrite(doorCloseBPin, LOW); // Pusti relej za zatvaranje kapije B
} // sve dok
while (doorCloseSwitchB != 0); // krajnji prekidac za zatvaranje kapije B ne prekine funkciju
delay(2000); // sacekaj 2 sek
do
{
digitalWrite(doorOpenAPin, LOW); // Pusti relej za zatvaranje kapije A
} // sve dok
while (doorCloseSwitchA != 0); // krajnji prekidac za zatvaranje kapije A ne prekine funkciju
}
*/
void loop()
{
digitalWrite(doorOpenAPin, HIGH); // podesene standardne vrednosti za izlaze releja
digitalWrite(doorOpenBPin, HIGH); // podesene standardne vrednosti za izlaze releja
digitalWrite(doorCloseAPin, HIGH); // podesene standardne vrednosti za izlaze releja
digitalWrite(doorCloseBPin, HIGH); // podesene standardne vrednosti za izlaze releja
rfOpen = digitalRead(rfOpenPin);
rfClose = digitalRead(rfClosePin);
if (rfOpen == HIGH) // Ako stigne komanda od supre za otvaranje
{
digitalWrite(ledPin, HIGH);
doorOpen(); // Pokreni funkciju za otvaranje kapije
}
else
{
digitalWrite(ledPin, LOW);
digitalWrite(doorOpenAPin, HIGH);
digitalWrite(doorOpenBPin, HIGH);
}
if (rfClose == HIGH) // Ako stigne komanda od supre za zatvaranje
{
digitalWrite(ledPin, HIGH);
doorClose(); // Pokreni funkciju za zatvaranje kapije
}
else
{
digitalWrite(ledPin, LOW);
digitalWrite(doorCloseAPin, HIGH);
digitalWrite(doorCloseBPin, HIGH);
}
}[/table]