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 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//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