So i have a small Programm where my relay is already on when i dont need it
Example:
- Pushed Button 1
2.Move servo - Relay 1 on
4.delay
5.Relay 1 off
6.delay
7.Relay 2 on
8.delay
9.Relay 2 off
10.delay - Servo 0 Pos
but the Problem is i dont even Push a button and both relays are on
// Include servo library
#include <VarSpeedServo.h>
// Define servo pins
#define servo1Pin 2 //ARM 1
#define servo2Pin 3 //ARM 2
#define servo3Pin 4 //DREHTELLER
// Define button pins
int button1Pin = 5;
int button2Pin = 6;
int button3Pin = 7;
int button4Pin = 8;
int button5Pin = 9;
// Define relay pin
#define relayPin 11
#define relayPin2 12
// Define servo objects
VarSpeedServo servo1;
VarSpeedServo servo2;
VarSpeedServo servo3;
// Define servo parameters
int servo1ZeroPos = 40; // Zero position for servo 1 ARM 1!!!!!!!!
int servo2ZeroPos = 0; // Zero position for servo 2 ARM 2 !!!!!!!
int servo3ZeroPos = 60; // Zero position for servo 3
// Define button states
int button1State = 0;
int button2State = 0;
int button3State = 0;
int button4State = 0;
int button5State = 0;
// Define relay state
int relayState = 0;
void setup() {
// Initialize servo objects
servo1.attach(servo1Pin);
servo2.attach(servo2Pin);
servo3.attach(servo3Pin);
// Initialize button pins as inputs
pinMode(button1Pin, INPUT);
pinMode(button2Pin, INPUT);
pinMode(button3Pin, INPUT);
pinMode(button4Pin, INPUT);
pinMode(button5Pin, INPUT);
Serial.begin(9600);
Serial.println("Roboter started");
// Initialize relay pin as output
pinMode(relayPin, OUTPUT);
pinMode(relayPin2, OUTPUT);
}
void setPos1() {
servo1.write(17, 10);
servo2.write(6, 20);
servo3.write(44, 20);
delay(1000);
digitalWrite(11, HIGH);
delay(3500);
digitalWrite(11, LOW);
delay(5000);
digitalWrite(12,HIGH);
delay(500);
digitalWrite(12, LOW);
delay(200);
}
void setPos2() {
servo1.write(19, 10);
servo2.write(2, 20);
servo3.write(51, 20);
delay(1000);
digitalWrite(10, HIGH);
delay(1500);
digitalWrite(10, LOW);
delay(5000);
}
void setPos3() {
servo1.write(19, 10);
servo2.write(0,20);
servo3.write(57,20);
delay(1000);
digitalWrite(10, HIGH);
delay(2500);
digitalWrite(10, LOW);
delay(2000);
}
void setPos4() {
servo1.write(19, 10);
servo2.write(2, 20);
servo3.write(63, 20);
delay(1000);
digitalWrite(10, HIGH);
delay(4000);
digitalWrite(10, LOW);
delay(2000);
}
void setPos5() {
servo1.write(19, 10);
servo2.write(2, 20);//POS 5
servo3.write(70, 20);
delay(1000);
digitalWrite(10, HIGH);
delay(4000);
digitalWrite(10, LOW);
delay(2000);
}
void setEndPos() {
servo1.write(servo1ZeroPos, 10);
servo2.write(servo2ZeroPos, 20);
servo3.write(servo3ZeroPos, 20);
delay(2000);
}
void loop() {
// Read button states
button1State = digitalRead(button1Pin);
button2State = digitalRead(button2Pin);
button3State = digitalRead(button3Pin);
button4State = digitalRead(button4Pin);
button5State = digitalRead(button5Pin);
servo1.write(servo1ZeroPos);
servo2.write(servo2ZeroPos);
servo3.write(servo3ZeroPos);
// If button 1 is pressed, move servo 1 to position and turn on relay
if (button1State == HIGH) {
Serial.println("1 shot will be filled");
// servo1.write(23, 10);
// servo2.write(4, 10);
// servo3.write(39, 10);
setPos1();
setEndPos();
}
// If button 2 is pressed, move servo 2 to position and turn on relay
else if (button2State == HIGH) {
Serial.println("2 shots will be filled");
setPos1();
setPos2();
setEndPos();
}
// If button 3 is pressed, move servo 3 to position and turn on relay
else if (button3State == HIGH) {
Serial.println("3 shots will be filled");
setPos1();
setPos2();
setPos3();
setEndPos();
}
// If button 4 is pressed, move all servos to zero position and turn off relay
else if (button4State == HIGH) {
Serial.println("4 shots will be filled");
setPos1();
setPos2();
setPos3();
setPos4();
setEndPos();
}
// If button 5 is pressed, move all servos to zero position and turn off relay after 5 seconds
else if (button5State == HIGH) {
Serial.println("5 shots will be filled");
setPos1();
setPos2();
setPos3();
setPos4();
setPos5();
setEndPos();
}
}