Background

Our team sought to solve the particular problem of controlling natural lighting, an issue that many of us have faced since the beginning of the pandemic. Lighting (and natural light especially) is a very crucial part of human health, influencing the circadian rhythm. When we are inside all day, we might experience lethargy and stress due to lack of light. On the other hand, some people may want to restrict the entry of light to prevent glare when working on the computer.

Solution

Our solution was to use the motion kit to control our blinds with a computer. Our end-goal was to have a set of hardware and software that would allow us to open and close the blinds remotely, perhaps even on a timed schedule.

Hardware Design

As shown in the images below, we used two DC motors from the motion kit to control our blinds. The intention was to use the motors to pull a string back and forth. We tied this string to the blinds to move them horizontally. We removed the tires from the wheels and used the remaining hubs use as spools for the string.

The motors were controlled by an ESP32 microcontroller using an L293NE H-bridge. The entire setup was powered by a single 9-Volt battery. We used a 5 volt voltage regulator to provide regular voltage to the ESP32 and the H-bridge. Since it was imperative that our motors ran at the same speed, we connected both motors in parallel (to have the same voltage). Both motors were then attached to the same H-bridge channel (leaving one channel unused). The motor and spool assembly was mounted with gorilla tape; the control center was left on the sofa next to the sliding-glass door.

Software Design

The following simple program was written to the ESP32 to move the motors based on Bluetooth input:

//This example code is in the Public Domain (or CC0 licensed, at your option.)
//By Evandro Copercini - 2018
//
//This example creates a bridge between Serial and Classical Bluetooth (SPP)
//and also demonstrate that SerialBT have the same functionalities of a normal Serial

#include "BluetoothSerial.h"

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
#include <string>

BluetoothSerial SerialBT;

void setup() {
    Serial.begin(115200);
  pinMode(22,OUTPUT);
  pinMode(23,OUTPUT);
  digitalWrite(22,LOW);
  digitalWrite(23,LOW);

  Serial.begin(115200);
  SerialBT.begin("ESP32test"); //Bluetooth device name
  Serial.println("The device started, now you can pair it with bluetooth!");
}

void forward(){

  Serial.println("Going for");
   digitalWrite(22,LOW);
  digitalWrite(23,HIGH);
  delay(1000);
  digitalWrite(22,LOW);
  digitalWrite(23,LOW);
}

void backward(){
  Serial.println("Going Back");
    digitalWrite(22,HIGH);
  digitalWrite(23,LOW);
  delay(1000);
  digitalWrite(22,LOW);
  digitalWrite(23,LOW);
}

char input = ' ';
void loop() {

    if (SerialBT.available()) {
    input = SerialBT.read();
    Serial.print(input);
    if (input == 'f') {
      forward();
    }
    if (input == 'b') {
      backward();
    }
  }
  if (Serial.available()) {
    SerialBT.write(Serial.read());
  }

  delay(20);
}

The following is Python code to send control messages over Bluetooth:

#!/usr/bin/python3
import serial

ser = serial.Serial('/dev/rfcomm1')
print(ser.name)
ser.write(b'b\n')
ser.close()
#!/usr/bin/python3
import serial

ser = serial.Serial('/dev/rfcomm1')
print(ser.name)
ser.write(b'f\n')
ser.close()

Challenges

We spent a few hours troubleshooting the H-bridge. For the longest time we could not get any voltage output from the L293NE. As it turns out, the connections were loose. As soon as the connections were tightened, the motors started moving.

An interesting programming challenge is that Linux assigns a new serial port to the ESP every time it reconnects via Bluetooth. This means we had to increment rfcomm1 to rfcomm2 and rfcomm3 etc. A more robust program would be able to determine the serial port automatically.

Although we were able to open the blinds slightly, alignment issues prevented full functionality. In the future, it would be nice to 3d-print an actual spool to prevent the string from falling off.

Built With

Share this project:

Updates