10. Case 08: A Big Beetle#

10.1. Purpose#


Make a big beetle with NezhaA Inventor’s Kit.

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

10.2. Purchse#


NezhaA Inventor’s Kit

10.3. Materials Required#


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

10.4. Assembly Steps#


../../_images/neza-a-step-08-01.png ../../_images/neza-a-step-08-02.png ../../_images/neza-a-step-08-03.png ../../_images/neza-a-step-08-04.png ../../_images/neza-a-step-08-05.png ../../_images/neza-a-step-08-06.png ../../_images/neza-a-step-08-07.png ../../_images/neza-a-step-08-08.png ../../_images/neza-a-step-08-09.png ../../_images/neza-a-step-08-10.png ../../_images/neza-a-step-08-11.png ../../_images/neza-a-step-08-12.png ../../_images/neza-a-step-08-13.png ../../_images/neza-a-step-08-14.png ../../_images/neza-a-step-08-15.png ../../_images/neza-a-step-08-16.png ../../_images/neza-a-step-08-17.png ../../_images/neza-a-step-08-18.png ../../_images/neza-a-step-08-19.png ../../_images/neza-a-step-08-20.png ../../_images/neza-a-step-08-21.png ../../_images/neza-a-step-08-22.png ../../_images/neza-a-step-08-23.png ../../_images/neza-a-step-08-24.png ../../_images/neza-a-step-08-25.png ../../_images/neza-a-step-08-26.png ../../_images/neza-a-step-08-27.png ../../_images/neza-a-step-08-28.png ../../_images/neza-a-step-08-29.png ../../_images/neza-a-step-08-30.png ../../_images/neza-a-step-08-31.png ../../_images/neza-a-step-08-32.png ../../_images/neza-a-step-08-33.png ../../_images/neza-a-step-08-34.png ../../_images/neza-a-step-08-35.png ../../_images/neza-a-step-08-36.png ../../_images/neza-a-step-08-37.png ../../_images/neza-a-step-08-38.png ../../_images/neza-a-step-08-39.png ../../_images/neza-a-step-08-40.png ../../_images/neza-a-step-08-41.png ../../_images/neza-a-step-08-42.png ../../_images/neza-a-step-08-43.png ../../_images/neza-a-step-08-44.png ../../_images/neza-a-step-08-45.png ../../_images/neza-a-step-08-46.png ../../_images/neza-a-step-08-47.png ../../_images/neza-a-step-08-48.png ../../_images/neza-a-step-08-49.png ../../_images/neza-a-step-08-50.png ../../_images/neza-a-step-08-51.png ../../_images/neza-a-step-08-52.png ../../_images/neza-a-step-08-53.png ../../_images/neza-a-step-08-54.png ../../_images/neza-a-step-08-55.png ../../_images/neza-a-step-08-56.png ../../_images/neza-a-step-08-57.png ../../_images/neza-a-step-08-58.png ../../_images/neza-a-step-08-59.png ../../_images/neza-a-step-08-60.png ../../_images/neza-a-step-08-61.png ../../_images/neza-a-step-08-62.png

10.5. Hardware Connections#


Connect two motors to M1 and M2 port, the ultrasonic sound sensor to J1 port and the line-tracking sensor on J2 port on Nezha-A master box.

../../_images/neza-a-case-08-03.png

10.6. Programming#


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

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

10.6.2. Sample Code:#

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

PlanetXTracking trackingJ2(J2);    //Create an instance of PlanetXTracking category
NezhaA nezhaa;    //Create an instance of Nezha category
PlanetXUltrasonic ultrasonicJ1(J1);    // Create an instance of PlanetXUltrasonic category
int distance;    //Create a variable of int distance

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

void loop() {
  distance = (ultrasonicJ1.getDistance());    //Set the detected value from ultrasonic sound sensor as the variable distance 
  if (distance > 3 && distance < 20) {    //Judge if the variable is over 3 and below 20
    nezhaa.setMotorSpeed(M1, 0);    //Set the speed of the motor connecting to M1 at 0%
    nezhaa.setMotorSpeed(M2, 0);    //Set the speed of the motor connecting to M2 at 0%
  } 
  else {
    if (trackingJ2.isTracked(Right)) {
      nezhaa.setMotorSpeed(M1, 0);    //Set the speed of the motor connecting to M1 at 0%
      nezhaa.setMotorSpeed(M2, 20);    //Set the speed of the motor connecting to M2 at 20%
    }
    if (trackingJ2.isTracked(Left)) {
      nezhaa.setMotorSpeed(M1, 20);    //Set the speed of the motor connecting to M1 at 20%
      nezhaa.setMotorSpeed(M2, 0);    //Set the speed of the motor connecting to M2 at 0%
    }  
  }  
}

10.6.3. Result#

After powering on, the beetle walks along with the line and it stops while it detects the obstacles.