Utilize Arduino in a simple home automation system

 

ULN2803 Relay Driver Working



In this tutorial, we are going to see the ULN2803 Relay Driver Working Function. Let’s Start.


Introduction of ULN2803

The ULN2803 is a high-voltage, high-current Darlington transistor array. The device consists of eight NPN Darlington pairs that feature high-voltage outputs with common-cathode clamp diodes for switching inductive loads. The collector-current rating of each Darlington pair is 50v/500 mA. The Darlington pairs may be connected in parallel for higher current capability. This article brings out the working of ULN2803 IC and how to use it in a circuit.

Applications include a stepper motor, relay drivers, hammer drivers, lamp drivers, display drivers (LED and gas discharge), line drivers, and logic buffers. The ULN2803 has a 2.7-k series base resistor for each Darlington pair for operation directly with TTL or 5-V CMOS devices.

Purpose of ULN2803

Most of the Chips operate with low-level signals such as TTL, CMOS, PMOS, NMOS which operate at the range of (0-5)v and are incapable to drive high power inductive loads. However, this chip takes low-level input signals (TTL) and uses that to switch/turn off the higher voltage loads that are connected to the output side.

Features

  • Internally frequency compensated.

  • Large DC voltage gain: 100 dB.

  • Very low supply current per operator essentially independent of the supply voltage.

  • Low input bias current: 20 nA (temperature compensated).

  • Low input offset voltage: 2 mV.

  • Differential input voltage range equal to the power supply voltage.

  • Large output voltage swing 0 V to (VCC – 1.5 V).

ULN2803 Relay Driver Working

The ULN2803 IC consists of eight NPN Darlington pair which provides the proper current amplification required by the loads. We all know that the transistors are used to amplify the current but here Darlington transistor pairs are used inside the IC to make the required amplification.

Darlington Working

A Darlington pair is two transistors that act as a single transistor providing high current gain. In this pair, the current amplified by the first transistor is further amplified by the next transistor providing a high current to the output terminal. When no base voltage is applied that when is no signal is given to the input pins of the IC, there will be no base current and the transistor remains in the off state.

When high logic is fed to the input both the transistors begin to conduct providing a path to ground for the external load that the output is connected. Thus when an input is applied corresponding output pin drops down to zero thereby enabling the load connected to complete its path.

Pin Diagram



Interfacing of Relay with Arduino using ULN2003

For interfacing of relay with arduino using ULN2003, we need ULN IC (it can also be done with transistor but ULN is better option) in between arduino & relay because relay can generate back EMF because of its coil and this back EMF can affect our arduino board, so to save our controller or development board side circuitry we will use ULN2003 IC as relay driver.

REQUIRED COMPONENT

S.N.COMPONENTQUANTITY
1.Arduino Uno1
2.Relay DC 12 V1
3.ULN2003 IC1
4.Button (switch)1
5.Resistor 1K ohm1
6.Resistor 220 ohm1
7.LED 2.2 V, 10 mA1
8.Power Supply 12V, 1A1
9.Connecting Wires

INTERFACING OF RELAY WITH ARDUINO USING ULN2003

ARDUINO CODE INTERFACING OF RELAY WITH ARDUINO – DC LOAD (5V, 12V, 24V….)

INTERFACING OF RELAY WITH ARDUINO USING ULN2003
ULN with DC LOAD

ARDUINO CODE INTERFACING OF RELAY WITH ARDUINO – AC LOAD (~ 220 V)

We can connect LEDs for low voltage or high voltage appliances like 110/220 V, 60/50 Hz AC appliances using a relay. For connecting, AC appliances see the circuit diagram below and code remains the same.

AC LOAD WITH ARDUINO AND ULN2003
ULN with AC LOAD

As we know ULN IC are Darlington pair IC and have transistors on the chips, we know transistor has 3 terminals namely baseemittercollector so the inputs are base ranges from 1B to 7B with grounded common emitter to all seven drivers and corresponding collectors as output for each base input. +12V to COM point is for a flyback diode that protects the circuitry from back EMF.

OUTPUT

When you push the button it gives a HIGH signal, which in turn gives a HIGH signal as OUTPUT from pin 13 to trigger the relay, this will turn ON either DC or AC appliance. And as you release button, appliances will turn OFF.


