Buy from US Buy from UK Buy from DE Buy from FR Buy from IT Buy from ES ここでご購入を!

In this project, we will make a simple RFID (IC card) + IoT controlled security door system. We use Cell phone APP to send control signal through UDP protocol similar to Lesson 8.

Security Door normally is often opened by servo motor. To make things simple, we just use servo turning 180 degree to imitate door open and rotate back to 0 degree to imitate door close.

The whole procedure will be work as follows:
When an IC card  detected by RC522 RFID module, Arduino will verify if its ID matches record.

If ID matches record, then servo turn 90 degree . Green LED turn on and Red LED turn off.

If  ID does not match record, then, servo does not move, instead, the buzzer will alarm(you need use browser to turn off alarm from remote computer).

At any time, remote browser can open the door(servo rotate to 90 degree) or close the door (servo back to 0 degree)  or turn off buzzer and monitor door status.

First, please plug OSOYOO MEGA-IoT Extension Board into MEGA2560 board:

Then connect the modules with the OSOYOO MEGA-IoT Extension Board with three 3-pin PnP cables and one 8pin 12cm Female to Female Cable as below (Jumper Cap should connect ESP8266 RX with A8, TX with A9):

Green LED Module – D12

Red LED Module – D11

Buzzer Module – D5

Micro Servo Motor – D3

RFID Module – RFID

Notice: Shut off your battery or Unplug your power adapter when upload sketch code to Arduino.

Step 1 Download OSOYOO Wifi UDP Robot Car control APP
In Google Play or Apple Store, please search key words “OSOYOO Wifi UDP Robot Car”, you will find an orange icon APP as following:

Step 2 WifiEsp Library Installation (if you have installed WifiESP library, please skip this step)

OSOYOO MEGA-IoT extension TX/RX pin to Arduino A9/A8 pin by default. So in Arduino sketch code, we need use Software Serial Port to communicate with ESP8266 (set A9 as TX and A8 as RX in softwareserial object).

To use this wifi shield in Arduino IDE, we need download WiFiEsp-master library from following link:

Open Arduino IDE, click Sketch – Include Library- Add .Zip library to load above zip files into Arduino IDE.

Step 3 RFID Library Installation

You also need install RFID library and save it as above operations.  Please read following article to test RFID library:

Osoyoo MEGA-IoT Shield RFID Tutorial: Get ID of a RFID card

Remember to change write down the RFID number of one ID card.

Step 4 After installing above library, please download the main code from following link, unzip it, you will see a folder called “smarthome-lesson16”:

Step 4 After above operations are completed, connect OSOYOO MEGA2560 Board to PC with USB cable.

Step 5 Arduino IDE:  Choose corresponding board type and port type for you project .

Step 6 Arduino IDE:  Click file – Open, then choose code “smarthome-lesson16B.ino” in the folder, load up the  sketch onto your Arduino.

Remember to change the lines 19 of the code with the card number you got from Step 3):
unsigned char my_rfid[] = {186,11,86,89,190}; // replace {186,11,86,89,190} with your own RFID card number

Note: In the  sketch, find  line 31 32 as following:

char ssid[] = "******"; // your network SSID (name)char pass[] = "******"; // your network password

please replace the ****** with your correct wifi SSID and password, otherwise your project can not connect to Internet.

After loading the sketch to Arduino , open the serial monitor in the upper-right corner of Arduino IDE, you will see following result:

From the serial monitor, you can see the IP address of your MEGA2560 board in the read circle (in above picture, IP is, default port 8888, you need to set this IP address and port number in cell phone APP.

Now Open your Orange color APP and click Setting, write IP address into the APP as following:

Running Result:
When you use an IC card which matches the value in code line 19, the door will open(servo rotate to 90 degree) and Green LED is ON.

When you use an IC card which does not match value of line 19, the door will NOT open and RED LED is ON. Buzzer will also alarm.

If you use Cell phone APP to control the Servo, the control method  will be as following:

when you click ◄ button, the servo will point zero degree, Green LED is OFF.
Serial Monitor will show Close THE DOOR!

when you click ▲ button, the servo will point 90 degree, Green LED is OFF.
Serial Monitor will show Half Close THE DOOR!

when you click ► button, the servo will point 180 degree, Green LED is ON.
Serial Monitor will show OPEN THE DOOR!

when you click || button, the buzzer will turn off.