TM4C InterfacingIR Emitter/Detector Pair

Share

Interfacing TCRT5000 IR Emitter/Detector Pair with TM4C

In this example, we going to have TCRT5000 IR Emitter/Detector pair as an input , an LED  and  a DC motor  as outputs. The way the code works is, if a an object is placed within the sensing range of the IR sensor, the LED turns on and the DC motor starts to rotate.  This pieced of code is part of a bigger code written to control a line following robot. We shall discuss how to build and program this robot in future lessons.



		
Program 
//Digital sensor
//Author :cortex-m.com
//Function: Interfacing TCRT5000 IR module as a digital sensor
#include "TM4C123.h"                    // Device header
#include <stdint.h>
#define DETECTOR (1U<<4)
#define LED_BLUE (1U<<2)
#define MOTOR (1U<<6) unint_32 state=0; void Port_init(void); int main(void) { Port_init(); while(1){ if((GPIOA -> DATA & DETECTOR)==DETECTOR)
	{
		 state = 0;
	 GPIOF ->DATA &= ~LED_BLUE;
	 GPIOA ->DATA &= ~MOTOR;
	}
	else
	{
		state =1;
		GPIOF -> DATA |=LED_BLUE;
		GPIOA -> DATA |=MOTOR ;
	}



}
}



void Port_init(void)
{
	SYSCTL->RCGCGPIO |=(1U<<0)|(1U<<5); GPIOF ->DIR  |=LED_BLUE;
	GPIOF ->DEN  |=LED_BLUE;
	GPIOA ->DR8R |=MOTOR;
	GPIOA ->DIR  |=MOTOR;
	GPIOA -> DEN |=DETECTOR|MOTOR ;



}



London, U.K
© 2019 BOHOBIOM LTD