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 following syntex

Serial.println("value");

Ituses SPI(Serial peripheral interface) protocol to exchange data between the computer and Arduino. Also, it converts the row 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. Here serial print Arduino function comes in the role. 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. Third way is 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 from 300 to 2000000 depend 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 and set the baud rate you want to communicate.

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

Arduino commands to print on serial monitor

You can print anything using following function:-

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 new value in new line. Which makes 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 use a python script to communicate with Arduino I use 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 temperature and print it on 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 *