Yash Sanghvi has Published 192 Articles

Basic analogRead in Arduino

Yash Sanghvi

Yash Sanghvi

Updated on 23-Mar-2021 11:46:52

406 Views

Converting analog values to digital is a common requirement from microcontrollers in general, and Arduino is no different. Arduino IDE has a built-in analogRead function to facilitate the conversion of analog values to digital.From the programming perspective, the only thing you require to know is the pins of your microcontroller ... Read More

Access pins in Arduino

Yash Sanghvi

Yash Sanghvi

Updated on 23-Mar-2021 11:46:32

1K+ Views

In order to access any pin of your board in Arduino, you can simply reference the number of the pin as an integer. On the Arduino boards like Uno, the label is provided for all the I/O pins, and the same label can be used in the code.Thus, both the ... Read More

Using a third-party library in Arduino

Yash Sanghvi

Yash Sanghvi

Updated on 23-Mar-2021 11:42:27

2K+ Views

The general way of using third-party libraries in Arduino is to install them from Tools -> Manage Libraries. We already have a separate post to cover that. However, what if a library you are using for cannot be found in Tools -> Manage Libraries? After all, Manage Libraries only includes ... Read More

First Hello World project in Arduino

Yash Sanghvi

Yash Sanghvi

Updated on 23-Mar-2021 11:41:13

10K+ Views

In every language, generally, the first Hello World project is a simple program that prints "Hello World"! We will see what such a code would look like for Arduino. The below code will print "Hello World" on the screen every time your board is powered ON.Examplevoid setup() {    Serial.begin(9600); ... Read More

For and While loops in Arduino

Yash Sanghvi

Yash Sanghvi

Updated on 23-Mar-2021 11:33:58

8K+ Views

The for and while loops in Arduino follow the C language syntax.The syntax for the for loop is −Syntaxfor(iterator initialization; stop condition; increment instruction){    //Do something }Examplefor(int i = 0; i< 50; i++){    //Do something }Similarly, the syntax for the while loop is −Syntaxwhile(condition){    //Do something }Exampleint ... Read More

Traditional C formatting in Arduino print

Yash Sanghvi

Yash Sanghvi

Updated on 23-Mar-2021 11:31:00

543 Views

If you are familiar with the C language and would like to use the formatting options provided by C language in the Arduino print statements, then there's an easy way to do it. All you need to do is define a character array, and populate it using sprintf(). Within sprintf, ... Read More

Stop Autoscroll in Serial Terminal in Arduino

Yash Sanghvi

Yash Sanghvi

Updated on 23-Mar-2021 11:30:33

2K+ Views

Suppose you have a code like the one below −Examplevoid setup() {    Serial.begin(9600); } void loop() {    // put your main code here, to run repeatedly:    Serial.println(analogRead(A0)); }As you can see, it is continuously printing the results of ADC conversion on A0 pin. Such programs can fill ... Read More

Print new line and tab in Arduino

Yash Sanghvi

Yash Sanghvi

Updated on 23-Mar-2021 11:29:44

7K+ Views

In order to print a newline, you can either introduce the '' character in your text, or use Serial.println() instead of Serial.print()An example code is given below −Examplevoid setup() {    // put your setup code here, to run once:    Serial.begin(9600);    Serial.println();    Serial.print("This is line1This is line2"); ... Read More

Reduce decimals while printing in Arduino

Yash Sanghvi

Yash Sanghvi

Updated on 23-Mar-2021 11:26:19

1K+ Views

Often some functions can output really long floating-point numbers, with several decimal digits. Several times, we are just interested in the first couple of decimal digits, and the remaining digits just reduce the readability and make the Serial Monitor window cluttered.In order to round of floating-point numbers when printing to ... Read More

Print binary values in Arduino

Yash Sanghvi

Yash Sanghvi

Updated on 23-Mar-2021 11:25:48

12K+ Views

In order to print binary representation of numbers/ characters in Arduino, you can add 'BIN' as the second argument of your Serial.print() function. Example is shown below −Examplevoid setup() {    // put your setup code here, to run once:    Serial.begin(9600);    Serial.println();    Serial.println(75);    Serial.println(75, BIN);   ... Read More

Advertisements