Roller blind is controlled via web browser from internet connected device

Roller blind is controlled via web browser from internet connected device

Assembly

The elements of the enclosures are 3D printable and available on github here. The other components are listed above. When assembling mechanism to your roller blind window, follow this instructions:

1. Put DC motor in the "Roller_Motor_Enclosure" part and tighten it with two M3x6 screws.

2. Close the motor with "Roller_Motor_Enclosure_Bottom", make sure that the wires are outside the box and tighten it with two M3x10 screws

3. Attach "Roller_Shaft" on the motor's shaft and tighten it with M3x6 screw.

4. Wrap a string of a roller blind on the shaft and cover it with "Roller_Shaft_Enclosure", then tighten it with two M3x30 screws.

5. Put microswitch in the "Roller_Endstop_Enclosure" and cover it with "Roller_Endstop_Enclosure_Top".

6. Solder some wires to the "C" and "NC" connectors of the microswitch, make sure you can plug it to the CORE2 hSens1.

7. Close the loop of the string and attach motor mechanism, so the string is tight. Then attach the endstop mechanism on the top of the frame of the window. The glue or the tape is the best option.

Optionally you can cover screws with "Roller_Hiding_Screw" elements.

Motor enclosure assemblyMotor enclosure assemblyEndstop microswitch assemblyEndstop microswitch assembly

Circuit diagram

Everything we need to program the device via Husarion Cloud is described on the Husarion's webpage:

https://docs.husarion.com/howtostart/core2_1_0_0/index.html

We have chosen option with Raspberry Pi 2, because we have one. It is also possible to connect Core2 with popular ESP8266 as you can see on their site.

1. Connect Raspberry Pi to the RPi connector as described on the documentation here.

2. Connect microswitch to the hSens1 port: normally closed pin ("NC") to the pin 1 and common pin ("C") to the GND (hSensor description).

3. Connect DC motor to the hMotC port following documentation from Husarion's webpage (hMotor description).

Circuit diagram with CORE2 and Raspberry Pi (source: husarion.com)Circuit diagram with CORE2 and Raspberry Pi (source: husarion.com)

Program

It is unusual, how programming CORE2 is convenient with its Husarion Cloud. We can leave any USB cables, it is programmed and then could be controlled through wifi, and we were surprised, how easy it is.

1. Connect your CORE2 via Husarion Config app (available on Google Playhere) to your account and your network (Connecting to the cloud). The app has its own tutorial, so just follow instructions.

2. Use our code and web user interface, it is open-sourced. Modify power of the motor, direction, length of the window or anything you need as you want.

3. Program CORE2 using Husarion Cloud and control it via web browser.

Eventually check, if your ProjectId is the same as in the Settings.

Source code

The code is available on github, but we also bring it here:

#include <cstddef>
#include <cstdint> 
#include "hFramework.h" 
#include "hCloudClient.h" 
#define power 500       //power of motor 
#define length 6500     //length of blind window in encoder tics 
#define dir -1          //direction of rotation of motor (for calibration) 
#define offset 460      //offset for end-point 
int act_pos, des_pos;   //actual position, desired position 
void cfgHandler()                               //UI 
{ 
	platform.ui.loadHtml({Resource::WEBIDE, "/ui.html"}); 
} 
void calibration_task() 
{ 
	hMot3.setPower(500); 
	sys.delay(2000); 
	hMot3.setPower(dir * (power * 0.7));    //up 
	hSens1.pin1.setIn_pu(); 
	hSens1.pin1.interruptOn_EdgeFalling(); 
	hSens1.pin1.interruptWait();            //end-point 
	hMot3.setPower(0);                      //stop 
	hMot3.resetEncoderCnt();                //reset encoder 
	act_pos = hMot3.getEncoderCnt(); 
	hMot3.rotAbs(-1050,500);	        //down 
} 
void onKeyEvent(KeyEventType type, KeyCode code) 
{ 
	switch (code) { 
	case KeyCode::Key_P: 
		if (type == KeyEventType::Pressed) { 
			hMot3.rotRel(100); 
			platform.printf("enc = %d\r\n", hMot3.getEncoderCnt()); 
		} 
		break; 
	case KeyCode::Key_L: 
		if (type == KeyEventType::Pressed) { 
			hMot3.rotRel(-100); 
			platform.printf("enc = %d\r\n", hMot3.getEncoderCnt()); 
		} 
		break; 
	default : break; 
	} 
} 
#define OFFSET -600 
#define MAXI 7600 
void onValueChangeEvent(hId id, const char* data) 
{ 
	int val = atoi(data); 
	hMot3.rotAbs(map(val, 0, 1000, -1050, 7000), 700); 
} 
void hMain() 
{ 
	act_pos = 0; 
	des_pos = 500; 
	platform.begin(&RPi); 
	platform.ui.setProjectId("@@@PROJECT_ID@@@"); 
	platform.ui.configHandler = cfgHandler; 
	platform.ui.onKeyEvent = onKeyEvent; 
	platform.ui.onValueChangeEvent = onValueChangeEvent; 
	sys.taskCreate(calibration_task);               //calibration at the beginning 
	for (;;) { 
		sys.delay(1000); 
		LED2.toggle(); 
		act_pos = hMot3.getEncoderCnt(); 
		platform.ui.label("l1").setText("Enc: %u Des_pos: %u", (unsigned int)act_pos, (unsigned int)des_pos); 
	} 
} 

Project uses Husarion CORE2, so we don't need to add motor controller - it is on the board.

Finally you can check if it works. We present to you our roller blind on rough and ready window and attached mechanism controlled via web browser in a phone:

We think about expanding our app with weather informations and connecting more roller blinds. Every time you turn on the device (or reset) it calibrate itself autonomously: roller blind goes up to the endstop.

Hope you enjoy this project. If there are any questions, feel free to ask.