CIKU + 2Amp Motor Driver Shield

Hi, this tutorial will show you how to build line following robot by using CIKU and 2Amp Motor Driver Shield.

A

HARDWARE

1. CIKU (link).
2. 2Amp Motor Driver Shield (link).
3. Aluminium Robot Chassis Complete Set (link).
4. Auto-Calibrating Line Sensor (link).
5. 2 units of 3.7V 1100mAh Li-Ion Battery (link).
6. 2×18650 Battery Holder (link).
7. Dual 18650 Li-Ion Battery Charger (link).
8. DC Jack(Male) to DG126 Converter (link).
9. Jumper wire to connect from DC motor to 2Amp Motor Driver Shield.
*You can refer here for how to mount CIKU, DC motor and line sensor to robot base.
**Total price ~ RM302.50

2

3

SOFTWARE

Please refer to “Getting Started with CIKU” tutorial.

CIKU SHIELD-2AMOTOR LIBRARY FUNCTION

Below is a list for SHIELD-2AMOTOR function that you can used with CIKU. You also can refer to the Shield2AMotor.h (under CIKU.X folder) for detail.

// Shield2AMotor_begin
// mode: SIGNED_MAGNITUDE or LOCKED_ANTI_PHASE
// sensor: LSS05_ENABLE or LSS05_DISABLE
void Shield2AMotor_begin(BOOL mode, BOOL sensor);
// Shield2AMotor_control
// motor1Speed: -100 to 100
// motor2Speed: -100 to 100
// *minus value will have different direction from positive value
void Shield2AMotor_control(INT16 motor1Speed, INT16 motor2Speed);
// Shield2AMotor_readLSS05
// return status for every IR sensor
// bit 1 represent 'detect line', and vice versa.
// e.g. 0b00100 means middle IR sensor detect black line
// e.g. 0b10000 means most left IR sensor detect black line
// e.g. 0b00001 means most right IR sensor detect black line (next to Cal. push button)
BYTE Shield2AMotor_readLSS05(void);

For more library reference, you can refer here.

USER CODE

This example code shows related function that you can used with 2Amp Motor Driver Shield. You also can see this code under User-LineFollowingRobot.c file (under CIKU.X folder).
*SW on CIKU board can be used as user program too. Please do refer on the following code. So, to run the robot, user need to press the SW first.

#include "Arduino.h"
#include "Shield2AMotor.h"
void setup()
{
Shield2AMotor_begin(SIGNED_MAGNITUDE, LSS05_ENABLE);
pinMode(SW, INPUT); // SW on CIKU board
pinMode(LED, OUTPUT); // LED on CIKU board
while(digitalRead(SW) == HIGH); // Wait SW button to be pressed
digitalWrite(LED, HIGH); // Turn ON LED
}
void loop()
{
BYTE lineSensor = Shield2AMotor_readLSS05();
if(lineSensor == 0b00100)
{
Shield2AMotor_control(80, 80); // Robot move straight forward
}
else if(lineSensor == 0b01100)
{
Shield2AMotor_control(50, 80); // Motor1 speed = 50%, motor2 speed = 80%
}
else if(lineSensor == 0b00110)
{
Shield2AMotor_control(80, 50); // Motor1 speed = 80%, motor2 speed = 50%
}
else if(lineSensor == 0b01000)
{
Shield2AMotor_control(30, 80); // Motor1 speed = 30%, motor2 speed = 80%
}
else if(lineSensor == 0b00010)
{
Shield2AMotor_control(80, 30); // Motor1 speed = 80%, motor2 speed = 30%
}
else if(lineSensor == 0b11000)
{
Shield2AMotor_control(10, 80); // Motor1 speed = 10%, motor2 speed = 80%
}
else if(lineSensor == 0b00011)
{
Shield2AMotor_control(80, 10); // Motor1 speed = 80%, motor2 speed = 10%
}
else if(lineSensor == 0b10000)
{
Shield2AMotor_control(0, 80); // Motor1 stop, motor2 speed = 80%
}
else if(lineSensor == 0b00001)
{
Shield2AMotor_control(80, 0); // Motor1 speed = 80%, motor2 stop
}
}

NOTE

If you want to compile User-LineFollowingRobot.c, under MPLAB X IDE, first please remove the User-Template.c (CIKU – Source Files – user). Right click on User-Template.c and select Remove From Project. Then, right click on user folder (CIKU – Source Files), choose Add Existing Item…, open User-LineFollowingRobot.c, and proceed with Build Project.

Buy

, , ,

Related Post

How to Make your Line Following Robot Faster?

Raspberry Pi: Control DC Motor using MDDS10

Simple steps to control Stepper Motor using 2Amp Motor Driver Shield and CIKU

Line following robot CT-ARM

Line Following Robot with CT-ARM

One thought on “CIKU + 2Amp Motor Driver Shield

Leave a Reply

Your email address will not be published. Required fields are marked *