LAB: ADC - IR sensor
Date: 2023-11-13
Author/Partner:
Github: repository link
Demo Video: Youtube link
PDF version:
Introduction
IR Reflective Sensor
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 for the LAB: 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 1: EC library
Using HAL library
Download ecADC_student.c ecADC_student.h
Change the file names as
ecADC.c, ecADC.h
Fill-in the missing code lines to define the following functions.
You must update your header files located in the directory EC \lib\
.
ecADC.h
Example Code
Check your library files by running the following examples.
Example 1: Using one Analog sensor
Single-Channel, Continuous Scan, 1msec ADC triggering with TIM3
Example 2: Using 2 Analog sensors
Multi-Channel, Continuous Scan, 1msec ADC triggering with TIM3
Channel Sequence:
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_IR
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
Type | Port - Pin | Configuration |
---|---|---|
System Clock | PLL 84MHz | |
GPIO | PB_0 PB_1 | Analog Mode No Pull-up Pull-down |
ADC | 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