Your shopping cart is empty!
Maker Nano RP2040 Interfacing With Maker Line Using Arduino IDE
- Hussien Jawhar Sathik
- 12 Apr 2022
- Tutorial
- 1913
Introduction
In this tutorial we shall see how to interface Maker Nano RP2040 with Maker Line. This is the continuation from the previous tutorial whereby we have seen how to control the DC motor using the Maker Drive. At the end of the tutorial we shall see how the Maker Line Following Robot function.
Video
Hardware Preparation
Since this is a continuation from the previous tutorial the additional that we will need is the Maker Line.
Building The Circuit
- Constructing the circuit is pretty much easy since we are using the grove connector. The connection between the devices are done as per the below figure.
Once the connection are made as per the figure above, we can now start to code.
Code
For the code, since we have used different type of devices, please ensure that all the library has been downloaded prior to running this code.
#include "CytronMotorDriver.h"
// Maker Line Sensor Pin Connection
#define LINE_D1 6
#define LINE_D2 7
#define LINE_D3 8
#define LINE_D4 9
#define LINE_D5 10
// Configure the motor driver.
CytronMD motor1(PWM_DIR, 2, 3); // PWM 1 = Pin 2, DIR 1 = Pin 3.
CytronMD motor2(PWM_DIR, 4, 5); // PWM 2 = Pin 4, DIR 2 = Pin 5.
// The setup routine runs once when you press reset.
void setup() {
pinMode(LINE_D1, INPUT);
pinMode(LINE_D2, INPUT);
pinMode(LINE_D3, INPUT);
pinMode(LINE_D4, INPUT);
pinMode(LINE_D5, INPUT);
}
// The loop routine runs over and over again forever.
void loop() {
// Perform line following
int D1 = digitalRead(LINE_D1);
int D2 = digitalRead(LINE_D2);
int D3 = digitalRead(LINE_D3);
int D4 = digitalRead(LINE_D4);
int D5 = digitalRead(LINE_D5);
if (D1==0 && D2==0 && D3==1 && D4==0 && D5==0) {
motor1.setSpeed(100);
motor2.setSpeed(100); //robot move forward
}
else if (D1==0 && D2==1 && D3==0 && D4==0 && D5==0) {
motor1.setSpeed(50);
motor2.setSpeed(100); //move to left
}
else if (D1==1 && D2==0 && D3==0 && D4==0 && D5==0) {
motor1.setSpeed(0);
motor2.setSpeed(100); //robot slowing down, move more to left
}
else if (D1==0 && D2==0 && D3==0 && D4==1 && D5==0) {
motor1.setSpeed(100);
motor2.setSpeed(50); //move to right
}
else if (D1==0 && D2==0 && D3==0 && D4==0 && D5==1) {
motor1.setSpeed(100);
motor2.setSpeed(0); //robot slowing down, move more to right
}
else {
}
}
Outcome
Just remember to calibrate the maker line before start beginning the line following task.
Thank You
Thanks for reading this tutorial. If you have any technical inquiries, please post at Cytron Technical Forum.
"Please be reminded, this tutorial is prepared for you to try and learn.
You are encouraged to improve the code for a better application."