Modulo Remainder in Arduino

Yash Sanghvi
Updated on 31-May-2021 14:16:04

8K+ Views

The modulo operator in Arduino is exactly the same as in C language, or most other languages for that matter. The operator is %. The syntax is: a % b and it returns the remainder when a is divided by b.ExampleThe following example illustrates the use of this operator −void setup() {    // put your setup code here, to run once:    Serial.begin(9600);    Serial.println();    Serial.println(10%3);    Serial.println(4%2);    Serial.println(50%9); } void loop() {    // put your main code here, to run repeatedly: }OutputThe Serial Monitor output is shown below. You can work out the remainders yourself and verify that the output is correct.

Check if a Character is Space or Whitespace in Arduino

Yash Sanghvi
Updated on 31-May-2021 14:15:32

779 Views

The isSpace() and isWhitespace() functions can be used to check if a character is a space or, more specifically, a whitespace. Whitespace is a subset of space. While whitespace includes only space and horizontal tab (‘\t’), space includes form feed (‘\f’), new line (‘’), carriage return (‘\r’) and even vertical tab (‘\v’).ExampleThe following example demonstrates the usage of these functions −void setup() {    // put your setup code here, to run once:    Serial.begin(9600);    Serial.println();    char c1 = 'a';    char c2 = ' ';    char c3 = '\t';    char c4 = '';   ... Read More

Check If a Character is a Punctuation Mark in Arduino

Yash Sanghvi
Updated on 31-May-2021 14:12:55

288 Views

Just like there is a function to check if a character is alphanumeric or not, there is another one to check if a character is a punctuation mark or not. The name of the function is isPunct(). It takes a character as an input and returns a Boolean: true if the given character is a punctuation mark.ExampleThe following example demonstrates the use of this function −void setup() {    // put your setup code here, to run once:    Serial.begin(9600);    Serial.println();    char c1 = 'a';    char c2 = ', ';    char c3 = '1';    char c4 ... Read More

Check If a Character is Alphanumeric in Arduino

Yash Sanghvi
Updated on 31-May-2021 14:12:30

825 Views

Depending on your use case, you may need to check if a character is alphanumeric or not in Arduino. One example can be validating password strings, wherein you’ve allowed only alphanumeric characters for passwords. Or checking file names for storage in SD Card (sometimes some special characters are not allowed in file names). Arduino has an inbuilt function which checks whether a given character is alphanumeric or not. As you would have guessed, the function is isAlphaNumeric() and it takes in a character as the argument, and returns a Boolean.Examplevoid setup() {    // put your setup code here, to ... Read More

Bitwise XOR in Arduino

Yash Sanghvi
Updated on 31-May-2021 14:12:06

2K+ Views

Just like other bitwise operators, bitwise XOR also applies on the corresponding bits individually.The operator is ^ and the syntax is, a ^ bwhere a and b are the two numbers to be XORed.The truth table for XOR is given below −PQP^Q000011101110As you can see, the XOR operator returns 1 only when the two bits are different.If you perform 10 ^ 3, this is the computation that will happen at the bit level (assuming your board represents integers using 16 bits)00000000000010101000000000000000113000000000000100110 ^ 3 = 9ExampleLet’s verify this on the Serial Monitor. The code is given below −void setup() {   ... Read More

Logical NOT in Arduino

Yash Sanghvi
Updated on 31-May-2021 14:11:41

3K+ Views

Logical NOT is performed using the ! operator. The truth table is given below −ExpressionOutputTFFTAs you can see, the logical NOT inverts the truth value of the expression.ExampleThe usage can be understood from the example given below −void setup() {    // put your setup code here, to run once:    Serial.begin(9600);    Serial.println();    int i = 10;    if (!(i > 10)) {       Serial.println("i is NOT greater than 10");    }    else {       Serial.println("i is greater than 10");    } } void loop() {    // put your ... Read More

Bitwise NOT in Arduino

Yash Sanghvi
Updated on 31-May-2021 14:11:19

1K+ Views

Unlike logical NOT, which inverts the truth value of an expression, the bitwise NOT applies to each bit of a number and inverts its value (0 to 1 and 1 to 0). The operator is ~.The syntax thus is ~a, where a is the number on which this operator has to apply.Please note, that all the leading 0s in the number’s representation are also converted to 1. For example, if your board uses 16 bits to represent an integer, then here’s what ~10 will look like0000000000001010101111111111110101~10=-11As you can see, each bit of 10 got inverted. This number corresponds to, using ... Read More

Logical AND and OR in Arduino

Yash Sanghvi
Updated on 31-May-2021 14:10:39

14K+ Views

The logical AND is denoted by the && operator, while the logical OR is denoted by the || operator.SyntaxExpression1 && Expression2ORExpression1 || Expression2Where expression1 and expression2 evaluate to Boolean values (true or false). The output of these statements is determined by the truth tables of logical AND and OR.The truth table for AND is given below −Expression1Expression2OutputTTTFTFTFFFFFAs you can see, both the expressions have to be true for the AND statement to output true.The truth table for OR is given below −Expression1Expression2OutputTTTFTTTFTFFFAs you can see, even if one of the expressions is true, the OR statement will output true.ExampleThe following ... Read More

Electrical Units and Metric Prefixes

Manish Kumar Saini
Updated on 29-May-2021 15:37:05

2K+ Views

A unit of measurement can be defined as a quantity chosen as a standard in terms of which other quantities may be expressed.Engineering is an applied science dealing with a variety of physical quantities (a physical quantity is one which can be measured) like time, speed, voltage, resistance etc. Hence, for the measurement of these quantities standard units are defined.There are a number of electrical units defined which are based on the SI system of units.Standard Electrical Units of MeasurementElectrical QuantitySymbol for QuantityMeasuring UnitSymbol for UnitChargeQ or qCoulombCVoltageV or vVoltVEMFE or eVoltVCurrentI or iAmpereAResistanceR or rOhmΩInductanceLHenryHCapacitanceCFaradFConductanceGMho or Siemen℧ or Ω-1or ... Read More

Band-Pass Filter Frequency Response

Manish Kumar Saini
Updated on 29-May-2021 15:36:29

5K+ Views

A band pass filter (BPF) is a circuit that passes frequencies within a certain range and rejects all the frequencies outside the range. This range of band pass filter is known as Bandwidth of the filter.The Bandwidth of band pass filter is given by, $$Bandwidth=f_{high}-f_{low}$$Where, fhigh and flow are the higher and lower cut off frequencies.The values of fhigh and flow are given by, $$f_{high}=\frac{1}{2\pi\:R_{2}C_{2}}$$$$f_{low}=\frac{1}{2\pi\:R_{1}C_{1}}$$In the frequency response curve or bode plot of the band pass filter, the signal is blocked(attenuated) at low frequencies with the output increasing at the rate of +20dB/Decadeuntil the frequency reaches the Lower Cut off ... Read More

Advertisements