Dear All
Plan to make motorized curtain with 12vdc Geared motor with limit switch,
present code is only long press latch code lack of other funtion code so for that component are added like diode, capacitors and comparators to achive desired result
As i am not good at programing need some hint on aurduino code so that extra components can be eleminated.
working of curtain
for curtain going up
- button 1 short press will start move curtain up and stop when button 1 released
*button 1 long press >=1 sec will start move curtain up till reaches the limit by sensing limit switch button 2 or if button 3 is short pressed only to stop motor
for curtain going down
- button 3 short press will start move curtain down and stop when button 3 released
*button 3 long press >=1 sec will start move curtain down till reaches the limit by sensing limit switch button 4 or if button 1 is short pressed only to stop motor
Thanks in advance
const int buttonPin1 = 2; // Pin for the first push button
const int buttonPin2 = 3; // Pin for the second push button
const int buttonPin3 = 4; // Pin for the third push button
const int buttonPin4 = 5; // Pin for the fourth push button
const int ledPin1 = 6; // Pin for the first LED
const int ledPin2 = 7; // Pin for the second LED
unsigned long buttonPressStartTime1 = 0;
unsigned long buttonPressStartTime2 = 0;
const unsigned long requiredPressTime = 1000; // 1 seconds
bool ledState1 = false;
bool ledState2 = false;
void setup() {
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(ledPin1, OUTPUT);
pinMode(buttonPin3, INPUT_PULLUP);
pinMode(buttonPin4, INPUT_PULLUP);
pinMode(ledPin2, OUTPUT);
}
void loop(){
// Check if the first button is pressed and held
if (digitalRead(buttonPin1) == HIGH) {
if (buttonPressStartTime1 == 0) {
buttonPressStartTime1 = millis();
} else if (millis() - buttonPressStartTime1 >= requiredPressTime) {
ledState1 = true;
digitalWrite(ledPin1, ledState1);
}
} else {
buttonPressStartTime1 = 0;
}
// Check if the second button is pressed to turn off the first LED
if (digitalRead(buttonPin2) == HIGH) {
ledState1 = false;
digitalWrite(ledPin1, ledState1);
}
// Check if the third button is pressed and held
if (digitalRead(buttonPin3) == HIGH) {
if (buttonPressStartTime2 == 0) {
buttonPressStartTime2 = millis();
} else if (millis() - buttonPressStartTime2 >= requiredPressTime) {
ledState2 = true;
digitalWrite(ledPin2, ledState2);
}
} else {
buttonPressStartTime2 = 0;
}
// Check if the fourth button is pressed to turn off the second LED
if (digitalRead(buttonPin4) == HIGH) {
ledState2 = false;
digitalWrite(ledPin2, ledState2);
}
}



