Arduino Serial Print- To Display Output of Sensors

Spread the love

About Arduino Serial Print

Arduino Serial print is an inbuilt function. which allows the computer to communicate with the Arduino board having the following syntax

Serial.println("value");

It uses SPI (Serial Peripheral Interface) protocol to exchange the data between the computer and Arduino. Also, it converts the raw data in ASCII (American Standard Code of Information Interchange). So humans can easily read it.

Understand this with a real-life situation. Suppose, you have a temperature sensor and you want to know the temperature of your surroundings. Then, a serial print Arduino function comes into the picture. It allows users to read the real-time temperature value and convert it into a human-readable format and display.

Material required

How to open Arduino Serial Monitor

Make sure your Arduino board is connected to your computer.

arduino serial print open serial monitor
Open serial monitor

The easiest way to open Arduino Serial monitor is to click on the magnifier icon. The second method is press Ctrl+Shift+M. The third way is to go to Tools>Serial Monitor

Baud Rate

First of all, you have to define the baud rate on which you want to communicate. Baud rates supported by Arduino range from 300 to 2000000, depending on the application.

arduino serial print
Baud

Always select same baud rate you define in code

Arduino serial commands and syntax

Arduino Serial Begin

Serial begin is the initiation to set the baud rate in which you want to communicate.

Serial.begin(9600); //Syntex to set baud

Arduino commands to print on Serial Monitor

You can print anything using the following functions-

Serial Print (456); Output : 456

Serial.print(9.365478);

Output : 9.36
Serial.print('G')

Output : G
Serial.print("Electronic smith")

Output : Electronic smith

Arduino serial Print New Line

Using this function you can print a new value in a new line that will make your output more sensible and easy to read.

Serial.println(temperature);

Arduino Serial Read

Arduino Serial read command is used to read the data coming from any other device. Here, I’m using a python script to communicate with Arduino I use the serial read command to read data coming from the computer.

Serial.read();

All serial commands

Serial.end(); //close the serial communication
Serial.available(); //use to check serial port is empty or not
Serial.flush(); //use to delete all serial values
Serial.write(); //send data through serial.

Here is an example code to read the temperature and print it on the serial monitor.

void setup()
{
Serial.begin(9600); //open serial port at 9600 baud rate
pinMode(A0, INPUT); //use A0 pin as input
}
void loop()
{
int temperature = Serial.readln(A0);//read tem and assign value to temperature variable 
Serial.print(temperature);//print on serial monitor
}

FAQ

Serial print not working ?

Choose correct port, Board and then try again. Also make sure Arduino is connected to your computer.

Serial write vs print

Serial write is use to send data and Serial print is use to print on serial monitor.

Add a Comment

Your email address will not be published. Required fields are marked *