Here are some ways to use Arduino in a home automation system: 
  • Temperature monitoring: Connect a temperature sensor to the Arduino and program it to monitor the temperature and adjust your HVAC system based on your preferences. 
  • Remote control: Add WiFi connectivity to allow you to remotely control and monitor your home automation system. 
  • Connect home appliances: Use a relay to connect home appliances to the Arduino board. 
  • Use a Bluetooth module: Connect a Bluetooth module to the Arduino board and use a smartphone app to communicate with it. 
  • Create a graphical user interface: Use a website like RemoteXY to create a graphical user interface for your smart home applications. 
  • Add sensors: Use sensors for gas, flame, light, temperature, humidity, and rain. 
  • Add a fire alarm: Add a fire alarm to your home automation system. 
Other things you can do with Arduino in a home automation system include: Create an internet controlled lighting system, Create an automatic ventilation system, Create an automatic folding bed, and Create automatic blinds.

Development of Smart Home Applications Based on Arduino and Android Platforms: An Experimental Work

by  1,2,*, 3, 3, 3 and 1
1
Mechanical Engineering Department, Faculty of Engineering, South Valley University, Qena 83523, Egypt
2
Mechanical Engineering Department, College of Engineering, Fahad Bin Sultan University, Tabuk 47721, Saudi Arabia
3
Health Technical Institute, South Valley University, Qena 83523, Egypt
*
Author to whom correspondence should be addressed.
Automation 20223(4), 579-595; https://doi.org/10.3390/automation3040029
Submission received: 23 August 2022 / Revised: 24 September 2022 / Accepted: 5 October 2022 / Published: 10 October 2022

Abstract

The ideal smart home could be automatically controlled using a variety of electronic tools and devices to perform everyday tasks. Smart home automation is crucially beneficial for human life, particularly when considering those with disabilities, inpatients, and elderly populations. In this paper, applications and systems for smart homes are investigated. During experimentation they were controlled via an Android mobile phone and the Arduino platform. Bluetooth Module HC-06 was used to connect the Arduino Uno R3 with the mobile phone. Five smart home applications were developed to control the lighting and electrical sockets, fan speed, temperature- and humidity-meter display/controls, as well as the fire-alarm and toxic-gas alarm systems. Herein, the definition, the graphical user interface, the required main components, and the control circuit connections are prepared and presented for each application. The graphical user interface was created using the RemoteXY website, which is a reliable website for this purpose. The developed applications were tested, and they were found to work efficiently and correctly. Additionally, this innovative system is both cost-effective and affordable (total cost at the time of development was 110 USD).

1. Introduction

