RTOS stands for Real Time Operating System. It is used to run multiple tasks concurrently, schedule them as required, and enable them to share resources. Now, while getting into the details of RTOS is out of the scope of this article, we will walk through an example that will give you a fair idea of RTOS. For now, you can just note that RTOS will help you perform multi-tasking within your Arduino, just like how the OS on your machine helps you run multiple tasks (like writing mails, listening to music, etc.) simultaneously.Now, since we are concerned with microcontrollers, we ... Read More
As discussed in another article, Timers are basically counters. When they reach the end of the count, they overflow. We can use this event to generate an interrupt. Now, the traditional way of generating the interrupts in Arduino involve changing a lot of registers. Luckily, we have libraries for making our lives easy.We will use the TimerOne library for generating interrupts on Timer1. Similarly, there is the TimerThree library for generating interrupts on Timer3 (not applicable for Arduino Uno).Go to Tools -> Manage Libraries and search for TimerOne and TimerThree (optional) and click Install.Next, import the library in your code ... Read More
As discussed earlier, Arduino Uno has 3 timers: Timer0, Timer1 and Timer2. Timer0 and Timer2 are 8-bit counters (they count from 0 to 255), while Timer1 is a 16-bit counter (it counts from 0 to 65535). Internally, Timer0 is used for the millis() function, and therefore, it is recommended not to mess with it. You can use Timer1 and Timer2 for your custom requirements.Note that the clock frequency of Arduino Uno is 16 MHz. Therefore, no timer can have intervals shorter than (1/16000000). However, for most applications, you would want longer intervals (lower frequencies). In other words, you would want ... Read More
Every microcontroller has one or more timers that help the users perform tasks at precise intervals. Arduino Uno, for example, has 3 timers: Timer0, Timer1 and Timer2. Other boards may have the same or different number of timers, which you can find from the datasheet of that board/ microcontroller. What are timers?Timers are essentially counters. Let me give you a simple example. Say you want to trigger a task every 5 seconds. Now, if you have a counter which can count from 0 to 255, then if you somehow adjust the rate of counting such that it finishes counting exactly in ... Read More
What is PWM?PWM refers to Pulse Width Modulation. In very simple terms, we can output a square wave from certain pins of the Arduino board, and we can control the fraction of time for which the wave will be at the HIGH state (known as the duty cycle).Why is PWM needed?PWM finds several applications. An important application is running motors. The RPM of the motor can be controlled by the PWM output. PWM can also be used in general for generating voltages between HIGH and LOW. So, if your HIGH level is at 5V and LOW level is at 0V, ... Read More
FloatFloating point numbers are stored using 4 bytes (32 bits).Their max value can be 3.4028235E+38 and their min value can be -3.4028235E+38.They have a precision of about 6-7 decimal places.DoubleWhile on several platforms, double has more precision than float. However, on most Arduino boards (Uno and many other ATmega boards), double has the same size as float. Arduino Due is an exception, wherein double has a size of 8 bytes (compared to 4 bytes of float).On the boards where double is stored using 8 bytes, the max value can be 1.7*10^308 and the min value can be -1.7*10^308. On the ... Read More
When you define an integer, it is signed by default. In other words, it can accept both positive and negative values. Unsigned integers, as the name suggests, accept only positive values. Therefore, they have a higher range.If you are using a board that uses two bytes (16 bits) to represent an integer, then the maximum range you would get for an unsigned integer is 0 to 65535 (216-1).However, when representing signed integers, the range would be -32767 to +32767. Note that 32767 corresponds to (215 -1). As you can see, the most significant bit seems to be out of action. ... Read More
Defining new functions in Arduino is equivalent to defining the functions in C.The syntax is −Syntaxreturn_type function_name(arg_type arg)The only difference is that in C, the function needs to be declared at the top, if it is invoked before its definition. No such constraint exists in Arduino. The following code demonstrates this −Examplevoid setup() { Serial.begin(9600); Serial.println(); } void loop() { // put your main code here, to run repeatedly: for (int i = 0; i < 10; i++) { long int w = square(i); Serial.println(w); delay(1000); ... Read More
In order to convert a string to lower/upper case, the in-built .toLowerCase() and .toUpperCase() functions can be used.Note: These functions change the original string itself, and don't return a new string with the changes.The implementation is shown below −Examplevoid setup() { Serial.begin(9600); Serial.println(); String s1 = "Hello World"; Serial.println(s1); s1.toLowerCase(); Serial.println(s1); s1.toUpperCase(); Serial.println(s1); } void loop() { // put your main code here, to run repeatedly: }The corresponding Serial Monitor output is −OutputAs you can see, the changes have been made in s1 itself. The return of .toUpperCase() and .toLowerCase() is void.Read More
The .replace() function in Arduino allows you to replace a character or a substring with another character/substring in Arduino.Note: This function replaces substrings in the original string itself, and does not return a new string containing the changes.Examples are given in the code below −Examplevoid setup() { Serial.begin(9600); Serial.println(); String s1 = "Hello World"; Serial.println(s1); s1.replace('e', 'a'); Serial.println(s1); s1 = "Hello World"; s1.replace("ll", "gg"); Serial.println(s1); s1 = "Hello World"; s1.replace("li", "gg"); Serial.println(s1); } void loop() { // put your main code here, to run ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP