Hi
I'm working on 3 actuator cylinder with with arduino.
The way I operating it is conneting all three actuator on a 8ch relay module and trigger the relay module with joystick switch.
I want the actuator to work while I dragging the joystick and stops when I release it.
I can drag the joystick in 4 direction (up, down, right, left) But even if I write all the direction for the code, it seems like only one direction (the last condition for the code) is working.
Here's my code: I'd put only "right" and "left" for the testing.
#define joyX A1
#define joyY A0
int button=4;
int buttonState = 0;
int buttonState1 = 0;
void setup() {
pinMode(button,INPUT);
digitalWrite(button, HIGH);
Serial.begin(9600);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
}
void loop() {
int xValue = analogRead(joyX);
int yValue = analogRead(joyY);
Serial.print(xValue);
Serial.print("\t");
Serial.println(yValue);
buttonState = digitalRead(button);
Serial.println(buttonState);
//RIGHT
if (yValue>500)
{
Serial.println("RIGHT");
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
digitalWrite(8,LOW);
digitalWrite(9,HIGH);
}
else {
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
}
//Left
if (yValue<3)
{
Serial.println("LEFT");
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
digitalWrite(8,HIGH);
digitalWrite(9,LOW);
}
else {
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
}
Serial.println(buttonState1);
delay(100);
}
Like I said earlier, only last condition for the code (Left direction) is working. When I check arduino serial monitor, it seems recognize the Right input but relay module is not working like the other one does.
Please help me if someone knows what's the problem here.
Thank you