Smart homes are very beneficial to people, particularly for those with long-term disabilities, inpatients, elderly populations, people experiencing debilitating diseases, and those who have been through painful accidents and/or injuries, thereby requiring them to be in the care of someone else. Since the smart systems work with a single click of a button, they provide immense convenience and utility. With a smart home, a person can control the air conditioner, turn the lights on and off, and can see who is standing at their door, all regardless of their physical location. In addition to the attained comfort, smart homes are an effective way to reduce utility expenses like electricity, water, and fuel. Furthermore, these homes provide people with increased safety through the use of sensors that can better detect the presence of fire and/or toxic gas leakage. Additionally, they provide improved security with the ability to install CCD cameras that are turned on 24/7 to aid in theft prevention and investigation. In general, these homes make human life easier by saving effort and time when compared with traditional homes [1,2,3,4,5].
Researchers have paid great attention to developing smart home systems and applications. Programmable logic controllers (PLC) and the Arduino platform are usually used for these purposes. Based on PLCs and human machine interfaces (HMI), Sasikala et al. [6] used ladder diagrams for controlling only the ON and OFF status of electrical devices that were found in different rooms from the control room. In their approach different smart home applications were not considered, and the required cost was not clear. In [7], Yilmaz used a PLC for controlling a home automation system. Their developed applications facilitated fault detection and tolerance as well as switching between ON and OFF in areas such as gas sensing, voltage control in power sockets, and the circuits of valve controls. The required cost was not clear, and many components were needed. Barz et al. [8] developed a smart home automation system using a Siemens PLC and an HMI Weintek eMT3070a touchscreen. Their applications were oriented towards the control and monitoring of lighting, room temperature, and irrigation systems. Their smart home was controlled via Ethernet. The required cost was also not clear. PLCs were also employed in ref. [9,10,11,12]. Most of these developed systems that used PLCs were not controlled remotely and they were only developed for local use. In addition, the required cost was high.
The Arduino platform, which is affordable and easy to program when compared with PLCs, has also been used with smart home applications and systems. In [13], Naing and Hlaing used two Arduino Nano units with sensors in the implementation of a smart home automation system. Their developed applications were designed to monitor and control lighting, room temperature, alarms, and a security system. In their approach, the microcontroller was responsible for sending SMS alerts to the owner in the event that the sensors detected an abnormality. Their approach was dependent on a power supply, and if this power supply were to fail the connection would be halted and the SMS alarm functions would be stopped. In addition, the required cost was, again, not clear. In [14], a smart home system was developed using an Arduino unit. Their system controlled electronic devices such as electric bulbs and fans in addition to providing alerts if there was a fire breakout. In case of a fire in the house, the user could be informed via SMS using the GSM Module. Their system was designed for local use only as it was neither WIFI nor Bluetooth enabled. In addition, the required cost was not clear. Raza et al. [15] developed a smart home system using an Arduino unit and an Android mobile application. In their case, the Arduino unit was connected to the Android mobile application via Bluetooth (HC-05) Module, and only the lighting was controlled. Development of other different smart home applications was missing, and the required cost was unclear. In [16], Chandramohan et al. implemented a smart home automation and security system using an Arduino unit and Wi-Fi connection via an android application. Their approach provided intelligent operation and control for only lamps and fans. Other applications were not investigated and the required cost for their approach was unclear. In [17], the authors managed electrical load and home security using the Internet of Things (IoT) based on the Arduino Mega 2560 system. Other smart systems were developed by researchers in [18,19,20,21]. A comparison between all the aforementioned smart home applications, including the main gaps in each system, is presented in Table 1.
Table 1. The comparison between some developed smart home applications stated in literature.
From the analysis thus far and consideration of Table 1, the main gaps and disadvantages of the previous methods that should be considered are summarized as follows:
  • Most of the methods were developed for local use only. Therefore, remote sensing technology should be taken into accounts (e.g., Bluetooth for controlling systems from a short range and Wi-Fi, IoT, or Cloud for controlling systems remotely from anywhere on the globe).
  • Most of the developed smart home applications in prior research are limited to one, two, or three functions. This is not enough. Smart home systems are very beneficial for daily life; therefore, many different applications in the smart home should be developed, controlled, and monitored.
  • The required cost for developing the smart applications is often unclear and rarely presented by previous researchers. Therefore, associated costs should be stated clearly to show if the method is cost effective or not.
  • Using the Arduino platform compared with other platforms is preferable because the hardware is affordable and easy to program.
All the previous gaps and challenges are considered in our presented approach. The main contributions and novelty of this paper are discussed clearly in the following points:
  • A cost-effective concept ($110) for a smart home has been developed and controlled herein via an Android mobile phone and Arduino platform.
  • The interface circuit between the Android platform and the mobile phone using Bluetooth Module HC-06.
  • Five different applications for this smart home have been developed which control the lighting and electrical sockets, fan speed, the display for temperature and humidity settings, the fire alarm system, and the toxic gas alarm system.
  • For all applications, a graphical user interface has been created based on the RemoteXY website.
  • The components, the controls, and the wiring circuit are presented for each application and system. In addition, the system was investigated experimentally, and its effectiveness is proven through this research.
  • The system may relieve elderly populations, those with injuries, and people with disabilities from routine stresses and can provide these groups with increased independence.
  • The system efficiently manages energy consumption and helps with reducing the household’s carbon footprint.
The remainder of this paper is divided into the following sections: Section 2 presents the control unit and the interface between the Arduino and Android platforms. In Section 3 the systems developed for the smart home are explained in detail. The components, the graphical user interface, as well as the electronic and control circuits are presented for each application. In Section 4 some experiments are discussed for the smart home applications. Section 5 summarizes the main important points in this paper and provides some direction for future research.

2. Control Unit and Bluetooth Network

