Introduction
In this tutorial, you will learn how to use serial communication by using the serial monitor of Arduino IDE.
Parts Required
Parts | Quantity | Link |
Arduino Uno | 1 | https://amzn.to/2TvSOxY |
A-B Cable | 1 | |
LED | 1 | https://amzn.to/2HDWLxI |
220-ohm Resistor | 1 | |
Connecting Wires | As Per Required | https://amzn.to/2TtqeNx |
Bread-Board | 1 | https://amzn.to/3mxYVON |
Circuit Diagram
Program
For programming this concept we need to understand some basic syntax of Arduino IDE. Before that, the first thing is we need to install Arduino IDE. After that, we need to know how to interface led to Arduino. Then we are move towards Serial Monitor concepts.
To initialize the serial monitor we need to call a function that is predefined in IDE.
Serial.begin(9600);
Here 9600 is the normal Baud rate of Serial Communication.
Like in C programming we also used the function printf() that normally prints the data. Here if we want to print some data then Serial.println() function have to call.
Serial.println("Welcome To Serial Communication");
For control led we need to declare led as output.
pinMode(PIN Number, Device TYPE);
PIN Number– The pin, to which we have connected the device. In this case, I have attached to 13 no pin of Arduino UNO.
Device Type– What is the device type. For output devices, we need to declare the type as OUTPUT and for input devices, we need to declare it as INPUT. In this case, we have connected Led. As we know, led is an output device. so we have to program.
pinMode(13, OUTPUT);
After declare we need to turn on/ off led. so, to do that we need to understand about digitalWrite().
digitalWrite(PIN Number, Status);
PIN Number– in which pin we have connected the device. In this case, I have attached to 13 no pin of Controller
Status– status means we need to turn the led on/off. For turning led on we can write HIGH or 1 and for turning off led we can write LOW or 0.
digitalWrite(LED,HIGH);
digitalWrite(LED,LOW);
Final Code
/*
Tested by robogenesis.in
This program blinks pin 13 of the Arduino (the built-in LED)
*/
// Initially defined LED connected in 13 no pin
#define LED 13
void setup()
{
pinMode(LED,OUTPUT); // LED as output
Serial.begin(9600); // Serial monitor starts
Serial.println("Welcome To Serial Communication"); //Printing purposes
}
void loop()
{
digitalWrite(LED,HIGH); // LED on
Serial.println("LED: ON"); // it will show in serial monitor if LED is on
delay(1000); // Delay
digitalWrite(LED,LOW); // LED on
Serial.println("LED: OFF"); // it will show in serial monitor if LED is off
delay(1000); // Delay
}
Comments