Xem mẫu

  1. AN ALERT SYSTEM USING ARDUINO AND NODEMCU SVTH:Đỗ Chí Bằng GVHD: TS Tạ Quang Hùng Tóm tắt - Trong thời gian gần đây, thuật ngữ “Hệ thống nhúng” đã trở nên phổ biến hơn đối với người dân, đặc biệt là sinh viên ngành Công nghệ thông tin (CNTT). Điều này một phần là do sự ra đời của bộ vi điều khiển đơn bo mạch Arduino và bộ vi điều khiển để xây dựng các thiết bị kỹ thuật số. Mặc dù đã có những thiết kế dành cho các thiết bị bảo mật có thể truy cập được trên internet, nhưng rất ít trong số chúng được kết hợp với Internet of Things - một trong những chủ đề nóng hổi liên quan đến CNTT. Bài báo này nhằm mục đích hướng dẫn những người có một số kiến thức nền tảng về CNTT để xây dựng một cảm biến phát hiện người trước khi gửi thông tin đến điện thoại, cảnh báo cho chủ sở hữu của cảm biến. Hơn nữa, bài báo này sẽ giải thích một số chi tiết chính về việc chế tạo thiết bị và sẽ được dùng làm tài liệu tham khảo cho các dự án trong tương lai trong việc tạo ra các thiết bị IoT. Abstract - In recent times, the term “Embedded System” has become more popular to the people especially Information Technology (IT) students. This was partly due to the introduction of Arduino single-board microcontrollers and microcontroller kits for building digital devices. While there has been designs for security devices that are accessible on the internet, few of them are combined with Internet of Things – one of the hot topics regarding to IT. This paper aims to guide people with a some IT background knowledge to build a sensor that detects people before sending the information to a phone, alerting the owner of the sensor. Moreover, this paper will explain some key details about the making of the device, and would be serve as a reference for future projects in creating IoT devices. Key words: Arduino, Embedded System, IoT. I. Introduction The field of security systems is also in development. Security devices are increasingly being introduced to the market and it can be difficult to choose among different types of devices with different functionality. In spite of the many differences between devices, it is important to note that most of the security systems works on the same principle and have similar framework. Noticeably, sensors play a crucial role in the field of security system. There are many types of sensors namely ultrasonic sensor, photoelectric sensor, microwave sensor, Passive Infrared Sensor, noise detector etc. These sensors helps to detect a certain object and report the information back to the controller for further processing. It can be applied to a lot of situation, notably in detecting people. Personally, the idea of making an alerting device came to me as I was working on my computer while wearing a headphone, unaware of the surroundings, only to realized there 103
  2. were guests visiting my parents downstairs. The thought of the question “what if it wasn’t a guest, but a burglar?” came to mind and I started to wonder if it is possible to create a ‘do-it- yourself’ (DIY) device that helps me to detect “uninvited guests” – intruders. However, a wired system with strings and contraptions are only applicable in the movies but not in reality. Wired contraptions and even wired electronic devices are out of date and its applications are limited. Thus, wireless security devices are preferred. They are user-friendly, simple and fast. With a proper battery backup and internet they will still operate wonderfully even during power outages. For that reason, this paper will provide a guide on making a device that can sense people, alerting the owner by sending notifications to a smartphone. II. Component and supplies A. Hardware 1. Arduino Uno According to Felgo on 2020, Arduino is one of the most recommended single-board microcontroller, especially for Embedded Computing. Being one of the most commonly used open-source microcontroller board, Arduino Uno is considered to be the most optimal solution for personal projects. It is the open-source microcontroller board based on the Microchip ATmega382P microcontroller, equipped with 14 digital input/output (I/O) pins and six of which is capable of PWM output. Another 6 programmable analog I/O pins are also equipped. The main reason that Arduino products, namely Arduino UNO is the optimal solution for this project is the simplicity of its set up. The board is programmable with the Arduino IDE (short for Integrated Development Environment), by connecting the board to the computer using a Type B USB cable. This cable can provide power to the board but an external 9-volt battery can also be used as a power source for the Arduino UNO (voltages between 7 and 20 volts are acceptable). Another reason for it’s popularity is due to the large amount of tutorials and guides is available online for further understanding of the board. Since Arduino is open-source, the library available on the internet is huge. People can help each other create and develop new resources for the software improvement. Figure 1: Arduino UNO 104
  3. 2. NodeMCU In a few guides and tutorials in making a similar security device, Bolt IoT Bolt Wifi Module is suggested for IoT integration (Hrushikesh S Bharadwaj & Pawan Kumar, 2020) . However, as a personal experience, I discovered that it is not only expensive, but also not fully available to some countries specifically Vietnam. Thus, to have a cheaper and better solution, this paper will suggest NodeMCU for this project. It is easy to acquire, inexpensive and a larger range of customization. However, regarding cyber security in NodeMCU, it is dependent on the programmer to provide the necessary means to protect the device from hackers to connect and take control of the device. Since this project is served as a personal project, cyber security will not be the main focus of this paper. Figure 2: ESP8266 NodeMCU 3. Ultrasonic Sensor HC-SR04 Figure 3: Ultrasonic Sensor HC-SR04 In this paper, we would suggest the Ultrasonic Sensor HC-SR04 because it is common on the market, with reasonable price and good functionality. This Distance Sensor can report the range of object up to 4 meters away which is enough for our alert system (Sunfounder, 2019). The sensor also use low power so it is suitable in case of using battery power supplies for the device (Lastminuteengineers, 2021). Some notable specifications are the Operating Voltage, Operating Current, Operating Frequency, max Range, min Range, Ranging 105
  4. Accuracy, Measuring Angle, Trigger Input Signal and Dimension are provided in the following table: Operating Voltage DC 5V Operating Current 15mA Operating Frequency 40KHz Max Range 4m Min Range 2cm Ranging Accuracy 3mm Measuring Angle 15 degree Trigger Input Signal 10µS TTL pulse Dimension 45 x 20 x 15mm Table 1: Ultrasonic Sensor HC-SR04 specification 4. Buzzer (Optional) The buzzer (or beeper) is a commonly found component in a lot of devices, and even in some toys. This is an audio signaling device, which can help sending out audio signals to alert people on detection (Sunfounder, 2016). This Buzzer can be coded to send out tunes with different tones by limiting the power current of the buzzer. It is optional depending on the maker’s preference. Figure 4: Buzzer 5. Jumper wires (generic) Jumper wires (also known as Jump wire, Jumper, DuPont wire or cable) is an electrical wire that has a connector or pin at each end or tinned. This is used to wire the component of a breadboard, for example to easily interconnect the pins of the Arduino UNO with other components like the buzzer. It is very cheap and easy to find, but as a tip for beginners, there are 3 types of jumper wires that should be known: the Male to Male, Female to Female and the Male to Female jumper wires. The male end is the end of a jumper wire that has a solid pin tip for plugging into the things such as the breadboard while the female ends do not and 106
  5. are used to plug things into. Depending on the need of what kind of pins the components have, some Male to Male wires are necessary and some Male to Female wires are required. Figure 5: Jumper wires 6. Breadboard When working with Arduino, welding would be extremely troublesome particularly when it is uncertain if a connection is correct or not. For beginners and experimentalists, a breadboard would solve most issues in creating a circuit and building the device. It is absolutely user-friendly and straightforward. The following yellow lines indicates the way the circuit is connected between the holes of the breadboard. Figure 6: Breadboard circuit 7. Button (optional) A push switch or a button is an optional choice in this project because normally it is not required to activate the alarm system manually. In some cases that you wish to turn the device into a doorbell that has the same alerting function, a button would not be irrelevant. Figure 7: Push switch 107
  6. B. Software 1. Arduino IDE Arduino IDE is an application that is noticeably based on C and C++. Not only it is used to write and program Arduino boards, it can also be used for other development boards with the help of third-party cores. It is a free software that anyone can download effortlessly on its official site (https://www.arduino.cc/en/software) . After a few simple steps of installing it – mentioned in a Arduino Introductory book by Alan G. Smith, you are now able to write codes and compile them, ready to upload to your connected Arduino board using just a single click. Figure 8: Arduino IDE 2. Twilio SMS Messaging API Twilio is an American cloud communications platform as a service (CPaaS) company. They provides software developers web service APIs that allows users to make and receive phone calls, send and receive Short Message Services (SMS) and many more communication functions. It is used in this project due to its convenience, programmable features and most importantly, its trial services. For experimental purposes, we will use the free trial of their products, however, a subscription fee would be required for satisfied users who choose to extend their usage on the device or further IoT related projects. III. Implementation A. Software 1. Arduino IDE - Esp8266 support NodeMCU is a firmware that runs on the ESP8266 Wifi SoC and is not manufactured by Arduino, so it is needed to install an extension to Arduino IDE for the software to be able to upload the code to the NodeMCU. 108
  7. 2. CH340 or CP2102 driver In some cases, the UART device cannot recognize your NodeMCU. This maybe due to the lack of correct driver in your computer. Your purchased ESP8266 NodeMCU may has a CP2102 chip or a CH340 chip. This can be solved by updating the driver for the chip. 3. Twilio account setup Setting up a Twilio number is an important part of the device. Noticeably, there are three key items that is needed for NodeMCU: - Your trial number is the number you will receive the SMS from. - Your account SID which can be copied and should be kept to yourself. - Your Auth token which is extremely important and must be kept a secret. B. Schematics 1. Precaution In some guides, it is said to connect the Arduino Tx pin to the ESP8266 NodeMCU Rx pin. A caution regarding this method is that it possesses the risk of damaging the ESP8266 NodeMCU pin due to the pin working on 3.3V (Robotica DIY, 2020). This problem should be solved by using a voltage divider or reducing the Arduino’s power supply voltage. Figure 9: Voltage divider (Fritzing) Another notable precaution is that the wiring process should be done with great care. A 109
  8. clean and clear board is always approved. Moreover, in order to avoid short circuit, it is supported to always visually check the circuit and to measure the voltage between two ends. 2. Wiring For experimental purposes and for simplification of the process, we will connect the D1 and D2 GPIO pins to the Arduino UNO. Since SoftwareSerial Library will be used for Serial Communication between Arduino UNO and the NodeMCU, the mentioned pins specifications will also operate smoothly. Therefore, the following circuit design will be used. Figure 10: Demonstration of the circuit Figure 11: Alert system schematic 110
  9. C. Mechanism 1. Arduino UNO After defining the pins and establish the Serial Communication between Arduino UNO and NodeMCU by using SoftwareSerial library, the sensor will start scanning for any response changes of its max travelling distance. These values may varies but once it reached under 30, meaning there is an obstacle blocking the sensor, making the buzzer to be activated and the alert system activated. Controled by the Arduino UNO, a byte type data of “115” – which in ASCII codes imply the character “s”, to the NodeMCU. Figure 12: Ultrasonic Sensor triggering Figure 13: Arduino UNO output 2. NodeMCU In the beginning, the NodeMCU will initiate the pins as well as the Serial Communication with the Arduino UNO, before declaring the key variables: the ssid of the wifi, the password of the wifi, the Twilio account sid, the Twilio’s authentication token, the Twilio number, the user’s phone number and the message body. On the declaration step, a Fingerprint array is provided by Twilio, although it may be changed in the future, it can be updated on Twilio’s document page. By connecting to Twilio 111
  10. API service using the guide from their official page (Twilio, 2020), the NodeMCU can now send request to Twilio using the “sendSMS()” function. Figure 14: NodeMCU output On setup function, NodeMCU will run a check whether it can connect to the Wifi using the declared SSID and password, while checking for a connection to Twilio API service with the declared SID and token. After the process, the NodeMCU is now ready to work and receive data from Arduino. If a 115 byte data is received from Arduino UNO, the program will recognize it as a trigger to send a SMS to the registered phone, alerting the owner (TigerFarmPress, 2020). Figure 15: SMS received 112
  11. IV. Conclusion Obviously the paper is guided towards making an alert system with IoT integrated. However, it shows the possibility of multiple different applications for sensors and IoT alike. With some tweaking, this device could be programmed to become a monitoring program or a sensor of a Wifi controlled car. In summary, with the help of Arduino and open-source resources, Embedded System and IoT related projects (e.g., a security system) are now more accessible for everyone. REFERENCES [1] Alan G. Smith, (2011) "Introduction to Arduino" (PDF). princeton.edu. Archived from the original (PDF) on 3 April 2018. Retrieved 4 February 2018. [2] Felgo, 2020. "6 Best Microcontrollers: Hardware for Embedded Computing" https://blog.felgo.com/6-hardware-for-embedded-development [3] Hrushikesh S Bharadwaj, (2020) "Intruder ALERT!!!" https://create.arduino.cc/projecthub/8951886314hsb/intruder-alert-4d687c [4] Lastminuteengineers.com, "How HC-SR04 Ultrasonic Sensor Works & Interface It With Arduino" https://lastminuteengineers.com/arduino-sr04-ultrasonic-sensor-tutorial/ [5] Magesh Jayakumar, Quick Start to Nodemcu (ESP8266) on Arduino IDE. https://www.instructables.com/Quick-Start-to-Nodemcu-ESP8266-on-Arduino-IDE/ [6] Pawan Kumar, (2020) "Intruder Alert System" https://create.arduino.cc/projecthub/saipavan4/intruder-alert-system-12df59 [7] Robotica DIY, (2020) "Send Data From Arduino to NodeMCU and NodeMCU to Arduino…" https://www.hackster.io/RoboticaDIY/send-data-from-arduino-to-nodemcu-and- nodemcu-to-arduino-17d47a [8] Sunfounder, 2016 "Buzzer modules". http://wiki.sunfounder.cc/index.php?title=Buzzer_modules [9] Sunfounder, 2019 "Ultrasonic Module". http://wiki.sunfounder.cc/index.php?title=Ultrasonic_Module [10] TigerFarmPress, "Send an SMS Using an ESP8266" https://www.instructables.com/Send-an-SMS-Using-an-ESP8266/ 113
nguon tai.lieu . vn