Interfacing IR Sensor with Nuvoton Board

08.02.23 05:38 AM By AKB

In this tutorial you will learn how to use an Infra-Red Sensor in combination with Nuvoton Board. At the end of this tutorial, you will be able to build any project with a Nuvoton board and various types of Sensor to read and encode them.

In this project we will be using IR sensors and Nuvoton MS51FB9AE Development Board.

Before continuing to build the project let’s know about what IR is and where it can be used.

What is Infrared Radiation (IR)?

Infrared radiation (IR) or infrared light is an electromagnetic radiation (EMR) used to carry radiant energy like all EMR. Although Infrared light behaves both like a wave and like its quantum particle, the photon.
Infrared light is not visible for humans because of longer wavelength as the human eye is capable to see:

  • Wavelength infrared: 700nm to 1000nm

  • Human visible wavelength: 400nm to 700nm

What is an IR Sensor?

An IR sensor is a device that can measure the infrared radiation in its surroundings and gives an electric signal as an output. An IR sensor can also be used for the detection of motion of the objects which are in the line of sight with the sensor.

As the infrared radiation is invisible to human eyes, it can be detected by the infrared sensor. An IR sensor is a photodiode that is sensitive to the IR light. When IR light falls on the photodiode, the resistances and the output voltages will change in proportion to the magnitude of the IR light received.

IR Sensor

Features:

  • The operating voltage is 5VDC

  • I/O pins – 3.3V & 5V

  •  Mounting hole

  • The range is up to 20 centimeters

  • The supply current is 20mA

  • The range of sensing is adjustable

  • Fixed ambient light sensor

NUVOTON MS51FB9AE Development Board

Please add the image here

About Nuvoton MS51FB9AE Development Board:

Nuvoton MS51FB9AE is  an embedded flash type, 8-bit high performance 8051-based microcontroller based on 1T 8051-based CMOS, runs up to 24 MHz, features 16 K bytes flash, 1 K bytes SRAM, and 4 K bytes loader ROM for the ISP, also equipped with rich peripherals: 2 sets of UART; 1 set of I²C, and 1 set of SPI, 18 GPIO, 8 channels of 12-bit ADC, Watchdog Timer, Window Watchdog Timer and 6*a 16-bit PWM channel package is available in TSSOP20.

Check out another powerful Microcontroller from Nuvoton here.Features of Nuvoton

Features of Nuvoton:
•Operating Characteristics
-Voltage range: 2.4V to 5.5V
-Temperature range: - 40 ℃ to + 105 ℃
-EFT 4 kV
•Core
-1T 8051-based CMOS microcontroller running up to 24 MHz
•Memories
-16 K bytes Flash
-Configurable 4 K / 3 K / 2 K / 1 K Bytes of LDROM, which provides flexibility to user developed Boot Code
-1 K bytes SRAM
-256 Bytes on-chip RAM
-Flash Memory accumulated with pages of 128 Bytes each
-Built-in In-Application-Programmable ( IAP )
•Clocks
-External clock input ( 32 K body only )
-16 MHz high-speed internal oscillator trimmed to ± 1 % when VDD 5.0 V, ± 2 % in all conditions.
-24 MHz high-speed internal oscillator trimmed to ± 1 % when VDD 5.0 V, ± 2 % in all conditions
-10 kHz low-speed internal oscillator
-On-the-fly clock source switch via software
•Power management
-Brown-out detection ( BOD ) with low power mode available, 4-level selection, interrupt or reset options
-Power-on reset ( POR )
•96-bit Unique ID ( UID )
•128-bit Unique Customer ID ( UCID )
•2-Byte ( 16-bit ) PDID

Let’s begin to interface IR sensors with Nuvoton.

Hardware Requirements:

For this project, we will use the below components-

Software requirement:

To write a code for Nuvoton MS51FB9AE module we would require Keil software.

Connections:

For LCD related connection:

RS - P04

EN - P03

D4 - P01

D3 - P00

D2 - P10

D1 - P11


                                                                                         MS51FB9AE


Connect the Nu-Link programmer to the board through USB from your PC to upload code.. The Input from IR Sensor is sensed by the analog input 0 (AN0), Pin P1.7 which is Analog input channel 0 is used to interface IR sensor.

Code:

As we are using Keil for this project you would be requiring a powerful LCD and MS51FB9AE library for proper debugging the Output from our IR sensor, Download 16x2 LCD Library for Nuvoton MS51FB9AE from here and download MS51 library here.

After downloading just add lcd.c and lcd.h and ms51.h files in your main KeilMS51FB9AE project.

#include "ms51.h"

#include "SFR_Macro.h"

#include "Function_define.h"

#include "Common.h"

#include "Delay.h"

#include "lcd.h"

#define bit_to_voltage_ratio 0.001220703125 // 5.0V divided by 4096 For 12-Bit ADC

void setup (void);

unsignedintADC_read(void);

float voltage;

charstr_voltage[20];

void main(void){

intadc_data;

setup(); 

lcd_com (0x01);

while(1){

lcd_com (0x01);

lcd_com (0x80);

lcd_puts("ADC Data: ");

adc_data = ADC_read();

lcd_print_number(adc_data);

voltage = adc_data * bit_to_voltage_ratio;

sprintf(str_voltage, "Volt: %0.2fV", voltage);

lcd_com(0xC0);

lcd_puts(str_voltage); 

 Timer0_Delay1ms(500);

 }

 }

void setup (void){

Set_All_GPIO_Quasi_Mode;

lcd_init();

 Enable_ADC_AIN0;

lcd_com (0x80);

LCD_ScrollMessage("Welcome to CampusComponent");

lcd_com (0x80);

lcd_puts("IR sensor Interfacing");

lcd_com (0xC0);

lcd_puts ("With MS51FB9AEmcu");

 Timer3_Delay100ms(5);

}

unsignedintADC_read(void){

register unsigned intadc_value = 0x0000;

clr_ADCF;

set_ADCS; 

while(ADCF == 0);

adc_value = ADCRH;

adc_value<<= 4;

adc_value |= ADCRL;

returnadc_value;

}

Output:

After successfully uploading of the code, 

Start the Input supply and place any object within the range i.e. 20cm infront of the IR Sensor, the voltage given to the ADC pin will show some change and we can notice the ADC value and Analog voltage displayed on the LCD.

When there is no object present in the line of sight of IR Sensor the LCD will show the ADC value of 4096, and when the object is present this value will start to drop, as you move the object close to the IR Sensor you can see a major drop in the ADC data value. From this we can detect any object and also how far the object is present from the Device.

 By further calibration you can achieve more accurate values and you work with it as per your requirements.

Conclusion:

Using above process you can make Nuvoton and IRmodule work as per your application. There are many high end industrial projects you can build and explore using Nuvoton. There are different modules from Nuvoton which comes with more addon functionality and hardware peripherals which are available at Campus Component.

The Nuvoton module can be used in varied applications such as Thermostat, Bluetooth Speaker, Infrared Sensing, Battery charger, Small IoT appliances. In terms industrial projects we can use Nuvoton Module to build Rail safety devices, Infrared Astronomy, optical power meters and Large scale IoT project.

If you are looking for electronic components and different microcontrollers from Nuvoton, reach out Campus Component today!

Added to cart
- There was an error adding to cart. Please try again.
Quantity updated
- An error occurred. Please try again later.
Deleted from cart
- Can't delete this product from the cart at the moment. Please try again later.