Chapter 11 Smart Home
Previously, we learned to send and receive data to and from the Arduino board through a mobile app, and use the mobile app to control LEDs, servos, etc. However the functions are simple and the interface of the app is relatively primitive. In this chapter we are going to make a feature-rich app with a nice-looking interface. Via which you can control your home appliances with your phone.
Project 1 Special Switch -- Relay
The Arduino UNO board we use can output 5V or 3.3V, and the voltage of common appliances in the home is generally 12V or higher. It’s kind of unlikely to use Arduino to control these appliances. So in this chapter, we will use relay to solve this problem.
1. Understanding relays
2. Using relay to control lights
How the relay works.
When the relay is on, the electromagnet A is charged, and the armature is pulled down to make D and E contact, and the working circuit is closed. When the electromagnet loses power, it loses its magnetism. The spring pulls the armature and cuts open the working circuit. Therefore, the relay is a switch that controls the working circuit using an electromagnet. The advantages of using a relay to control the circuit is that: it uses low voltage to control the high voltage, and, so that we can use Arduino to control high voltage electrical appliances.
Note: the maximum power of the working circuit supported by this relay supports up to 250V / 10A AC devices or 28V / 10A DC devices. Do not exceed the limits during use of relay. Attention: when connecting, if it is a 3.0-5.0V low-power electrical equipment, you can directly connect to the Arduino to supply power. If it is externally powered, pay special attention to your safety.
Relay module interface description
Connect the relay module to UNO Digital Pin 5.
Hardware connection (relay-5)
Please match the colors when plugging
On the working circuit side of the relay, connect the lamp power to the NC and COM ports of the relay.
Note: lamp is off when wiring. Here we use a 12V1A DC power supply for the lamp.
If we don't have a suitable table to use, we can use LED lights or other elements instead of the lamp for demonstration.
With the way a relay controls working circuit, you can close or open the working circuit by sending high or low level to the corresponding pins. Here, we connect the lamp to the port that is normally closed. When relay’s pin has high level, the relay closes the circuit and the lamp is on.
1. Reference program
2. Program analysis
Here we do not need to modify the app. When the app sends data "A", the relay is connected and the table lamp is on; when the app sends data "B", the relay is off and the table lamp is off.
Common applications of relays in life:
We might not be familiar with the name “relay”, and it seems pretty far from our daily life. That’s simple not true. Relays are in almost every electrical appliance in our life.
Car turn signals and relays
When we use the relay, we can hear a crisp “snap” sound when the relay is turned on. Now, we can try to think what appliances make this sound. (Different types of relays are used in different appliances, so you won’t hear exactly same sounds.) For example, the relay is used to flash in the car's turn signal. When the car has the turn signal on, the “tick” sound we hear is made by the relay. Relays are also used in the computers and heating plate in rickcookers.
Now that you have mastered controlling a lamp through the relay, can you use relay to control other appliances? Pay special attention to your safety.