How To Switch ON/OFF LED Using ARDUINO UNO And C# Form Applications


This article is for beginners who are interested in the Internet of Things. This article demonstrates how to create two buttons for switching the LED light ON and OFF, with simple Arduino and C# code.


  1. Arduino Uno R3 + Arduino data cable I already have this broad
  2. USB 2.0 Male to B Male cable
  3. Arduino Uno R3 Software I have also downloaded
  4. One LED light “5MM”
  5. 300 Ohm resister
  6. Jumper wire only two (Male to Male)
  7. Bread broad
  8. Visual Studio Any versions
Follow my steps 

Arduino is available in several versions online but you only have to buy  Arduino Uno R3.

Step 1

First connect Arduino from your computer if the  flash light is ON it's successfully connected

Step 2

Go to any browser type this link

Scroll down on windows installer click to download 96MB Software



Step 3

Download the software


Step 4

Then after installation completes this page appears


Step 5

Then select FILL NEW . This will open a new page


Step 6



Step 7

Then select Tool Box TOOL  PORT COM3 ARDUINO UNO


Step 8

Given source code type our Arduino Software


source code

  1. int data;  
  2. void setup() {  
  3.     Serial.begin(9600);  
  4.     pinMode(13, OUTPUT);  
  5. }  
  6. void loop() {  
  7.     if (Serial.available()) {  
  8.         data =;  
  9.         if (data == 'A') {  
  10.             digitalWrite(13, HIGH);  
  11.         } else {  
  12.             digitalWrite(13, LOW);  
  13.         }  
  14.     }  
  15. }  

Step 9

Compiler process is successful



Step 10

Then select the upload a program option 


Step 11

I also have Visual Studio 2017.Then select FILE NEW PROJECT


Step 12

Select Windows form applications Change file name as per your wish


Step 13

Then left corner appears on tool box select search button drag and drop two buttons and search Serial Port drag and drop from form applications


Step 14

Then select serial port1 properties;  modifier will change for public view


Then scroll down to  port name it will change to COM3


Step 15

Button1 click to change from properties will change button name for ON

Button2 click to change from properties will change button name for OFF


Step 16

ON Double click to going to page from Form1.cs file

Again OFF Double click to going to page from Form1.cs file

Then replace this C# source code 


Source code

  1. public Form1() {  
  2.     InitializeComponent();  
  3.     serialPort1.Open();  
  4. }  
  5. private void button1_Click(object sender, EventArgs e) {  
  6.     serialPort1.Write("A");  
  7. }  
  8. private void button2_Click(object sender, EventArgs e) {  
  9.     serialPort1.Write("B");  
  10. // This is just a sample script. Paste your real code (javascript or HTML) here.  
  11. if ('this_is' == /an_example/) {  
  12.     of_beautifier();  
  13. else {  
  14.     var a = b ? (c % d) : e[f];  
  15. }  

Then click Start button or Ctrl+F5 and our program will debug


Click  LED ON and OFF; the  process is working.



LED light switch ON to LED is ON then switch LED LED is OFF. Simple project will be created and deployed.

Up Next
    Ebook Download
    View all
    View all