Automated wooden curtain poles

Hi Guys, i want to automate my wooden curtain poles. Ive completed all the engineering side but have fallen flat on my face with the arduino control side. Can anyone help with this at all?

I want to be able to open, close the curtains via dashboard and Alexa and jog them manually via dashboard only. I hope to use ogiewon’s app with Hubitat and have posted on his thread.

At the moment im using a D1 Mini, i would prefer to use zigbee or zwave but i know less about that than i do Arduino… (bought an ikia blind to see if i can cannibalise it to control my pole!!!)

i have a working basic arduino sketch that is working with Blynk but as soon as i try to add limit switches, it all goes pear shaped, its something to do with the way the loop is formatted.

But then i had a thought, (it didnt hurt much) " what if i learn how to write the sketch for blynk and thats not what i need for Hubitat arduino???" ill have wasted much time and effort…

The aim is to get this working with Hubitat and dashboard/alexa can some one please point me in the direction i need to go to get this working? is it even going to be possible?

The code i have below works with blynk but as soon as i add limit switches it wont work and ive got to re write it.

  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  This example runs directly on ESP8266 chip.

  Note: This requires ESP8266 support package:
    https://github.com/esp8266/Arduino

  Please be sure to select the right ESP8266 module
  in the Tools -> Board menu!

  Change WiFi ssid, pass, and Blynk auth token to run :)
  Feel free to apply it to any other example. It's simple!
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "GdXuPDTYzFyO0qXSZHOSr6VYOltp1xQ_";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Mark & Kims Place HD";
char pass[] = "SmellyEllie8";

byte limitCW = D0;
byte limitCCW = D1;
byte directionPin = D2;
byte stepPin = D3;
byte buttonOnOffpin = D4;
byte buttonCWpin = D5;
byte buttonCCWpin = D6;
byte buttonJogCWpin = D7;
byte buttonJogCCWpin = D8;

boolean buttonCWpressed = false;
boolean buttonCCWpressed = false;
boolean buttonJogCWpressed = false;
boolean buttonJogCCWpressed = false;
boolean buttonOnOffpressed = false;


unsigned long curMillis;
unsigned long prevStepMillis = 0;
unsigned long millisBetweenSteps = 1; // milliseconds

void setup()
{
  // Debug console
  Serial.begin(9600);
  Serial.println("Starting Stepper Demo with millis()");

  pinMode(directionPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(buttonOnOffpin, OUTPUT);

  pinMode(limitCW, INPUT);
  pinMode(limitCCW, INPUT);
  pinMode(buttonCWpin, INPUT);
  pinMode(buttonCCWpin, INPUT);
  pinMode(buttonJogCWpin, INPUT);
  pinMode(buttonJogCCWpin, INPUT);

  Blynk.begin(auth, ssid, pass);
}

void loop()
{
  Blynk.run();

  curMillis = millis();
  readButtons();
  actOnButtons();

}

void readButtons() {

  buttonCCWpressed = false;
  buttonCWpressed = false;
  buttonJogCCWpressed = false;
  buttonJogCWpressed = false;
  buttonOnOffpressed = false;

  if (digitalRead(buttonCWpin) == HIGH) {
    buttonCWpressed = true;
  }
  if (digitalRead(buttonCCWpin) == HIGH) {
    buttonCCWpressed = true;
  }
  if (digitalRead(buttonJogCWpin) == HIGH) {
    buttonCWpressed = true;
  }
  if (digitalRead(buttonJogCCWpin) == HIGH) {
    buttonCCWpressed = true;
  }
  if (digitalRead(buttonOnOffpin) == HIGH) {
    buttonOnOffpressed = true;
  }
}

void actOnButtons() {
  if (buttonCWpressed == true) {
    //while (limitCW = HIGH)
    digitalWrite(directionPin, LOW);
    singleStep();
  }
  if (buttonCCWpressed == true) {
    digitalWrite(directionPin, HIGH);
    singleStep();
  }
  if (buttonJogCWpressed == true) {
    digitalWrite(directionPin, LOW);
    singleStep();
  }
  if (buttonJogCCWpressed == true) {
    digitalWrite(directionPin, HIGH);
    singleStep();
  }
  if (buttonOnOffpressed == true) {
  digitalWrite(buttonOnOffpin, HIGH);
  }
}

void singleStep() {
  if (curMillis - prevStepMillis >= millisBetweenSteps) {
    // next 2 lines changed 28 Nov 2018
    //prevStepMillis += millisBetweenSteps;
    prevStepMillis = curMillis;
    digitalWrite(stepPin, HIGH);
    digitalWrite(stepPin, LOW);
  }
}```

Hi @mark . If you look here you’ll find information on @markus Aqara Smart Curtain Motor driver. Maybe this helps you given it’s an existing product etc.

1 Like