Hye guys
I want to contol a DC-motor with a 4 relay-module but with my program it doesnt work.
There are 2 pushbuttons, if I push on the left button the motor has to turn left and if i push once again the motor has to stop. If I push on the right button the motor has to turn right and again if I push once again the motor has to stop. Here you see my program.
const int drukknopplus = 22;
const int drukknopmin = 23;
const int drukknopN = 24;
const int relais1 = 34;
const int relais2 = 35;
const int relais3 = 36;
const int relais4 = 37;
int op = 0;
int opd = 0;
int neer = 0;
int neerd = 0;
void uitschuiven ()
{
digitalWrite (relais1, HIGH);
digitalWrite (relais2, LOW);
digitalWrite (relais3, HIGH);
digitalWrite (relais4, LOW);
}
void inschuiven ()
{
digitalWrite (relais1, LOW);
digitalWrite (relais2, HIGH);
digitalWrite (relais3, LOW);
digitalWrite (relais4, HIGH);
}
void motorstop ()
{
digitalWrite (relais1, LOW);
digitalWrite (relais2, LOW);
digitalWrite (relais3, LOW);
digitalWrite (relais4, LOW);
}
void setup() {
// put your setup code here, to run once:
pinMode (drukknopplus, INPUT);
pinMode (drukknopmin, INPUT);
pinMode (drukknopN, INPUT);
pinMode (relais1, OUTPUT);
pinMode (relais2, OUTPUT);
pinMode (relais3, OUTPUT);
pinMode (relais4, OUTPUT);
Serial.begin(9600);
}
void loop()
{
// put your main code here, to run repeatedly:
if (op == 0)
{
motorstop ();
}
else
{
uitschuiven ();
}
if (neer == 0)
{
motorstop ();
}
else
{
inschuiven();
}
if ((op == 0) and (drukknopplus == LOW))
{opd = 1;} else {}
if ((op == 1) and (drukknopplus == LOW))
{opd = 0;} else {}
if ((neer == 0) and (drukknopmin == LOW))
{neerd = 1;} else {}
if ((neer == 1) and (drukknopmin == LOW))
{neerd = 0;} else {}
if ((op == 0) and (drukknopplus == HIGH) and (opd == 1))
{op = 1;} else {}
if ((op == 1) and (drukknopplus == HIGH) and (opd == 0))
{op = 0;} else {}
if ((neer == 0) and (drukknopmin == HIGH) and (neerd == 1))
{neer = 1;} else {}
if ((neer == 1) and (drukknopmin == HIGH) and (neerd == 0))
{neer = 0;} else {}
}