Skip to content Skip to sidebar Skip to footer

Widget HTML #1

How to Compare Hexadecimal on Arduino

How to Compare Hexadecimal Values on Arduino

How to Compare Hexadecimal Values on Arduino - In some applications, we will encounter the use of certain number values. These numbers are decimal, comma, binary, hexadecimal, and octal.

In this article we will learn how to compare Hexadecimal numbers using C language on Arduino.

Hexadecimal numbers are numbers that use the 16 system. If the Decimal numbers, we only use the 9 system. Starting from the numbers 0 to 9.

In hexadecimal numbers the numerical values are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F.

One of the uses of Hexadecimal numbers is on the InfraRed Remote. Why convert infrared signal using Hexadecimal?

A. Introduction

Two terms that are often used in infrared signals are decoding and encoding. Encoding is a term for encoding data into infrared signals. Encoding term is often associated with the remote sender (transceiver).

While coding is encoding infrared signals into data. The term coding is often associated with a remote receiver (receiver).

Let's take the example of the NEC Ir Remote protocol. Data is encoded using pulse distance coding or digital signals (0 and 1). The frequency speed of this signal is about 38kHz. The data sent is 32-bit (4 bytes). 16-bit for address data and 16-bit for command data.

Cara Membandingkan Nilai Hexadesimal Pada Arduino, how to compare hex value arduino
Contoh protokol NEC

If the above data is sent all at once, then the data is 00000000111111111011010101001010. If this data is processed, of course it will take a long time and there may be data left behind.

Therefore, the binary data is converted into Hexadecimal to facilitate data processing. Data 00000000111111111011010101001010 = 0xFFB54A.

B. Compare Arduino Hex Numbers


Now we will make a comparison of Hex numbers for decision making. For example, let's say we receive remote data and we want to compare it with the Hex data that has been set to turn on the LED.

If the data compared is correct, the LED will light up. If it is wrong then the LED will turn off. The basic comparison code is:
if (data masuk == 0x......)
  {
    //maka lakukan sesuatu
  }
  else
  {
    //maka lakukan sesuatu
  }

In writing Hex values, we must put "0x" before the actual value. This indicates that the value is a hexadecimal value.

For an example of a project turning on lights with a remote, please read the article TSOP1738 Arduino How to Receive IR Remote Data on this website.

Thank you for visiting Chip Piko website. May be useful. 

Post a Comment for "How to Compare Hexadecimal on Arduino"