WHAT'S NEW?
Loading...

Arduino MULTIPLE LED Control from Computer

Hello, controlling a single LED at your command from the computer was good but now the challenge is to control multiple LEDs from the computer such that each LED is turned on and off at our wish.




Before this, you should read : Arduino Serial LED Control from Computer

We have to define a total of 12 variables, two operations for each LED.

Mostly, alphabet/numeric keys from the computer keyboard are used to give commands to the Arduino to control the output pins through the serial communication.

Let’s get started with the Arduino multiple LEDs serial communication project.

Things you will need:

1. Arduino Uno
2. Breadboard
3. Arduino Cable
4. LED 5V (red, yellow or green) *6
5. Jumper cables
6. Resistor – 220 ohm *6

Step 1: Making the Circuit



1. Fix the LEDs on the breadboard such that the two legs of the each LED do not short and the positive terminal (the longer leg) of each LED is not common with another LED.

2. Short or common the negative terminal (the shorter led) of each LED and connect it to the Arduino Gnd.

3. Connect the pin 2 of the Arduino to the positive terminal of the LED1 with jumper cable.

4. Connect the pin 3 of the Arduino to the positive terminal of the LED2 with jumper cable.

5. Connect the pin 4 of the Arduino to the positive terminal of the LED3 with jumper cable.

6. Connect the pin 5 of the Arduino to the positive terminal of the LED4 with jumper cable.

7. Connect the pin 6 of the Arduino to the positive terminal of the LED5 with jumper cable.

8. Connect the pin 7 of the Arduino to the positive terminal of the LED6 with jumper cable.

Connect the 220 ohm resistor between each output pin and the positive of the each LED so as to protect the LED from getting damaged.

Step 2: Uploading the Code


Enter the following code into the Arduino IDE or paste it. The code would be called by the Arduino to check whether the value entered by us matches. If it does, the corresponding operation would be performed. 

In this code, we use numeric commands in place of strings.


int incomingByte;

void setup(){
  Serial.begin(9600);
 
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
}

void loop(){
  if (Serial.available() > 0) {
     incomingByte = Serial.read();
     if (incomingByte == '1') {
      digitalWrite(2, HIGH);
    }
   
    if (incomingByte == '2') {
      digitalWrite(2, LOW);
   
    if (Serial.available() > 0) {
      incomingByte = Serial.read();
      if (incomingByte == '3') {
      digitalWrite(3, HIGH);
    }
  }
    
    if (incomingByte == '4') {
      digitalWrite(3, LOW);
     
      incomingByte = Serial.read();
      if (incomingByte =='5'){
        digitalWrite(4, HIGH);
       
      }
    }
   
    if (incomingByte == '6');
     digitalWrite(4, LOW);
    
      if (Serial.available() > 0) {
      incomingByte = Serial.read();
      if (incomingByte == '7') {
      digitalWrite(5, HIGH);
     
      }
      }
     
      if (incomingByte =='8');
       digitalWrite(5, LOW);
     
        if (Serial.available() > 0) {
      incomingByte = Serial.read();
      if (incomingByte == '9') {
      digitalWrite(6, HIGH);
     
      }
        }
    
      if (incomingByte =='10');
       digitalWrite(6, LOW);
      
        if (Serial.available() > 0) {
      incomingByte = Serial.read();
      if (incomingByte == '11') {
      digitalWrite(7, HIGH);
     
      }
        }
       if (incomingByte =='12');
       digitalWrite(7, LOW);    
    }
  }
}


Now, connect the Arduino to the computer via the USB cable provided and choose the correct COM port.  Click on the upload button from the toolbar. And, wait till the software says “Done Uploading”.

Step 3: LED Control from Computer


Now that the code is uploaded, open the serial monitor (Ctrl+Shift+M) from the Arduino software, it may appear in a new window. The serial monitor would be initially blank and has an input box on the top.

Enter “1”. The Led 1 should be turned on.

Whoa! Did you see that? The LED just turned on immediately without delay.

Now, Enter “2”. The Led 1 should be turned off. Similarly, Enter “3”. The Led 2 should be turned on.

And so on...till the numbers hit 12.

All six LEDs may be turned on by hitting their respective commands i.e 1,3,5,7,9,11 each at a time. So you get the idea that you may control the multiple output pins from your computer and Arduino works as you wish.

Congratulations! You have just completed your Arduino Project – simple, fun and easy.

Add or subtract the number of LEDs that may be maximum 14 (I/O pins) by defining each pin as the output pin in the code. Example - pinMode(8, OUTPUT);


Stay Hungry! Stay Foolish!




Arduino Serial LED Control from Computer

Hello, 

Arduino also works on manual commands by the user who controls it and may turn on/off or control the output digital pins and hence the device connected at that pin.





Mostly, alphabet/numeric keys from the computer keyboard are used to give commands to the Arduino to control the output pins through the serial communication.

