How to make your own electric curtains with great imagination

I got in touch with Arduino during the winter vacation and made a "smart curtain". I posted a post to write down the whole process. I hope you find it helpful!

1. Analysis Purpose and Process

The "smart curtains" I want to make are to achieve a function - they can be opened by themselves in the morning and pulled by themselves in the evening. It is simple and practical.

The general process is:

Collect the light intensity data collected by the photoresistor;

Determine whether the motor needs to be turned on and determine the direction of motor rotation.

As for why we don’t make an APP on mobile phones, it’s because I personally agree with the statement that “smartphones are not the core of future smart home systems.” [I won’t say it because I don’t know how]

2. Prepare materials

To realize this function, the materials include: external power supply (above 5V), photoresistor, DC Motor, L293D (H-bridge) and some resistors and jumpers.

3. Hands-on implementation

1. Write a program

Before the things come back, write the program first. The source code is as follows:

[C] View copy code in plain text

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

p>

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

/* smart curtain */

/* writer: tttt-top */

/* date: 20160227 */

int enablepin=11;

int in1a =4;

int in2a=7;

int photocellPin = 2; // Photoresistor interface

int photocellVal = 0; // Photosensitive output value initialization

int curtainState = 0; //The curtain is initially opened

int i=0, j=0;

void setup() {

//pinMode(ledPin, OUTPUT);

pinMode(enablepin, OUTPUT);

pinMode(in1a, OUTPUT);

pinMode( in2a, OUTPUT);

digitalWrite(enablepin, LOW);

Serial.begin(9600);

}

void loop () {

//The photosensitive output analog value read from the serial port output

photocellVal = analogRead(photocellPin);

Serial.print(photocellVal);

Serial.print(" ");

// There is insufficient light and the curtains are not drawn

if (photocellVallt; 80 amp;

amp; curtainState==0)

{

i ;

Serial.println(i);

// delay(2000 );

}

//When the light is insufficient for more than 15 minutes, close the curtains

if(i gt; 10 amp; amp; curtainState == 0 )

{

digitalWrite(in1a, LOW);

digitalWrite(in2a, HIGH);

digitalWrite(enablepin, HIGH) ;

Serial.print("i=");

Serial.print(i);

Serial.println(" fan zhuan, close the curtain "); //Reverse the curtains

delay(4000);

digitalWrite(enablepin, LOW);

curtainState = 1; //Curtains Close

i=0;

}

// There is enough light and the curtains are closed

if (photocellVal gt; 300 amp ;amp;curtainState == 1)

{

j ;

Serial.println(j);

}

if(j gt; 10 amp; amp; curtainState == 1){

digitalWrite(in1a, HIGH);

digitalWrite(in2a, LOW);

p>

digitalWrite(enablepin, HIGH);

Serial.print("j = ");

Serial.print(j);

Serial.println("zheng zhuan, open the curtain"); //Forward rotation to open the curtain

delay(2000);

digitalWrite(enablepin, LOW);

curtainState=0;

j=0;

}

delay(2000);

}

Connect the components as shown in Figures 1 and 2;

Show the actual picture:

After the connection is completed, check the circuit again.

3. Programming test

Manually change the light intensity, and you can see the accurate value of the current light intensity from the serial monitor:

When the light is less than 80 When the number is more than 10 times (simulating insufficient light in actual use for up to , the test was successful.

IV. Summary

This attempt did not use it on real curtains because the connection problem between the motor and the curtains was not solved. The original idea was to use a gear similar to a bicycle chain to connect the motor and one end of the curtain. Unfortunately, I never found anything that could be tested, so I only used the forward and reverse rotation of the motor to represent the opening and closing of the curtain. If you have any good suggestions on this issue, you can discuss it together.

360 screenshot 20160227134401319.jpg (60.15 KB, Number of downloads: 14)

Figure 1 Connection of photoresistor

360 screenshot 20160227134950564.jpg (97.88 KB, Number of downloads: 15)

Figure 2 H-bridge connection

360 screenshot 20160227140855744.jpg (123.53 KB, number of downloads: 23)

Physical picture

p>

Serial port.png (56.64 KB, download times: 26)

Serial port monitor data