The Arduino UNO R3 and Bluetooth module used in this research are presented below. The Arduino UNO R3 [22,23,24] is extensively used in building projects because of its ease of use and programming. The one used here is a type ATmega328 which provides ports for directly connecting the electronic components, such as sensors, through 14 (entrance or exit) of the digital types of input/output. These 14 digital pins can work as inputs or exits and are used to insert and eject fixed digital signals 0 or 5. Each port can provide a current pull of up to 40 mA. Six of the ports can be used to obtain PWM (Pulse-Width modulation). In addition, the circuit contains a crystal oscillator at a 16 MHz frequency, a USB inlet for communication with the computer, and a separate inlet for energy. The power inputs/outputs are defined as follows: (1) the VIN or DC power jack is an outlet in which the Arduino can be run through an external power source such as a battery, (2) the 5V port can be used for sensors or other circuits, (3) the 3.3V port in which the maximum current value that can be utilized is 50 mAh, and (4) the GND port which is used to connect the ground line. Bluetooth Module HC-06 [25] is used to connect the Arduino Uno with the Android mobile phone. This module is one of the commonly used units with Arduino and it comprises four pins as follows: (1) the VCC pin, which is connected with the Arduino’s 5V output; (2) the GND pin, which is connected to the Arduino’s ground; (3) the TX pin, which is used to send the order from the phone to the Arduino and is connected to the Arduino’s RX; and (4) the RX pin, which is used to drop the order from the phone to the Arduino and is connected to the Arduino’s TX. These connections are shown in Figure 1.
Figure 1. The connections between the Bluetooth Module HC-06 and the Arduino Uno.
RemoteXY [26] is a reliable website on the Internet that helps the programmer create a graphical user interface easily and free of charge. Therefore, this resource was chosen to create the GUI for the smart home applications. Figure 2 shows how RemoteXY works.
Figure 2. The work of RemoteXY in creating the graphical user interface.

3. Smart Home Applications and Their Control Circuits

This section presents the developed five applications of the smart home. These applications are shown in Figure 3. This work was carried out through cooperation between the Health Technical Institute and the Faculty of Engineering at South Valley University, Qena, Egypt. The definitions, the components, and the control circuits for each application and system are discussed in detail in the following subsections.
Figure 3. The five developed smart home applications in this paper.

3.1. Lighting and Sockets Control

The aim of this system is to control the operation of lighting and electrical sockets in the home using an Android phone. In this case, three lamps and two sockets are used. Using the RemoteXY program, the GUI in the phone is arranged as presented in Figure 4. The main components of this system are presented in Table 2.
Figure 4. The graphical user interface used to control the operation of lighting and sockets.
Table 2. The main components used to control the operation of lighting and sockets.
The control circuit is constructed by connecting the first end of the relay to the positive voltage, the second end of the relay to the ground of the circuit, and the third end of the relay to the output no. 8 of the Arduino. The lamp is connected in series with the relay. This circuit is illustrated in Figure 5. The implemented code is divided into two parts: the first part defines the functions of the keys within the RemoteXY software interface, in addition to the name and number of the pin switches that the user operates, while the second part is about defining pin states and integrating them with RemoteXY’s software interface. This code is presented in Appendix A.
Figure 5. The control circuit for the operation of lighting and sockets in the smart home.

3.2. Fan Speed Control

The aim of this system is to control fan speed from the Android phone. In this case two fans are used. Using the RemoteXY program, the graphical user interface on the phone is arranged as shown in Figure 6. The main components of this system are presented in Table 3.
Figure 6. The graphical user interface used to control the speed of the fans.
Table 3. The main components used to control the fan speed.
The control circuit for this system is constructed by connecting the output no. 9 of the Arduino to the base of the transistor. The first end of the fan is connected to the positive voltage, and the second end of the fan is connected to the collector of the transistor. The emitter of the transistor is connected to the ground of the circuit. This circuit is presented in Figure 7. The implemented code is also divided into two parts: the first part provides the definitions for the sliders within the RemoteXY software interface, in addition to the name and number of the pin switches that the user operates, while the second part is about defining states within the sliders and integrating them with RemoteXY’s software interface. This code is presented in Appendix B.
Figure 7. The control circuit for the fan speed in the smart home.

3.3. Temperature and Humidity Measurement

