Introduction: Smart Curtain System

Would you like a smart curtain system that close itself when the room is too hot and bright and also able to control it remotely on-the-go?

Here I am gonna show you how to make one real easy~

Supplies

  • Carton box
  • DHT11 temperature sensor
  • Servo motor
  • Reed sensor
  • Realtek Ameba1 RTL8195AM microcontroller
  • Jumper wire

Step 1: MQTT

MQTT is a machine-to-machine (M2M)/"Internet of Things" connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport.

We can say MQTT is a protocol designed for IoT. MQTT is based on TCP/IP and transmits/receives data via publish/subscribe.

Since we are using ameba development board, we can register an account on the official website at amebaiot, and get a free MQTT server at amebaiot.com/cloud-getting-started

Note, once you have registered on AmebaIOT.com and have
registered your device for “Cloud Service”, then the username and password you used to log in to AmebaIOT.com is the same for your MQTT connection, details will be explained later in the tutorial.

Step 2: Software Setup

The center of every IoT (Internet-of-Things) project is a Wi-Fi-enabled microcontroller, our project is no exception. The Wi-Fi microcontroller used here is Ameba-1 RTL8195AM from Realtek, it has got many useful peripherals and a strong Wi-Fi module at a power low enough to run on a cell battery for weeks.

What’smore? This board is programmable on Arduino IDE! Yes, no learning hardcore software is needed, just open your Arduino IDE and paste the following link into the “additional board manager URLs” under “File -> Preferences” and the microcontroller’s entire toolchain and utilities will be downloaded automatically by installing this board from “Board Manager” under “Tools -> Board”

After that, you may download the source code from Github at Github.

The last thing you need to do is to edit the following information on the code you just downloaded and then you are ready to hit that “Upload” button at last and get the code flashed on ameba in seconds.

Step 3: Hardware Connection

You may refer to supplies section to get a list of things that you need.

First you need to build a “house” from the carton box, not too fancy, this one below will do.

The circuit connection is rather straightforward, check the connection map below to get everything connected.

Once connection is done, you may glue the servo to the wall of your carton house while connecting its arm to the curtain, glue the reed sensor on one side of the curtain and glue the magnet to the other side of the curtain. Take note that, by default, reed sensor and magnet are supposed to be adjacent to each other until servo motor pull the curtain and drag it away with it.

The purpose of the reed sensor is to let ameba knows if the curtain is closed or opened. Last but not the least, glue the DHT11 sensor to the other side of the wall, it will help to measure the “room” temperature and is supposed to tell ameba if the room is getting too much sunlight that raised the temperature to an uncomfortable level. If the room is indeed to hot, it will automatically close on the curtain and send the user a MQTT message.

Step 4: Phone Setup

In order to control the curtain remotely through MQTT, we first need to install a MQTT client. There are many free MQTT client app on Playstore for Android and Appstore for iOS. Here is the android version and the iOS version.

No matter which version you use, the setup procedure are identical,

Firstly, you need to fill in the MQTT server address -> “cloud.amebaiot.com”;

Secondly, fill in the port number -> “1883”;

Thirdly, fill in topic to subscribe -> “outTopic”;

Fourthly, fill in topic to publish -> “inTopic”;

Fifthly, fill in your MQTT cloud service username and password;

Lastly, hit “connect” button to get connected.

Once connected, you will receive a “---MQTT server connected!---” message sent from ameba as confirmation of successful bidirectional connection. Now, you may send an “on” message to open the curtain and “off” message to close it anytime you like!