Project tutorial
Smart Plug with Arduino MKR WiFi 1010

Smart Plug with Arduino MKR WiFi 1010 © CC BY-SA

In this tutorial we are going to create a smart plug to turn on or off the light of a lamp remotely using Google's voice assistant.

  • 2,242 views
  • 0 comments
  • 12 respects

Components and supplies

Mkr wifi 1010 usibb9nl4v
Arduino MKR WiFi 1010
×1
Arduino MKR Connector Carrier
×1
5V Relay module
×1
Panasonic 2 rechargeable Panasonic NCR18650B Li-Ion batteries (3400 mAh, 3.7V).
×1

About this project

INTRODUCTION

In this tutorial we are going to create a smart plug to turn on or off the light of a lamp remotely using Google's voice assistant.

We will use the IFTTT web service. This service allows us to create / schedule actions between different applications. In our case we will link the Google voice assistant with the Adafruit IO Cloud.

The procedure will be as follows:

Using the Google voice assistant and saying the voice command "turn on the light" will record the "ON" value in a "feed" of the Adafruit IO Cloud and when we say "turn off the light" the value "OFF" will be recorded.

These values ​​will be read continuously using an Arduino MKR WiFi 1010 board. If the value read is “ON” a relay will be activated that will cause the lamp light to turn on (the circuit will be closed) but if the value is “OFF” the lamp light will turn off (the circuit will open).

PARTS LIST

  • Arduino MKR WiFi 1010
  • Arduino MKR Connector Carrier
  • KS0011 Keyestudio 5V Relay
  • 2 rechargeable Panasonic NCR18650B li-ion batteries (3400 mAh, 3.7V)
  • Battery holder for two 18650 batteries with power cable
  • 4-pin female converter cable from Grove to Dupont connector
  • Electricity cables
  • Electrical connection strips
  • Electrical connection box
  • 220 VAC male electrical plug
  • 220 VAC female electrical plug
  • 3 mm thick wood
  • M3 separators (20mm) and screws

ADAFRUIT IO CLOUD

The first thing we will have to do is create a Feed in the Adafruit IO Cloud.

Step 1: Go to Adafruit IO Cloud: https://io.adafruit.com/

Step 2: We will create a "feed" called "ON_OFF" within the DEFAULT group.

Check out the following guide to understand the basics of creating a feed:

https://learn.adafruit.com/adafruit-io-basics-feeds/overview

Step 3: We will modify the property "Feed History" so that it does not save the value history of this feed (for this example it is not necessary). For this we will put "OFF" this property.

Once the Feed has been created, we can create the necessary actions on the IFTTT website.

IFTTT

Step 1: Go to IFTTT website: https://ifttt.com

Step 2: We will create two actions, one to turn off the light and another to turn on the light.

To create the service that will turn off the light we will follow the following steps shown in the following images:

To create the service that will turn on the light we will perform the same steps but by changing the following parameters of the following screens:

If we have done everything correctly, we will have the two previously created actions in the “My Applets” section:

CIRCUIT

The circuit we will create will be as shown in the following images:

The circuit components will be:

  • Arduino MKR WiFi 1010
  • Arduino MKR Connector Carrier
  • KS0011 Keyestudio 5V Relay
  • 2 rechargeable Panasonic NCR18650B Li-Ion batteries (3400 mAh, 3.7V)
  • Battery holder for two 18650 batteries with power cable
  • 4-pin female converter cable from Grove to Dupont connector

We will power the MKR Connector Carrier with 2 rechargeable Panasonic NCR18650B Li-Ion batteries (3400 mAh, 3.7V) through the connection terminal pins labeled GND and VIN. On the other hand, we will connect the connector labeled D0 to the 5V relay module using a 4-pin female converter cable from Grove to Dupont connector (we only need 3 of the 4 cables).

The D0 connector has a standard four-pin Grove connector and usually the cables that connect to these connectors have four standard colors:

  • pin 1 - Yellow (primary digital input / output)
  • pin 2 - White (secondary digital input / output)
  • pin 3 - Red (VCC)
  • pin 4 - Black (GND)

The connection between the D0 connector of the MKR Connector Carrier and the 5V Relay Module will be as follows:

pin 1 - Yellow cable (i/o) --> S (Signal)

pin 3- Red cable (VCC) --> + (VCC)

pin 4 - Black cable (GND) --> - (GND)

NOTE: The Arduino MKR WiFi 1010 only supports 3.3V I/Os so we need the MKR Connector Carrier which will provide the necessary 5V on all the output pins of its connectors. These 5V are necessary for the correct operation of the 5V Relay module.

Now we will fix all these components to a 3 mm thick wooden support to finally introduce the whole assembly into the electrical connection box.

We will use the N.C pins (normally closed) from the 5V Relay module and connect them to the terminal strip as follows:

Now it will only be necessary to connect the power cables to the terminal strip and put the whole assembly inside the electrical connection box:

SKETCH

As mentioned at the beginning of the tutorial we will use an Arduino MKR WiFi 1010 board to read the value of the Adafruit IO Cloud Feed. If the value read is “ON” a relay will be activated that will cause the lamp light to turn on (the circuit will be closed) on the contrary if the value is “OFF” the lamp light will turn off (the circuit will open).

To get the value of the “feed” that indicates if you have to turn off (“OFF”) or turn on the light (“ON”) we will use the option to get the last value of an Adafruit IO REST API feed (v2.0.0) using the WiFiNINA library.

If we look at the API documentation we see that to take this information we need to make the following call:

GET: /api/v2/{username}/feeds/{feed_key}/data/last

... and deserialize a JSON with the following structure:

{
"id": "string",
"value": "string",
"feed_id": 0,
"group_id": 0,
"expiration": "string",
"lat": 0,
"lon": 0,
"ele": 0,
"completed_at": "string",
"created_at": "string",
"updated_at": "string",
"created_epoch": 0
}

To deserialize the data of the returned JSON we will use the “ArduinoJson” library:

https://arduinojson.org/v6/doc/deserialization/

Finally, we will load the sketch of the following repository on the MKR board and verify that by varying the value of the Feed (“ON / OFF”) using Google's voice assistant it causes the relay to be activated or deactivated causing the lamp to turn on / off :

https://github.com/avilmaru/enchufe_inteligente_wifi

NOTE: Remember that you have to change the following values for yours:

arduino_secrets.h
#define SECRET_SSID "XXX"
#define SECRET_PASS "YYY”
#define IO_USERNAME "ZZZZ"
#define IO_KEY "XXXX"

Code

https://github.com/avilmaru/enchufe_inteligente_wifi

Comments

Similar projects you might like

Monitor Your Energy Bill via Modbus, MKR WiFi 1010 and RS485

Project tutorial by 3 developers

  • 23,349 views
  • 16 comments
  • 71 respects

[IoT] Telegram Bot with Arduino MKR WiFi 1010

Project tutorial by AppsByDavideV

  • 6,862 views
  • 13 comments
  • 22 respects

Plant Communicator with MKR WiFi 1010

Project tutorial by Arduino_Genuino

  • 4,298 views
  • 2 comments
  • 18 respects

Pavlov's Cat with MKR WiFi 1010

Project tutorial by Arduino_Genuino

  • 1,722 views
  • 1 comment
  • 12 respects

The Nerd with MKR WiFi 1010

Project tutorial by Arduino_Genuino

  • 1,510 views
  • 0 comments
  • 3 respects

PuzzleBox with MKR WiFi 1010

Project tutorial by Arduino_Genuino

  • 971 views
  • 0 comments
  • 4 respects
Add projectSign up / Login