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
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
Post a Comment