Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Andrew BerryJack DuffAdam O' CeallaighSpivey
Published

IoT Window Blind

In this tutorial we will be going over how to use a Wia Dot One with two stepper motors to make an IoT window shade controlled by a sensor.

IntermediateFull instructions provided30 minutes804

Things used in this project

Hardware components

Wia Dot One
Wia Dot One
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Stepper Motor
Digilent Stepper Motor
×1
Micro USB 16340 Lithium Battery Shield Mobile Power Holder Adapter For Arduino
×1

Software apps and online services

Wia
Wia

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

Cylinder case

This is the case that cylinder is resting in and the motors attach to.

Main PCB Case Component

This is the main component which holds the PCB boards in place

PCB Case Lid

This is the lid to the case which holds the Dot one and motor drivers (PCBs)

Battery Case Main

This is the main case for the battery to power the motors and Dot One

Battery Case Lid

This is the lid to the battery case

Code

Distance Sensor Code

C/C++
This is the code for the distance sensor which will activate the window shade.
// This is the code for the Distance Sensor

#include <WiFi.h>

#include <Wia.h>

const int PIR = 16;

Wia wiaClient = Wia();

void setup() {

  WiFi.begin();

  delay(2500);

  pinMode(PIR, INPUT);

}

void loop() 
{
  if (digitalRead(PIR) == HIGH) 
  {

    wiaClient.createEvent("ToggleShade");

    delay(2500);

  }
}

Rolling shade up and down

C/C++
// This is the code for the stepper motors

#include <WiFi.h>

#include <Wia.h>

// Include the AccelStepper library:

#include <AccelStepper.h>

// Motor pin definitions:

#define motor1Pin1  16     // IN1 on the ULN2003 driver

#define motor1Pin2  17     // IN2 on the ULN2003 driver

#define motor1Pin3  21     // IN3 on the ULN2003 driver

#define motor1Pin4  22     // IN4 on the ULN2003 driver

#define motor2Pin1  23     // IN1 on the ULN2003 driver

#define motor2Pin2  19     // IN2 on the ULN2003 driver

#define motor2Pin3  18     // IN3 on the ULN2003 driver

#define motor2Pin4  26     // IN4 on the ULN2003 driver

// Define the AccelStepper interface type; 4 wire motor in half step mode:

#define MotorInterfaceType 8

// Initialize with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper library with 28BYJ-48 stepper motor:

AccelStepper stepper1 = AccelStepper(MotorInterfaceType, motor1Pin1, motor1Pin3, motor1Pin2, motor1Pin4);

AccelStepper stepper2 = AccelStepper(MotorInterfaceType, motor2Pin1, motor2Pin3, motor2Pin2, motor2Pin4);

bool toggleRoll = true;

unsigned long previousMillis = 0;

const long interval = 21000;

String currentState = "0";

String previousState = "0";

Wia wiaClient = Wia();

void setup()

{

  WiFi.begin();

  delay(2500);

  // Set the maximum steps per second:

  stepper1.setMaxSpeed(1000);

  stepper2.setMaxSpeed(1000);

}

void loop()

{

  unsigned long currentMillis = millis();

  currentState = wiaClient.getDeviceState("roller");

  delay(1000);

  digitalWrite(16, LOW);

  digitalWrite(17, LOW);

  digitalWrite(21, LOW);

  digitalWrite(22, LOW);

  digitalWrite(23, LOW);

  digitalWrite(19, LOW);

  digitalWrite(18, LOW);

  digitalWrite(26, LOW);

  if (currentState != previousState)

  {

    toggleRoll = !toggleRoll;

//     while (digitalRead(pin) == HIGH)

//     {

//       delay(100);

//     }

    previousState = currentState;

    previousMillis = millis();

  }

  if (toggleRoll)

  {

    while (currentMillis - previousMillis < interval)

    {

      currentMillis = millis();

      // Set the speed of the motor in steps per second:

      stepper1.setSpeed(-900);

      stepper2.setSpeed(900);

      // Step the motor with constant speed as set by setSpeed():

      stepper1.runSpeed();

      stepper2.runSpeed();

    }

  }

  else

  {

    while (currentMillis - previousMillis < interval)

    {

      currentMillis = millis();

      // Set the speed of the motor in steps per second:

      stepper1.setSpeed(900);

      stepper2.setSpeed(-900);

      // Step the motor with constant speed as set by setSpeed():

      stepper1.runSpeed();

      stepper2.runSpeed();

    }

  }

}

Credits

Andrew Berry
25 projects • 11 followers
Contact
Jack Duff
32 projects • 8 followers
Man of the people. Champion of the downtrodden. Marketing magic @ Wia. Becoming a maker by learning, building, and exploring
Contact
Adam O' Ceallaigh
20 projects • 8 followers
Contact
Spivey
82 projects • 59 followers
Tourist in a Tutu || US Born || Melbourne/Mexico/California Raised || New Yorker at ❤️ || SF to Dublin to be COO of Wia the best IoT startup
Contact

Comments

Please log in or sign up to comment.