Day 8 - Section 2 - Activating devices
After the completion of this section the students will be able to:
- describe the Relay device and its uses
- create a circuit with a Relay and a NodeMCU to control a high or low voltage device with their smartphones
- build the code to make their smartphone communicate with the circuit
- create a Relay project in Blynk app
Using a relay to activate other devices
One of the most useful things you can do with the IoT is to control higher voltage (120-240V) devices like fans, lights, heaters, and other household appliances. Since the NodeMCU operates at 3.3V it can’t control these higher voltage devices directly, but you can use a relay to switch the 120-240V current and use the NodeMCU to control the relay.
A Relay is an electrically operated switch. Many relays use an
electromagnet to mechanically operate the switch and provide electrical
isolation between two circuits. In this project we will use a NodeMCU to
control the relay. We will develop a simple circuit to demonstrate and
distinguish between the NO (Normally open) and NC (Normally closed)
terminals of the relay.
The NodeMCU can be programmed to turn on the relay when a certain event occurs, for example when the temperature of a thermistor gets higher than 30° C. Or when the resistance of a photoresistor drops below 400 Ohms. Almost any sensor can be used to trigger the relay to turn on or off. The trigger doesn’t even need to be from a sensor. It can occur at set time intervals, it can be triggered from the press of a button, or even when you get an email.In our case we 'll build a circuit that will activate the relay whenever we press a button on our mobile into the Blynk application.
First of all we have to create the circuit below:
Change the credentials to yours.
If you don't know them, ask the admins. The auth is the key that you
received previously on your email. The ssid is the name of your WiFi
network and the pass is the password.
char auth = "????????????";
char ssid = "XXXXXXXXXX";
char pass = "YYYYYYYYYYY";
Finally Save the file and Press Upload.
If all went according to the instructions, then you can switch ON and OFF the LED.