Introduction: Arduino and Infra-Red (IR) Obstacle Detection / Proximity Sensing / Line Counter, With 320x480 LCD Interface

Abstract

The infrared sensor consists of two parts, an infrared transmitter and an infrared receiver. The IR transmitter excite a source of infrared light with a center wavelength range of 830nm-950nm. The power of the infrared light excited is proportional to the current injected.

The infrared receiver is a semiconductor device for translating the infrared light signal into the electrical signal. The IR module can be used for intellectual robot, obstacle avoidance / detection, counter device in the pipeline, black and white lines tracking device, etc.

Nowadays, the beautiful TFT LCD screens are getting cheaper and using it in an embedded design, makes it more user friendly. In this instructable, also explains connecting the 320x480, 3.5Inch TFT LCD, with ILI9488 driver and SPI interfacing into Arduino. The LCD can be connected to the Arduinos SPI bus. It needs minimum number of port pins (4).

The IR sensor (obstacle / object detector) will detect the objects, with in the detection range (5CM to 10CM). IR sensor module provides a digital output signal and an analog output signal, which is connected to the Arduino digital IO pin and an analog IO pin. Software will read the digital IO pin value and displayed on the connected 320x480 TFT LCD display (Obstacle / Free indication / Obstructed count / Approximate distance in %), also prints via the serial port for further analysis. The analog out pin is read, and print on the serial port / TFT LCD, which may provide approximate / rough distance from obstacle to the senor.

Parts and components

Arduino Uno board = 1 No

Infrared Reflective Sensor = 1 No

320x480 TFT LCD (SPI interface, ILI9488 LCD controller) = 1 No

Step 1: Schematic

The TFT LCD (3.5 inch, 320x480 pixel, ILI9488 LCD controller), is used for this instructable.

The LCD is easily interfaced with Arduino SPI bus, and it needs minimum of four Digital IO lines.

The ILI9488 LCD Controller is a 16.7M single-chip SoC driver for a-Si TFT liquid crystal display panels with a resolution of 320(RGB) x 480 dots.

The ILI9488 is comprised of a 960-channel source driver, a 480-channel gate driver, 345,600 bytes GRAM for graphic data of 320 (RGB) x 480 dots, and power supply circuit.

The LCD operates at 3.3 Volt Logic. Arduino SPI port is connected to the LCD ( D13- SCLK, and D11 – MOSI).

Arduino Digital IO pin D9 and D10 is connected to RS and CS pin of LCD.

The reflective infra-red sensor has four pins:- VCC, GND and DOUT and AOUT.

Sensor DOUT pin is connected to D5 digital IO pin of Arduino and AOUT is connected AO analog pin of Arduino.

Sensor effective distance of measurement is 5 centimeter to 10 centimeter.

Can be used for obstacle detection, pipeline counting and proximity detection.

Step 2: Software

Arduino SPI port is connected to the LCD ( D13- SCLK, and D11 – MOSI). Arduino Digital IO pin D9 and D10 is connected to RS and CS pin of LCD.

Software will detect the obstacle and shows on connected TFT LCD display (Obstacle / Free).

Also the “number of times obstructed” (three digit counter) will be displayed.

Once count value reaches to 999, then the software will reset it to zero.

The analog out pin is read, and print on the serial port / TFT LCD, which may provide approximate / rough distance from obstacle to the senor.

When debug flag is enabled at compile time, then the software will sends the debug information to serial port.

//Experiment of 3.5 Inch LCD (320x480), ILI9488 SPI Interface driver
//Demonstrates the use of Infrared obstacle detection. //Adafruit ILI9341 library is modified for ILI9488 (320x480)

// DHT22 Data line connected to Arduino digital IO 2

// LCD MOSI to Arduino digital IO D11 // LCD SCLK to Arduino digital IO D13 // LCD CS to Arduino digital IO D10 // LCD RS / DS to Arduino digital IO D9

// IR Module digital output to Arduino digital pin 5 // IR Module analog output to Arduino analog pin 0

// Name:- M.Pugazhendi // Date:- 06thSep2016 // Version:- V0.1 // e-mail:- muthuswamy.pugazhendi@gmail.com

//Include Libraries #include "SPI.h" #include "Adafruit_GFX.h" #include "Adafruit_ILI9341.h"

//Constants #define SERIAL_DEBUG

//Variables unsigned int count = 0x00; unsigned int count_one = 0x00; unsigned int previous = 0x00;

int detect_obstacle=5; int ain_obstacle=A0; int adc_value;

