This project belongs to the series of "Fun Learning with Sumo Robot", this topic focuses on TM023: IR Sensor Module, but not putting it alone, instead we build this project on top of PJ031: Control DC Motor by Motor Driver Module with Arduino, so to make a fun test result, and bring a closer result as wanted by a Sumo Robot. Goals:
Consolidate knowledge and skills of motion parts (DC motor, motor driver) for robotics projects like Sumo Robot
Build knowledge and skills of TM023: IR Sensor Module, what it is, and how to use for boundary/edge detection
Build a fun small demo system using DC Motor + Motor Driver + Dual IR Modules to simulate a Sumo or vehicle robot reaction when reaching edges
START A BIT > Projects Library > This page
[ ] Simple: 30-60 minutes
[x] Moderate: 1-2 hours
[ ] Challenging: more than 2 hours
The estimation bases on average situation without unexpected troubleshooting, assuming that the student meets prerequisites. It only indicates rough time needed to complete this project, but not about technical difficulty, not covering discussion and sharing time.
Experience with Arduino UNO and basic programming skills, preferably participated LP2508: Starting Experience of C++ with Arduino, 25w08
2x DC Motor and wheels
1x Education Shield for UNO
Jumping wires
Purpose: Understand how to wire IR sensor module, and how voltage signal changes indicating detection results
🎬Show Points:
Show the Youtube video
Use battery or power bank to directly power up the module
Use multimeter to monitor the voltage signal output, also observe the LED indication
Use potentiometer to change sensitivity
💡Conclusions
Key Points:
The output is voltage HIGH (no object detected) or LOW (object detected)
LED indication when target object is detected
Adjustable sensitivity by using the potentiometer
Purpose: Basic knowledge of how to wire the hardware, how to use program to get the detection output, how to calibrate the detection threshold
Is it working well for white edge detection?
Please calibrate the expected threshold of the "white" to let it detect accurately.
Add another one, so we have 2 IR sensor modules simulating "Front Side Detector" and "Back Side Detector", modify the code to test with both.
// Input pin from IR module
#define IR_MODULE 2
void setup() {
Serial.begin(115200);
pinMode(IR_MODULE, INPUT);
}
void loop() {
// LOW signal input means detected light color surface!
if (digitalRead(IR_MODULE) == LOW)
{
Serial.println("IR module has detected white edge!");
}
else
{
Serial.println("Well, it's fine...");
}
}
The OUT pin from IR Module should wire to any digital pin of Arduino as Digital Input.
Purpose: Build bigger system with DC Motor and IR Modules, make reactions by IR detection results, so to get better idea of a real use case scenario
This setup combines Task 1 with PJ031: Control DC Motor by Motor Driver Module with Arduino.
There might be a side task to solder some header pins!
I want to reverse the robot when the front IR module detects the white edge, here is the example code with some bugs, please fix the faults and test working as expected.
// Control pins for Motor A, adapt to your real wiring
#define IN1 5
#define IN2 6
// Control pins for Motor B, adapt to your real wiring
#define IN3 10
#define IN4 11
// Input pins from IR modules
#define IR_FRONT 2
int speed = 200;
void setup() {
Serial.begin(115200);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
pinMode(IR_FRONT, INPUT);
}
void loop() {
// LOW signal input means detected light color surface!
if (digitalRead(IR_FRONT) == LOW)
{
Serial.println("Front IR detected edge! Let's move back!");
analogWrite(IN1, 0);
analogWrite(IN2, speed);
analogWrite(IN3, 0);
analogWrite(IN4, speed);
}
Serial.println("It's fine, let's move forward!");
analogWrite(IN1, speed);
analogWrite(IN2, 0);
analogWrite(IN3, speed);
analogWrite(IN4, 0);
}
This example code makes an interesting program with both Front Detection and Back Detection, and simulates the reaction to avoid overrun.
The code has some bugs, please fix the faults and test working as expected.
// Control pins for Motor A, adapt to your real wiring
#define IN1 5
#define IN2 6
// Control pins for Motor B, adapt to your real wiring
#define IN3 10
#define IN4 11
// Input pins from IR modules
#define IR_FRONT 2
#define IR_BACK 3
void setup() {
Serial.begin(115200);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
pinMode(IR_FRONT, INPUT);
pinMode(IR_BACK, OUTPUT); // Fix bug here
}
void loop() {
if (digitalRead(IR_FRONT) == LOW)
{
Serial.println("Oops, front side is in danger!");
reverse(200);
}
else if (digitalRead(IR_BACK) == HIGH) // Fix bug here
{
Serial.println("Oops, back side is in danger!");
drive(200);
}
// We are safe, just drive in full speed!
else
{
Serial.println("Safe, full speed driving");
drive(255);
}
// Deley a bit for easier log reading
delay(500);
}
void drive(int speed)
{
Serial.println("Driving forward!");
analogWrite(IN1, speed);
analogWrite(IN2, 0);
analogWrite(IN3, speed);
analogWrite(IN4, 0);
}
void reverse(int speed)
{
Serial.println("Reverse back!");
analogWrite(IN1, 0);
analogWrite(IN2, speed);
analogWrite(IN3, 0);
analogWrite(IN4, speed);
}
Purpose: Enhance basic knowledge understanding, reflect and summarize what we have learnt
How does IR Sensor Module work to detect a target object? What could affect the detection result?
What to do in program to get the IR Sensor Module detection result?
Where to mount the sensor module in a real robot to get a best working result?
Take 1-2 minutes to explore anything on the tools and the making flow, with curiosity, no matter how much prior knowledge you have, you should make
At least 1 interesting finding
At least 1 curious question