This system measures the temperature and humidity and displays it on the Android phone. Using the RemoteXY program, the GUI on the phone is arranged as shown in Figure 8. The main components of this system are presented in Table 4.
Figure 8. The graphical user interface used to display the temperature and humidity of the smart home on the phone.
Table 4. The main components used to control the humidity and temperature system.
The control circuit of this system is constructed by connecting the sensor VCC terminal to the 5 V output of the Arduino; the sensor GND to the Arduino GND; and the sensor’s OUT to port no. 13 on the Arduino from which it receives the signal. This circuit is presented in Figure 9. The implemented code is divided also into two parts: the first part defines the text and level within the program interface for the RemoteXY program and defines a library for temperature and humidity sensors, whereas the second part programs the texts and levels to display temperature and humidity data. This code is presented in Appendix C.
Figure 9. The control circuit for displaying the temperature and humidity in the smart home.

3.4. Fire Alarm System

The purpose of this system is to turn on an alarm when there is a fire detected inside the house. The implemented graphical user interface on the Android phone is presented in Figure 10. The main required components for this system are illustrated in Table 5.
Figure 10. The graphical user interface on the phone for controlling the fire alarm system in the smart home.
Table 5. The main components for the fire alarm system in the smart home.
The control circuit of this system is constructed as follows. The Arduino port is connected to a power source; the VCC terminal of the sensor is connected to the 5-volt terminal of the power source; the GND end of the sensor is connected to the ground; and the D-OUT for the sensor is connected to the port no. 6 of the Arduino unit. This circuit is shown in Figure 11. The executed code for this part is presented in Appendix D.
Figure 11. The control circuit for the fire alarm system in the smart home.

3.5. Toxic Gas Leak Warning System

The main objective of this system is to turn on an alarm in the event that toxic gases (CH4, CO, or H2S) are leaking and their air-concentration levels rise inside the house. The graphical user interface on the android phone is the same as the one presented in Figure 10. The main components for this system are presented in Table 6.
Table 6. The main components for the toxic gas warning system in the smart home.
The control circuit of this system is constructed as follows. The Arduino port is connected to a power source; the VCC terminal of the sensor is connected to the 5-volt terminal of the power source; the GND end of the sensor is connected to the ground; and the D-OUT for the sensor is connected to the port no. 6 of the Arduino unit. This circuit is presented in Figure 12. The executed code for this system is presented in Appendix E.
Figure 12. The control circuit for the toxic gas warning system in the smart home.

4. Experiments

All the components controlled by the five applications are rigidly connected to a wooden board/panel to simulate the smart home, as shown in Figure 13.
Figure 13. The simulation of the smart home: (a) All of the components (lamps, sockets, fans, and sensors) controlled by the five developed applications are arranged on the front side of the panel. (b) The connections, wires, Arduino unit, Bluetooth unit, and relay are configured on the back side of the panel.
All the developed smart home applications and systems are investigated using the created GUI on the mobile phone. The user turns the ON and OFF switches for the three lamps easily using the mobile phone interface. The two electrical sockets are tested by connecting them to two mobile chargers. When the user switches the socket to ON, the mobile device starts charging and when the person turns it to OFF, the mobile charging is stopped. The user can increase and decrease the speed of the two fans easily using the graphical user interface. The temperature and the humidity data for the surrounding air are displayed correctly in the graphical user interface. When there is a flame or gas leakage detected, the sensors activate their respective alarm system. In conclusion, the developed smart home applications work efficiently and correctly. A demo video for these experiments is available at the following link: https://www.youtube.com/watch?v=LlYoM6kFP_A&t=19s (accessed on 12 June 2022).
Supplementary materials are attached to this paper and available for any interested researcher which contain the implemented code, the used Arduino software, the used alarm voices, and the RemoteXY.

5. Conclusions and Future Work

For this paper, five applications for the smart home were successfully developed and controlled via an Android mobile phone and an Arduino platform. The applications control the lighting and electrical sockets, the fan speed control, the temperature and humidity display, the fire alarm system, and the toxic gas alarm system in a simulated smart home. The required components for these systems were procured and then the controls and wiring circuits were implemented. A GUI designed for use on a mobile phone was created using the RemoteXY software. The developed systems were tested and found to be working efficiency. Finally, this concept is very cost-effective which indicates an encouraging probability of mass adoption and commercialization of similar systems. Furthermore, these systems are easily utilized by beneficial for people with disabilities, those suffering from injury, and elderly populations. In future research, Arduino units could be connected to Android mobile phones via Wi-Fi. In addition, different controllers could be used and investigated such as PLCs. The focus of this paper could also be expanded to the level of smart city applications.







Comments