Maker Nano RP2040 Interfacing With Maker Line Using Arduino IDE

Maker Nano RP2040 Interfacing With Maker Line Using Arduino IDE

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.

2

makernanorp2040 makerdrive time 0 00 1815

Hardware Components

 

Building The Circuit

  1. 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.

 

3

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.

maker line time 0 00 5515

 

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."

 

 


Related Posts

Build Fun Piano with Ultrasonic using Maker Nano RP2040

Build Fun Piano with Ultrasonic using Maker Nano RP2040

This tutorial shows how to make a piano using an ultrasonic sensor and Maker Nano RP2040. The project is super fun and very simple to make!....
Bidirectional Visitor Counter using CircuitPython on Maker Nano RP2040

Bidirectional Visitor Counter using CircuitPython on Maker Nano RP2040

In this video I would like to share about a bidirectional visitor counter project that is programmed using CircuitPython on Maker Nano RP2040.....
Maker Nano RP2040 Interfacing With Maker Drive Using Arduino IDE

Maker Nano RP2040 Interfacing With Maker Drive Using Arduino IDE

 Video Hardware PreparationThis are the list of items used in this tutorial.Maker Nano RP2040: Simplifying Projects with Raspberry Pi RP2040Make....
Display Images on Graphic LCD with Maker Nano RP2040

Display Images on Graphic LCD with Maker Nano RP2040

Display Image on the graphic LCD using Maker Nano RP2040 and CircuitPython..