Lesson 4/31: What are Binary, Decimal, Hexadecimal and Octal Number, Arduino Serial Monitor
In this lesson, we will explore the fundamental concepts of number systems, including binary, decimal, hexadecimal, and octal representations. Understanding these systems is crucial for working with Arduino, especially when it comes to data representation and manipulation. By the end of this tutorial, you will be able to differentiate between these number systems and utilize them effectively in your projects.
We will also introduce the Arduino Serial Monitor, a powerful tool that allows you to communicate with your Arduino board through your computer. This functionality is essential for debugging and monitoring data exchanges. To see practical examples and a thorough explanation, make sure to check the video at (in video at 12:30).
Code Examples & Walkthrough
In the following code snippets, we will explore how to use the Serial Monitor effectively. The first example initializes serial communication and prints a welcome message.
void setup() {
Serial.begin(9600);
Serial.println("Robojax");
Serial.println("Welcome");
Serial.print("To Arduino Class\n");
}
Here, the setup() function is called once at the start of the program. It initializes the serial communication at a baud rate of 9600 and prints a welcome message to the Serial Monitor.
Next, we will look at how to read user input from the Serial Monitor.
void loop() {
if(Serial.available() > 0) {
Serial.println(Serial.read());
}
}
This code checks if there is any data available in the serial buffer. If there is, it reads the input and prints it back to the Serial Monitor. This is a fundamental way to interact with user input.
Lastly, let's see how to print characters based on user input.
void loop() {
if(Serial.available() > 0) {
Serial.print(Serial.read());
Serial.print("\t");
Serial.println((char) Serial.read());
}
}
This example demonstrates how to read a character from the Serial Monitor and print it along with its corresponding ASCII value. The (char) cast is used to convert the numerical value to its character representation.
For the full code and more examples, please refer to the complete code that loads below the article.
Demonstration / What to Expect
Once you upload the code to your Arduino, you should see the welcome messages displayed in the Serial Monitor. You can then enter characters, and the Arduino will respond with the corresponding ASCII values. Be cautious of the baud rate; if it does not match the one set in the code, the output may appear garbled (in video at 18:45).
Video Timestamps
- 00:00 Introduction
- 0:55 Base Numbers
- 03:13 Decimal numbers
- 4:59 Binary numbers
- 3:61 Octal numbers
- 8:00 Hexadecimal numbers
- 11:34 Serial Monitor
- 22:54 Reading user keyboard inputs
- 25:56 Printing actual numbers On Serial Monitor
- 26:42 Serial monitor example codes
/*
* درس ۰۴- نمایشگر مسلسل و نوع داده
* کیت آردوینو ۳ در ۱ ماشین هوشمند سانفاندر
* 📚⬇️ صفحه دانلود و منابع https://robojax.com/RJT587
* نوشته Ahmad Shamshiri
* برای مشاهده توضیحات کامل ویدیو https://youtu.be/rJiSo6sr1hA
* www.robojax.com
*/
void setup() {
Serial.begin(9600);
Serial.println("Robojax");
Serial.println("Welcome");
Serial.print("To Arduino Class\n");
Serail.print("Name: \nTelephone: \nAddress:");
Serail.print("Last Name: \tTele\\Phone: \tAddress:");
}
void loop() {
// متن اصلی خود را اینجا قرار دهید، تا به طور مکرر اجرا شود:
}
/*
* درس ۰۴ - خواندن ورودی کاربر از المان سریال
* پکیج سه در یک ماشین هوشمند آردوینو سان فاندر
* 📚⬇️ صفحه دانلود و منابع https://robojax.com/RJT587
* نوشته احمد شمشیری
* ویدئوی کامل توضیحات را تماشا کنید https://youtu.be/rJiSo6sr1hA
* www.robojax.com
*/
void setup() {
Serial.begin(9600);
}
void loop() {
if(Serial.available() >0 ){
Serial.println(Serial.read());
}
}
/*
* درس 04-خواندن ورودی کاربر از مانیتور سری و چاپ یک خصیصه
* کیفیت 3 در 1 ماشین هوشمند آردوینو سان فاندر
* 📚⬇️ صفحه دانلود و منابع https://robojax.com/RJT587
* نوشته احمد شمشیری
* مشاهده توضیحات کامل ویدئو https://youtu.be/rJiSo6sr1hA
* www.robojax.com
*/
void setup() {
Serial.begin(9600);
}
void loop() {
if(Serial.available() >0 ){
Serial.print(Serial.read());
Serial.print("\t");
Serial.println((char) Serial.read());
}
}
Common Course Links
Common Course Files
منابع و مراجع
هنوز هیچ منبعی موجود نیست.
فایلها📁
هیچ فایلی موجود نیست.