7. Case 05: A Line-follwing Car#

7.1. Purpose#


Make a line-following car with NezhaA Inventor’s Kit.

../../_images/neza-a-case-05-01.png

7.2. Purchse#


NezhaA Inventor’s Kit

7.3. Materials Required#


../../_images/neza-a-case-05-02.png

7.4. Assembly Steps#


../../_images/neza-a-step-05-01.png ../../_images/neza-a-step-05-02.png ../../_images/neza-a-step-05-03.png ../../_images/neza-a-step-05-04.png ../../_images/neza-a-step-05-05.png ../../_images/neza-a-step-05-06.png ../../_images/neza-a-step-05-07.png ../../_images/neza-a-step-05-08.png ../../_images/neza-a-step-05-09.png ../../_images/neza-a-step-05-10.png ../../_images/neza-a-step-05-11.png ../../_images/neza-a-step-05-12.png ../../_images/neza-a-step-05-13.png ../../_images/neza-a-step-05-14.png ../../_images/neza-a-step-05-15.png ../../_images/neza-a-step-05-16.png ../../_images/neza-a-step-05-17.png ../../_images/neza-a-step-05-18.png ../../_images/neza-a-step-05-19.png ../../_images/neza-a-step-05-20.png ../../_images/neza-a-step-05-21.png ../../_images/neza-a-step-05-22.png ../../_images/neza-a-step-05-23.png ../../_images/neza-a-step-05-24.png ../../_images/neza-a-step-05-25.png ../../_images/neza-a-step-05-26.png ../../_images/neza-a-step-05-27.png ../../_images/neza-a-step-05-28.png ../../_images/neza-a-step-05-29.png ../../_images/neza-a-step-05-30.png ../../_images/neza-a-step-05-31.png ../../_images/neza-a-step-05-32.png ../../_images/neza-a-step-05-33.png ../../_images/neza-a-step-05-34.png ../../_images/neza-a-step-05-35.png ../../_images/neza-a-step-05-36.png ../../_images/neza-a-step-05-37.png ../../_images/neza-a-step-05-38.png ../../_images/neza-a-step-05-39.png

7.5. Hardware Connections#


Connect two motors to M1 and M2 port and the line-tracking sensor on Nezha-A master box. ../../_images/neza-a-case-05-03.png

7.6. Programming#


7.6.1. Prepare the programming#

Steps for preparation please refer to: Arduino 3 in 1 Breakout Board

Import the libraries and the subsidiary libraries of Nezha-A master box and then import the libraries of the line-tracking sensor: PlanetXTracking-main.zip Download and import the self-defined library connections for Nezha-A master box: RJPins-main.zip

7.6.2. Sample Projects:#

// Language ArduinoC
#include <NezhaA.h>
#include <RJPins.h>
#include <PlanetXTracking.h>

PlanetXTracking trackingJ1(J1);    //Create an instance of PlanetXTracking category
NezhaA nezha;    /Create an instance of NezhaA category

void setup() {
  nezha.begin();    //Initiliaze the buzzer, motor, servo and light
}

void loop() {
  if (trackingJ1.isTracked(Right)) {
    nezha.setMotorSpeed(M1, 0);    //Set the speed of the motor connecting to M1 at 0%
    nezha.setMotorSpeed(M2, 15);    //Set the speed of the motor connecting to M2 at 15%
  }
  if (trackingJ1.isTracked(Left)) {
    nezha.setMotorSpeed(M1, 15);    //Set the speed of the motor connecting to M1 at 15%
    nezha.setMotorSpeed(M2, 0);    //Set the speed of the motor connecting to M2 at 0%
  }  
}

7.6.3. Result#

After powering on, the car drives along with the map.