How to control a relay module using Arduino Cloud

How to control a relay module using Arduino Cloud

Hello and welcome back. In this project, we will learn how to control a relay module using Arduino Cloud. For that, I have used the Arduino UNO R4 WIFI board. I’ve also connected an AC bulb to the relay module, but you can swap it out for something else if you prefer. The cool thing is, you can control it from anywhere in the world using your computer or smartphone. If you want to know about the Arduino cloud, please use this link. Specially I have designed my own relay module using JLCPCB. You can customize and expand on it however you like, using the knowledge gained from this project.

Ok, let’s do this project step by step. The required components are given below.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

(adsbygoogle = window.adsbygoogle || []).push({});

Step 1

Firstly, identify these components.

Step 2

Secondly, let’s order our Relay PCBs with JLCPCB. For that, follow the instructions below.

  • First, go to the JLCPCB official website and log in to your account. If you are a new member of this, please use this link. Then, you can get a 60$ coupon for orders to PCBs. Also, you can order 6 Layer PCBs using the following links.
  • JLCPCB: 48-Hour Turnaround for 6 Layer PCBs! — Click on me
  • Limited Time Offer: Get $10 OFF on JLCPCB 6-Layer PCBs! — Click on me
  • Now, click the instant quote button and upload the Gerber file. You can download it using the link below.
  • Gerber file — Download
  • I have ordered 5 PCBs with Red color. You can also remove the order number on PCBs.
  • Then, select the build time and shipping. Finally, click the save to cart button.
  • Now, open your cart and click the secure checkout button. Then, enter your shipping details and shipping method.
  • Next, submit your order and pay for this using Paypal, Debit Card, Credit Card, or Coupon. Then, it will be received soon.
(adsbygoogle = window.adsbygoogle || []).push({});

Step 3

Thirdly, unbox your PCB package and check it. The JLCPCB PCBs manufacturing process is of high quality so there is no need to worry about the quality of PCBs.

Step 4

Now, apply soldering paste and paste one by one SMD components on the PCB. Then, solder them using a hot air gun or hot plate. I used a hot air gun.

Step 5

Next, solder the relay, female header, and three-pin terminal to the PCB.

Step 6

Now, connect the Relay module to the Arduino board. For that, use the circuit diagram below.

How to control a relay module using Arduino Cloud
(adsbygoogle = window.adsbygoogle || []).push({});

Step 7

Ok, let’s set up Arduino cloud. For that, follow the instructions below.

  • First, connect the Arduino board to the computer. Then, go to the Arduino Cloud website and create a new account using your email. Then, log in to your account and click the Get Started button.
  • Arduino Cloud -> Click on me
  • Then, add your device to the cloud. For that, download and install the Arduino agent program.
  • Now, the Arduino agent program will run on your computer. Then go back to the web editor and click the Devices tab. This step will automatically detect your Arduino UNO R4 WIFI board.
  • Next, click the Configure button. Then the firmware and necessary files will be updated. After this process unplug your Arduino board and reattach it. Then, click the Continue button and name your board as you like. Finally, click the done button.
  • Afterward, click the Things tab and associate your device. Next, enter your network credentials. For that, click the configure button and enter your WIFI SSID and password.
  • Next, add one boolean variable. For that, click the Add button.
  • Now, copy and paste the following program into the Sketch tab and click the Upload button.
  • Code, Circuit, and Gerber file — Download
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  bool relay;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.

#include "thingProperties.h"

#define relayPin 2

void setup() {
  // Initialize serial and wait for port to open:
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found

  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, HIGH);

  // Defined in thingProperties.h

  // Connect to Arduino IoT Cloud

     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4

void loop() {


  Since Relay is READ_WRITE variable, onRelayChange() is
  executed every time a new value is received from IoT Cloud.
void onRelayChange()  {
  if (relay) {
    digitalWrite(relayPin, LOW);
  } else {
    digitalWrite(relayPin, HIGH);
(adsbygoogle = window.adsbygoogle || []).push({});
  • Next, click the dashboard tab and add one switch widget. Then, link the variable you created earlier.

Everything is done. The Arduino cloud is ready for you.

Step 8

Now, connect the bulb holder to the relay module. Use the circuit diagram above for that. I have used a plug top to supply the AC voltage. You should work carefully with AC voltage. If you don’t like this step, please skip it.

(adsbygoogle = window.adsbygoogle || []).push({});

Step 9

Next, install the bulb on the bulb holder and provide AC voltage using the plug top. Also, connect the DC power to the Arduino board.

Step 10

Finally, download and install the Arduino cloud app from the Play Store or App Store. Then, log in to your account. Now you can control the relay module from anywhere in the world with web and mobile dashboards.

OK, enjoy your project. The full video guide is below. So, we hope to see you in the next project. Have a good day.


  • Check jumper wires
  • Check your WIFI SSID and password.
  • Check AC and DC voltages.
  • Verify the health of your components.

How to control a relay module using Arduino Cloud

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *