Arduino Serial print is an inbuilt function. which allows the computer to communicate with the Arduino board. Having following syntex
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.
Make sure your Arduino board is connected to your computer.
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
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.
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:-
Output : 456
Output : 9.36
Output : G
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.
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.
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.
Serial.begin(9600); //open serial port at 9600 baud rate
pinMode(A0, INPUT); //use A0 pin as input
int temperature = Serial.readln(A0);//read tem and assign value to temperature variable
Serial.print(temperature);//print on serial monitor
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.