Skip to main content

Many Ways To Light Up LED Part 1: LED Control Using Keyboard and Arduino

HELLO THERE!!!


     How are you guys? I hope everybody's fine always. Today I would like to share with you guys one of the experiments that I made during my free time. There are many ways in lighting up a LED and I would like to share with you guys some of it. In this series I would like to show you guys first on lighting up LED using keyboard control, using bluetooth module, and android app Blynk. 

      For this experiment, the items needed is:

1. Arduino UNO




2. LED

3. A 330 ohms resistor (recommended but not used in this experiment)


The software that are used :

1. Arduino IDE : download here: https://www.arduino.cc/en/Main/Software
2. Processing IDE : download here: https://processing.org/download/



Now that the software and the hardware are obtained, let's go to the set up of the circuit. The circuit has no difference if compared to the Blink! circuit set-up:


The circuit for this experiment


Now that the circuit is set up, lets divide the code into two parts, one the Processing part and the  other is the Arduino part. For the Processing part, the code is stated as below, with the comments:

import processing.serial.*;// so that we can connect to arduino

Serial port;//declaring the serial connection
void setup()
{
  size(200,200);//size of the window created
port = new Serial(this, "COM2", 9600);//declaring our port that arduino uses, if your port is 21                                                                     //than change to COM21
}

void draw()
{
}

void keyPressed()//this part shows the program for the keyboard key to be pressed
{
  if(key == 'q'){        //example when key "q" is pressed
    port.write('q');    //the processing IDE sends data "q" to arduino
  }
   if(key == 'w'){
    port.write('w');
  }
  if(key == 'e'){
    port.write('e');
  }
   if(key == 'r'){
    port.write('r');
  }
}


Now that is done in the Processing IDE, let's shift over to Arduino IDE and write this code:

int val; //declare val variable
int value;  //declare value variable
int led = 9;  //LED is connected to pin 9(PWM)



void setup()
{
  Serial.begin(9600);//serial connection at 9600 bps make sure its the same in ARDUINO
  pinMode(led,OUTPUT);//The LED is declared as output
  
}
void loop()
{
  if (Serial.available()){  //if serial connection available
    val = Serial.read(); //read the serial data and keep in variable val
    if(val == 'q'){  //if serial data is q
      digitalWrite(led, HIGH); //led turn on
    }
    if(val == 'w'){ //if serial data is w
      digitalWrite(led, LOW); //led turn off
    }
    if(val == 'e'){ //if serial data is e
      value = value + 20; //the brightness value is increased by 20
      analogWrite(led,value); //write the brightness value to led
    }
    if(val == 'r'){ // if serial data is r
        value = value - 20; //the brightness value is decreased by 20
      analogWrite(led,value); //write the brightness value to led
    }
  }
}

First upload the arduino code and then run the processing code. Here is the video of the experiment that is made:






Comments

Popular posts from this blog

Arduino and Multi Function Shield: Pots,LEDs and buzzers

HELLO THERE!!!!!    How are you guys? I hope everyone is fine and in good mood always. This week, I continue my tinkerings with the Multi Function Shield. In this experiment, I used the potentiometer in the shield to control the LEDs in the shield. Without further wasting time, let's jump in straight to the experiment!! HARDWARE 1.ARDUINO UNO  2.MULTI-FUNCTION SHIELD SOFTWARE: 1. ARDUINO IDE CIRCUIT ASSEMBLY    The circuit assembly is fairly simple. Just attach the multi function shield on top of Arduino properly. Please attach the shield properly as failure to do so would cause the shield  not to function as intended. CODING THE ARDUINO: Let's refer to the multi-function shield image below: Referring to the image of the shield, it can be seen that the potentiometer (blue object near buttons) is connected to pin A0 (analog 0)     int pot = A0; //declaring the pot ...

Arduino Beginner Experiments: Arduino and Light Blocking Sensor

HELLO THERE!!!     How are you guys? I hope everyone is fine and in a good mood always. This week, I would like to share with you guys my experiment on Arduino and Light Blocking Sensor. The objective of this experiment is to receive feedback from the sensor ( Digital and Analog) What is Light Blocking Sensor?      A linear hall sensor is a type of sensor which responds when the sensor is blocked out from light. The sensor is different for LDR's as LDR's responds to the amount of light it received while the light blocking sensor responds if the light is blocked out or not from the sensor.It can be used for both digital and analog measurements. HARDWARE: 1.Arduino UNO 2. Light Blocking Sensor SOFTWARE: 1.Arduino IDE CIRCUIT ASSEMBLY   Let's refer to the image of the blocking sensor below: The Connection of the Sensor to the Arduino is shown below: SENSOR  ----->       ARDUINO Signal   ...

Arduino Tinkering : Controlling multiple LED with multiple potentiometers

HELLO THERE!!!!            How are you guys? I hope everyone is fine and well always. For this week's post, I would like to share with you guys a simple tinkering on Arduino, LED, and potentiometers. The objective of the experiment is to light up different amount of LED's with different intensity by controlling two potentiometers. Before starting, of course, we need to know what items are needed. The items needed are: 1. Arduino UNO   2. 4 to 5 LEDs 3. 2 Potentiometers The software used in this experiment is: 1. Arduino IDE. Now that all the hardware and software are obtained, let's go to the schematics of the circuit. The circuit is quite simple actually. The long legs of the LED's were connected to PWM pins while the shorter legs were connected to ground. The potentiometers however have three legs. The middle leg is connected to the analog pins (A0, A1) while the other two legs were connected to 5V and GND respect...