LAB: ADC - IR reflective sensor
Date: 2025-11-06
Author/Partner:
Github: repository link
Demo Video: Youtube link
PDF version:
Introduction
Create a simple program that uses ADCs to use analog sensors. For this lab, we will use two IR reflective sensors.
The ADCs are triggered by a timer at the given sampling rate.
This lab will be extended to Project: Line Tracing Car
You must submit
LAB Report (*.md & *.pdf)
Zip source files(main*.c, ecRCC.h, ecGPIO.h, ecSysTick.c etc...).
Only the source files. Do not submit project files
Requirement
Hardware
MCU
NUCLEO-F411RE
Actuator/Sensor/Others:
IR Reflective Sensor (TCRT 5000) x2
Software
Keil uVision, CMSIS, EC_HAL library
Problem 0: STM-Arduino
Procedure
Create a new project under the directory
\repos\EC\LAB\LAB_ADCFollow the tutorial: ADC with photodector and sound sensor
Problem 1: EC library
(Option 1) Use the provided library
Download Library Header Files (solution)
(Option 2) Create your own library
Download the exercise files.
Change the file names as
ecADC2.c
ecADC2.h
ecADC2.h
Fill-In missing code in ecADC2_student.c
You must update your header files in the directory EC\include\. and add in ecSTM32F4v2.h
Example Code
Check your library files by running the following examples.
Example 1: One Analog sensor (ADC)
Single-Channel, Continuous Scan
1msec ADC triggering with TIM3
Example 2: Multiple Analog sensors (JADC)
Multi-Channel(2 channels), Continuous Scan
1msec ADC triggering with TIM3
(ADC) Channel Sequence:
SQ1=ADC_CH_8(PB_0) to SQ2=ADC_CH_9(PB_1)
(JADC): Channel Sequence:
JSQ1=ADC_CH_8(PB_0)(PB_0) to JSQ1=ADC_CH_9(PB_1)
JADC: Has its own data register for each ADC channels
ADC: Shares the same data register from multiple channels
Problem 2: Measurement from multiple analog sensors
IR Reflective Sensors (TCRT 5000)
First, download and read IR Reflective Sensor(TCRT 5000): Spec Sheet
TCRT5000 and TCRT5000L are reflective sensors that include an infrared emitter and phototransistor in a leaded package, which blocks visible light.

The HC-SR04 Ultrasonic Range Sensor Features:
Input Voltage : 5V
Detector type: phototransistor
Operating range within > 20 % relative collector current: 0.2 mm to 15 mm
Emitter wavelength: 950 nm
APPLICATIONS
Position sensor for shaft encoder
Detection of reflective material such as paper, IBM cards, magnetic tapes etc.
Limit switch for mechanical motions in VCR
Procedure
Create a new project under the directory
\repos\EC\LAB\LAB_ADC
The project name is “LAB_ADC_IR”
Create a new source file named as “LAB_ADC_IR.c”
You MUST write your name on the source file inside the comment section.
2. Update and use ecSTM32F411.h. This header should be defined as explained in
Configuration
System Clock
PLL 84MHz
GPIO
PB_0 PB_1
Analog Mode No Pull-up Pull-down
ADC (JADC)
PB_0: ADC1_CH8 (1st channel) PB_1: ADC1_CH9 (2nd channel)
ADC Clock Prescaler /8 12-bit resolution, right alignment Continuous Conversion mode Scan mode: Two channels in regular group External Trigger (Timer3 Trigger) @ 1kHz Trigger Detection on Rising Edge
TIM3
Up-Counter, Counter CLK 1kHz OC1M(Output Compare 1 Mode) : PWM mode 1 Master Mode Selection: (Trigger) OC1REF
Line Tracing
Create a logic to trace a dark line on white background surface for your RC car.
Use 2 IR reflective sensors to detect if the black line is in between the sensors. It should display whether the system needs to move Left or Right to keep the line between sensors.
Set the ADC sampling rate trigger to be 1KHz
Determine the threshold value to differentiate dark and white surface of the object.
Display (1) and (2) on serial monitor of Tera-Term. Print the values every second.
(1) reflection value of IR1 and IR2
(2) print ‘GO LEFT’ or ‘GO ‘RIGHT’
Display Example

Circuit Diagram
You need to include the circuit diagram

Discussion
How would you change the code if you need to use 3 Analog sensors?
Answer discussion questions
Which registers should be modified if you need to use Injection Groups instead of regular groups for 2 analog sensors?
Answer discussion questions
Code
Your code goes here: ADD Code LINK such as github
Explain your source code with necessary comments.
Results
Experiment images and results
Show experiment images /results
Add demo video link
Reference
Complete list of all references used (github, blog, paper, etc)
Troubleshooting
(Option) You can write Troubleshooting section
Last updated
Was this helpful?