Rajiv SharmaIoTBoys
Published © Apache-2.0

How to Control LED From Windows PC Using Arduino

I will guide you through the step-by-step process of controlling an LED from your Windows computer using an Arduino board.

BeginnerFull instructions provided2 hours229
How to Control LED From Windows PC Using Arduino

Things used in this project

Hardware components

Arduino Uno
×1
1K Ohm Resister
×3
LED
×3
Breadboard
×1
Jumper Wire
×4

Software apps and online services

Arduino IDE
Arduino IDE
IoT Control Tower

Story

Read more

Schematics

Schematic Diagram

Code

Sketch for Controlling LED using Windows PC

C/C++
int RED_PIN = 5;
int BLUE_PIN = 6;
int GREEN_PIN =7;

String inputString;

void setup() {
  // put your setup code here, to run once: 5-0
  Serial.begin(9600);
  
  pinMode(RED_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
}

void loop() {
  
 inputString = Serial.readString();

  if(inputString != ""){
  
  int delimiterPos = inputString.indexOf('-');

    if (delimiterPos != -1) {
    String pinString = inputString.substring(0, delimiterPos);  
    String stateString = inputString.substring(delimiterPos + 1);  
    
    int pinNumber = pinString.toInt(); 
    int command = stateString.toInt(); //0 = Off or 1 = ON

    if (command == 1) {
      digitalWrite(pinNumber, HIGH);
    } else if (command == 0) {
      digitalWrite(pinNumber, LOW);
    }  
  }  
  }

}

Credits

Rajiv Sharma

Rajiv Sharma

17 projects • 71 followers
Having more than 10 years of experience in IoT and software technology. Founded IoTBoys to share knowledge with IoT enthusiasts.
IoTBoys

IoTBoys

9 projects • 115 followers
Watch, Learn and Built IoT projects | DIY IoT Projects | IoT Projects for College Student.

Comments