---
description: >-
  These are the classes/lessons for the "Made in Workshop" training workshops.
  We will be controlling the Centurion gate motors with a 2-channel relay. This
  will close or open the gate.
---

# Controlling a Centurion gate Motor with NodeMCU a 2-channel relay

For this activity we will be controlling the Centurion gate motor with a 2-channel relay. We will be using the Arduino-based nodeMCU and the Blynk mobile app to control the relay. The Blynk app will have two buttons. One will be to open and the other will be to close the gate.&#x20;

This workshop will be 3 hours long and the following objectives need to be covered in this time period.

### Requirements:

* Bring your own laptop installed with Arduino IDE.
* Basic knowledge of electric circuits.
* Android/iOS smartphone installed with the Blynk app.

### What we will provide:

* Centurion Gate motor Box.
* 12VDC battery.
* 12 V power supply for the Arduino IOT 33 micro-controller board.&#x20;
* Relay switch module.
* jumper cables.
* Breadboard.



**The Outcomes of this workshop/Tutorial**

* The main objective will be to open and close the Centurion motor gate using your smartphone.
* Learn how to setup/configure your Blynk app to include buttons to open and close the gate.
* Connect the gate motor to the relay module.
* Setup the power supply to power the Arduino IoT 33 board.
* Setup the 12V battery to power the Centurion Gate motor.&#x20;
* Setup the Blynk library on the Arduino IDE.
* Write the code (on Arduino IDE) to allow communication between the Blynk app and the Arduino IoT 33 board so that you can toggle the relay module to open and close gate.

#### What will you need ?

* NodeMCU dev kit/ Arduino IoT 33 board
* 2-channel relay&#x20;
* An android smartphone with the Blynk app installed.
* male-to-female jumper cables
* a desktop computer/laptop with the Arduino IDE installed&#x20;
* A 12V DC motor&#x20;
* &#x20;

#### Introducing the components:

* **Arduino IoT 33 board -** This will be used as our main controller. It will be used to communicate with the Blynk app. The code/program that will control the&#x20;
* **Relay Switch module -** used to open and close a circuit electro-mechanically or electrically.
*

Circuit setup is as follows:\
&#x20;&#x20;

![](https://3073865318-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ly3RLHyAwTi7Hml5lZN%2F-M0h-mfyzxQzvQAopkZz%2F-M0h9xVKPlNLk9C7FZp6%2Fimage.png?alt=media\&token=36b6bdc2-a149-4d07-8418-e6bac6583e03)



![](https://3073865318-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ly3RLHyAwTi7Hml5lZN%2F-M0buuD_f4T8OTAlKTqe%2F-M0bvDgOar6ntUd3gBxM%2Fcenturiongatemotor.PNG?alt=media\&token=76fd7e60-10b6-473a-bacc-958bd1297acd)

1. Connect one male-to-female jumper cable from the D0 pin on the NodeMCU to the "IN1" PIN on the relay board.  Also connect the D1 PIN to the "IN2" PIN.
2. Connect the GND pin of the relay module to the GND pin of the NodeMCU. Then connect the VCC pin of the of the relay module to the 5V pin (the relay needs a power supply of 5V. A nodeMCU only gives an output voltage of 3 - 3.3V so you will need to use an Arduino Uno or a 5V power supply.
3. Connect the both of the wires of the motor into the COM of each of the relay modules.&#x20;
4. For the DC motor, connect the positive terminal of the power supply to both the Normally Open (NO) pin of the two relay modules. Then connect the negative terminal of the power supply to the two Normally Closed (NC) pins of both the relays.

Credit: [https://www.youtube.com/watch?v=BQOji4i4PEc](https://www.youtube.com/watch?v=BQOji4i4PEc)



If this is the first time working with the NodeMCU, you will need to install the ESP8266 board on the Arduino IDE as demonstrated here:&#x20;

1. &#x20;The first thing you will need to do is install the Blynk app on your smartphone and create a New Project. Once you have created it, you will receive the authentication code via the e-mail address that you you signed up with. \


![Create a New Project](https://3073865318-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ly3RLHyAwTi7Hml5lZN%2F-M03JikBnsQsPlIxMYT4%2F-M03K02CJg0YHYzSCp9x%2Fcreateblynkappname.png?alt=media\&token=9f727bfc-42a5-43e0-b2c7-b6c3367ef790)

![Authentication key generated](https://3073865318-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ly3RLHyAwTi7Hml5lZN%2F-M03KDo9v6nt_nTwJupT%2F-M03L5WWDnQ0DNvgwWIN%2Fcreateblynkapp.png?alt=media\&token=8e54d6f4-10a4-40bc-99ab-1fa9976b8239)

Add two buttons for the two relays one labelled "Open Gate" the other "Close Gate":

![](https://3073865318-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ly3RLHyAwTi7Hml5lZN%2F-M03aBGuy64rMBjviWee%2F-M03b12HjDsusWZnD08v%2FScreenshot_20200214-184846.png?alt=media\&token=c2f04cb8-f763-4516-9310-05f145afef89)

After adding the buttons, click on the "OPEN GATE" one and then change the logic from 0-1 to 1-0 because the output of the NodeMCU is active LOW. Under the PIN tab, assign it the digital pin D0.

Do the same with the "CLOSE GATE" button and assign the digital pin D1 to it.

&#x20;

![Configuring the OPEN GATE button](https://3073865318-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ly3RLHyAwTi7Hml5lZN%2F-M07JHFvoi80dUvQESwd%2F-M07K7L4ckz92QQxiYXx%2FScreenshot_20200215-103136.png?alt=media\&token=f78d6dd0-d417-4408-b0ff-0c9fe11c58ab)



![Configuring the "CLOSE GATE" button ](https://3073865318-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ly3RLHyAwTi7Hml5lZN%2F-M07JHFvoi80dUvQESwd%2F-M07K1CqlstYLfXfwma5%2FScreenshot_20200215-103136.png?alt=media\&token=1609da1c-12d0-456f-a249-0d16139003c3)





2\. The second thing you will need to do is to add the is include the example code for blynk using the nodeMCU board.&#x20;

click on **File > Examples > Blynk > Boards\_WiFi > NodeMCU**&#x20;

This will be the code that you get:

![The example code for Blynk NodeMCU](https://3073865318-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ly3RLHyAwTi7Hml5lZN%2F-M02eixPeXM41UwBxfp7%2F-M02iMEKGedzPuakdQZB%2Fblynk_nodemcu.PNG?alt=media\&token=ec6d9530-c686-4d3a-9744-7fbb32e404af)

```
/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  This example runs directly on NodeMCU.

  Note: This requires ESP8266 support package:
    https://github.com/esp8266/Arduino

  Please be sure to select the right NodeMCU module
  in the Tools -> Board menu!

  For advanced settings please follow ESP examples :
   - ESP8266_Standalone_Manual_IP.ino
   - ESP8266_Standalone_SmartConfig.ino
   - ESP8266_Standalone_SSL.ino

  Change WiFi ssid, pass, and Blynk auth token to run :)
  Feel free to apply it to any other example. It's simple!
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
}

void loop()
{
  Blynk.run();
}

```

