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.
Requirements
- Arduino Uno R3 + Arduino data cable I already have this broad
- USB 2.0 Male to B Male cable
- Arduino Uno R3 Software I have also downloaded
- One LED light “5MM”
- 300 Ohm resister
- Jumper wire only two (Male to Male)
- Bread broad
- 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 https://www.arduino.cc/
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
Then Click Toolbox Selected TOOL BROAD ARDUINO/GENUINO UNO
Step 7
Then select Tool Box TOOL PORT COM3 ARDUINO UNO
Step 8
Given source code type our Arduino Software
Source Code
- int data;
- void setup() {
- Serial.begin(9600);
- pinMode(13, OUTPUT);
- }
- void loop() {
- if (Serial.available()) {
- data = Serial.read();
- if (data == 'A') {
- digitalWrite(13, HIGH);
- } else {
- digitalWrite(13, LOW);
- }
- }
- }
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 toolbox 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
- public Form1() {
- InitializeComponent();
- serialPort1.Open();
- }
- private void button1_Click(object sender, EventArgs e) {
- serialPort1.Write("A");
- }
- private void button2_Click(object sender, EventArgs e) {
- serialPort1.Write("B");
- }
- if ('this_is' == /an_example/) {
- of_beautifier();
- } else {
- var a = b ? (c % d) : e[f];
- }
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. A simple project will be created and deployed.