// For the LCD shield, these are the default. #define TFT_DC 9 #define TFT_CS 10

// Initialize LCD // Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

// If using the breakout, change pins as desired //Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);

int converted = 0; int converted_previous = 0;

//Arduino setup void setup() { #ifdef SERIAL_DEBUG Serial.begin(9600); Serial.println("Infra Red Obstruction Counter"); #endif

//Initialize IR pinMode(detect_obstacle,INPUT); //Initialize TFT LCD tft.begin();

#ifdef SERIAL_DEBUG // read diagnostics (optional but can help debug problems) uint8_t x = tft.readcommand8(ILI9341_RDMODE); Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX); x = tft.readcommand8(ILI9341_RDMADCTL); Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX); x = tft.readcommand8(ILI9341_RDPIXFMT); Serial.print("Pixel Format: 0x"); Serial.println(x, HEX); x = tft.readcommand8(ILI9341_RDIMGFMT); Serial.print("Image Format: 0x"); Serial.println(x, HEX); x = tft.readcommand8(ILI9341_RDSELFDIAG); Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX); #endif

//Rotate the screen to right direction tft.setRotation(1);

//Print the headers printHeader(); }

//Main loop void loop(void) { adc_value=analogRead(ain_obstacle); converted = map(adc_value, 0, 1024, 0, 100); //Distance header print //tft.setCursor(25,230); //tft.print("Distance %"); if(converted != converted_previous) { //Print ADC Value tft.setTextSize(4); tft.setTextColor(ILI9341_WHITE); tft.fillRect(50,260,120,38,ILI9341_BLUE); tft.setCursor(50,260); tft.print(converted); tft.print("%"); tft.drawRect(240+20,255,206,40,ILI9341_WHITE); tft.fillRect(240+23,258,200,34,ILI9341_BLUE); if(converted > 50) { tft.fillRect(240+23,258,(converted*2),34,ILI9341_GREEN); } else { tft.fillRect(240+23,258,(converted*2),34,ILI9341_RED); } converted_previous = converted; } //printIRDetection(); if(digitalRead(detect_obstacle)==LOW) { #ifdef SERIAL_DEBUG Serial.println("Obstruct"); Serial.print("ADC value ="); Serial.println(adc_value); #endif if(previous == count) { count++; //Reset the counter if(count >= 1000) { count = 0; } //Obstruction tft.setTextSize(4); tft.setTextColor(ILI9341_WHITE); tft.fillRoundRect(0,110,235,100,10,ILI9341_RED); tft.setCursor(20,150); tft.print("OBSTACLE"); } } else { adc_value=analogRead(ain_obstacle); #ifdef SERIAL_DEBUG Serial.println("Free"); //print the counted value Serial.print("Count ="); Serial.println(count); Serial.print("ADC value ="); Serial.println(adc_value); #endif if(previous != count) { //Free tft.setTextSize(4); tft.setTextColor(ILI9341_BLUE); tft.fillRoundRect(0,110,235,100,10,ILI9341_GREEN); tft.setCursor(70,150); tft.print("FREE"); previous = count;

tft.setTextSize(4); tft.setTextColor(ILI9341_WHITE); //Counter tft.fillRect(350,170,120,38,ILI9341_BLUE); tft.setCursor(350,170); tft.print(count); } } //Delay 2 Seconds delay(500);

}

//Print headers unsigned long printHeader() { unsigned long start = micros(); tft.fillScreen(ILI9341_BLUE); tft.setTextColor(ILI9341_WHITE);

//void drawRoundRect(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint16_t radius, uint16_t color); //Header tft.drawRoundRect(0,0,480,100,10,ILI9341_WHITE);

//Obstruction tft.drawRoundRect(0,110,235,100,10,ILI9341_WHITE); //Counter tft.drawRoundRect(245,110,235,100,10,ILI9341_WHITE);

//Distance Percentage tft.drawRoundRect(0,220,235,100,10,ILI9341_WHITE);

//Distance slide scale tft.drawRoundRect(245,220,235,100,10,ILI9341_WHITE);

tft.setCursor(70,20); tft.setTextSize(3); tft.print("Infra Red Obstruction");

tft.setCursor(170,50); tft.print("Counter");

//Counter header print tft.setCursor(300,120); tft.print("Counter");

//Distance header print tft.setCursor(25,230); tft.print("Distance %"); }

Step 3: Conclusion

The project is successfully completed with Arduino UNO, 320x480 TFT LCD and Infrared reflective sensor module.

The obstacle detection is shown on LCD display as well as serial port.