Let’s get started with the Arduino serial communication project.

Things you will need:

1. Arduino Uno
2. Breadboard
3. Arduino Cable
4. LED 5V (red, yellow or green)
5. Jumper cables
6. Resistor – 220 ohm

Step 1: Making the Circuit


You may connect the LED or skip this step as the Arduino Uno R3 (a common development board) comes with inbuilt LED at pin 13. But, we shall make the circuit so as to understand the pins connections and get hands-on experience.


1. Fix the LED on the breadboard such that the two legs of the LED do not short.

2. Connect the pin 13 of the Arduino to the positive terminal (the longer leg) of the LED with jumper cable.

3. Connect the Gnd of the Arduino to the negative terminal (the shorter leg) of the LED with jumper cable.

4. Connect the 220 ohm resistor between pin 13 and the positive of the LED so as to protect the LED from getting damaged.

Step 2: Uploading the Code


Enter the following code into the Arduino IDE or paste it. The code would be called by the Arduino to check whether the value entered by us matches with the variable in the code. If it does, the corresponding operation would be performed.

int led = 13; // Pin 13
    
void setup()
{
    pinMode(led, OUTPUT); // Set pin 13 as digital out
    
    // Start up serial connection
    Serial.begin(9600); // baud rate
    Serial.flush();
}
    
void loop()
{
    String input = "";
    
    // Read any serial input
    while (Serial.available() > 0)
    {
        input += (char) Serial.read(); // Read in one char at a time
        delay(5); // Delay for 5 ms so the next char has time to be received
    }
    
    if (input == "on")
    {
        digitalWrite(led, HIGH); // on
    }
    else if (input == "off")
    {
        digitalWrite(led, LOW); // off
    }
}

Now, connect the Arduino to the computer via the USB cable provided and choose the correct COM port.  Click on the upload button from the toolbar. And, wait till the software says “Done Uploading”.

Step 3: LED Control from Computer


Once the code is uploaded, it is time to check the LED output as we desire it to be. If we command it to turn on, it should be turned on and if we command it to turn off, it should be turned off.

Open the serial monitor from the Arduino software (Tools>Serial Monitor), it may appear in a new window. You may also open it by using commands : Ctrl+Shift+M. The serial monitor would be initially blank and has an input box on the top.

Enter the term “on” and hit enter.
Whoa! Did you see that? The LED just turned on immediately without delay.

Now, enter the term “off” and hit enter.
Oh, now the LED just turned off. So you get the idea that you may control the output pins from your computer and Arduino works as you wish.

Congratulations! You have just completed your Arduino Project – simple, fun and easy.

Add another commands for example “yes”, “no” etc or even command multiple LED with just a little update in the code.


Stay Hungry! Stay Foolish!



Arduino LED Blinking Project to Get Started


Hello, 


Arduino development board looks cool but the possibilities of it are even cooler and endless only if you know how to get started with Arduino and create fun and interesting toys and projects. Not only the circuits in many Arduino projects are easy to connect but are fun to play with.




Before this, you should read :


Let’s get started with the Arduino LED Blinking Project

Things you will need:

1. Arduino Uno
2. Breadboard
3. Arduino Cable
4. LED 5V (red, yellow or green)
5. Jumper cables
6. Resistor – 220 ohm

Step 1: Making the Circuit



You may or may not connect the circuit as the Arduino Uno R3 (a common development board) comes with inbuilt LED at pin 13. But, we shall make the circuit so as to understand the pins connections and get hands-on experience.

Arduino LED Blinking Circuit Connections


1. Fix the LED on the breadboard such that the two legs of the LED do not short.

2. Connect the pin 13 of the Arduino to the positive terminal (the longer leg) of the LED with jumper cable.

3. Connect the Gnd of the Arduino to the negative terminal (the shorter leg) of the LED with jumper cable.

4. Connect the 220 ohm resistor between pin 13 and the positive of the LED so as to protect the LED from getting damaged.

Step 2: Uploading the Code



Although, you may find this code easily in the Arduino IDE (Arduino software) in File>Examples>Basics>Blink, you shall also copy the below code and paste it to the sketchbook.

int led = 13;

// the setup routine runs once when you press reset:
void setup() {      
         
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);    
}

// the loop routine runs over and over again forever:
void loop() {

  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second

  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

Now, connect the Arduino to the computer via the USB cable provided and choose the correct COM port. Then, click on the upload button from the toolbar. And wait till the software says 'Done Uploading'.

Step 3: LED Blinking



You may now observe the behavior of the LED on the breadboard, the LED turns on and off after a fixed interval of time of one second.



The time interval may be varied by altering the delay();  value and consequently the behavior of the LED may be changed.

Congratulations! You have just completed your Arduino Project – simple, fun and easy.

Watch it blink all day, add different colors LED or connect multiple LEDs at once.







Stay Hungry! Stay Foolish!