Easy Basics: Project 077c Control 5V 8 relay module with Visual Basic app

of Acoptex.com in UNO

Basics: Project 077c

Project name: Control 5V 8 relay module with Visual Basic app

Tags: Arduino, Arduino Uno, 5V relay module, 5V relay, Visual Basic app, Visual Basic, Visual Studio 2017 Community IDE, 8 relay module

Attachments: sketch, relaycontrolappcode

In this project, you needed these parts (Dear visitors. You can support our project buy clicking on the links of parts and buying them or donate us to keep this website alive. Thank you):

1.Arduino Uno R3 (you can also use the other version of Arduino)

2. Arduino IDE ( you can download it from here  )

3.Jumper cables F-M

4. 5V 8 relay module 1 pc

5. Visual Studio 2017 Community IDE


We will learn how to control 8 relay module attached to Arduino board with Visual Basic app.

We are normally using the Serial Monitor of the Arduino IDE to communicate with the Arduino board but today we will use a Visual Basic app that we’ve created. Basically in the Visual Basic app we have 8 buttons which will interact with the Arduino when we press them.

We will show you how to make the Visual Basic app that allows the user to operate 8 relay module attached to the Arduino. 

Important Notes:

  1. When you’re using the Vusual Basic app the Serial monitor on the Arduino IDE must be closed.
  2. You need to match the com port in your Visual Basic code to the right com port you have your Arduino board attached.

Understanding the relay

You can read more about it here.

Signals and connections of the relay module

The 8 Relay module has 8 relays with three high voltage terminals (NC, C, and NO) each which connect to the device you want to control. The other side has three low voltage pins (GND (0V), VCC (+5V); IN1, IN2, IN3, IN4, IN5, IN6, IN7, IN8 (Signal pins) which connect to the Arduino board.

 8 Relay module pinout:

  • NC: Normally closed 120-240V terminal
  • NO: Normally open 120-240V terminal
  • C: Common terminal
  • GND: Connects to the ground pin on the Arduino board
  • 5V VCC: Connects the Arduino’s board 5V pin
  • IN1 - IN8 (Signal): Carries the trigger signal from the Arduino board that activates the relay


The following picture shows the needed connections with the Arduino Uno.

Step by Step instruction

1. Installing Visual Studio 2017 Community IDE

  • See how to do it here.

2. Making Visual Basic app

  1. Once Visual Studio is successfully installed, launch it.
  2. If you are using Windows 10, you can find Visual Studio by typing in the search textbox beside the Start Menu icon - Visual Studio 2017
  3. You will see that the IDE is loading.
  4. After logging in you will see a Start Page.
  5. Make a New project by either following the link on the Start page or from the file menu: File -> New -> Project
  6. You will see the New Project window. Go to the Installed Templates-> Visual Basic -> Select template Windows Forms App (.NET Framework). Framework version (for example we have 4.7.2), change the name of your project to RelayControlApp1 and click on OK button. Please Note that you need to have Net.Framework 4.7.2 installed in your Windows OS.

  7. Visual Studio will create a new project for you. Double-click on Form1.vb in Solution Explorer section. You will see the Form1.vb (Design) tab opened.
  8. Change the Size and Height of the shape by selecting it and going to the Properties in the right bottom corner. You will need to scroll and find Layout->Size, Height and Width. Change to 320, 300
  9. Go to Properties->Appearance->Change Text from Form1 to Relay Control App.
  10. Go to Properties -> Layout->Start position and change from Windows Default Location to CenterScreen.
  11. Go to Toolbox and find a Server Control called Button. Drag it to shape and drop. Do that 16 times as we have 8 relays and need 8 buttons to turn relay on and 8 buttons to turn relay off. If the Toolbox is not visible for you, you can make it visible by going to View -> Toolbox
  12. You can move it to other location too. 
  13. Select Button1 and change Text from Button1 to ON in the Properties. Do the same with other buttons - Button3, Button5, Button7, Button9, Button11, Button13, Button15. Change the Text to ON accordingly.
  14. Select Button2 and change Text from Button2 to OFF in the Properties. Do the same with other buttons - Button4, Button6, Button8, Button10, Button12, Button14, Button16. Change the Text to OFF accordingly.
  15. Go to Toolbox and find a Server Control called Label. Drag it to shape and drop. Do it 9 times.
  16. Select Label1 and change Text from Label1 to Relay 1. Do the same for Label2-Lebel8, change them to Relay 2 - Relay 8.

  17. Select Label9 and change Text from Label1 to Relay Control APP, Text Align change to MiddleCenter and Font Size from Appearance to 15 in the Properties.

  18. Select Relay 1 ON button and go to its Properties. Select Lightning icon and change Action Click to btnrelay1ON_Click. Do the same for other buttons: Relay2 ON - btnrelay2ON_Click, Relay3 ON - btnrelay3ON_Click, Relay4 ON - btnrelay4ON_ClickRelay5 ON - btnrelay5ON_Click, Relay6 ON - btnrelay6ON_Click, Relay7 ON - btnrelay7ON_Click, Relay8 ON - btnrelay8ON_Click
  19. Select Relay 1 OFF button and go to its Properties. Select Lightning icon and change Action Clickto btnrelay1OFF_Click. Do the same for other buttons: Relay2 OFF - btnrelay2OFF_Click, Relay3 OFF - btnrelay3OFF_ClickRelay4 OFF - btnrelay4OFF_ClickRelay5 OFF - btnrelay5OFF_Click, Relay6 OFF - btnrelay6OFF_Click, Relay7 OFF - btnrelay7OFF_Click, Relay8 OFF - btnrelay8OFF_Click

  20. Congrats!!! Design is done. Let's start with code.
  21. Double-click on Relay 1 ON button. The Form1.vb file with code opens. 
  22. Press Save all button to save all modifications done.
  23. Open this file in any Editor program (Notepad, Wordpad, MS Word), select and copy all code to Form1.vb. You need to modify PortName, it should be the port where your Arduino Uno attached (you can check it in Arduino IDE: Tools ->Port->Serial Ports

  24. Click on References from Solution Explorer section with right mouse button and select Manage NuGet packages...
  25. We will need to install two packages: System.IO.Ports and System.IO. Go to Browse tab and in Search field enter System.IO.Ports. Select it from the list and click on Install button. Then click on Accept button and the package will be installed. Do the same with System.IO package.
  26. Save all of your work. Click on the Save All icon in the Visual Studio menu or from the menu select File -> Save All. Let’s get the result of all of our work by running the application. Click on the green arrow icon in the Visual Studio menu to run the application.
  27. By default the buttons are grey. If you switch the relay on or off the button color will change to green or red with corresponding note - Turned on or Turned off.
  28. The compiled exe file saved in:

3. Uploading Sketch

  1. Do wiring.
  2. Open Arduino IDE.
  3. Plug your Adruino Uno board into your PC and select the correct board and com port
  4. Open sketch, verify and upload it to your Adruino Uno.


We learnt how to control 8 relay module attached to Arduino board with Visual Basic app.


  • No libraries required


  • See attachment on the begining of this project

Other projects of Acoptex.com
Easy Basics: Project 101a Ai Thinker A9G GPRS GPS development board of Acoptex.com, Not selected 23-11-2019
Easy Basics: Project 100a Ai Thinker A9 GSM GPRS development board of Acoptex.com, Not selected 22-11-2019

Published at 23-11-2018
Viewed: 4224 times