element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Twist, Turn and Move Design Challenge with TE Robotics
  • Challenges & Projects
  • Design Challenges
  • Twist, Turn and Move Design Challenge with TE Robotics
  • More
  • Cancel
Twist, Turn and Move Design Challenge with TE Robotics
Blog Twist, Turn, & Move Design Challenge - Unlimited CNC Robot - Blog #2
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Leaderboard
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: dwinhold
  • Date Created: 13 Aug 2022 2:53 PM Date Created
  • Views 712 views
  • Likes 9 likes
  • Comments 4 comments
  • robots
  • Line Following
  • cnc
  • dwinhold
  • Twist Turn and Move Robotics Design Challenge
Related
Recommended

Twist, Turn, & Move Design Challenge - Unlimited CNC Robot - Blog #2

dwinhold
dwinhold
13 Aug 2022

Unlimited CNC Robot Blog #2 - The making of the line following robot.

For the first part of my project, I created the line follower. I felt it would be best to make a working line following robot first, the 2nd part is to add the CNC.

I did have to change one part of my robot and that was switching from a spindle CNC to a laser CNC. I found with the spindle that the torque of when it starts turns the robot almost 180 degrees. The chassis and wheel motors aren't strong enough to handle the spindle. I can't afford upgrading to more appropriate hardware at this time. Using a laser still accomplishes what I envisioned.

Below is the code and pictures of my project so far:

/**Unlimited CNC Robot**/
/**set control port - DFRobot L298P**/
const int E1Pin = 10;
const int M1Pin = 12;
const int E2Pin = 11;
const int M2Pin = 13;

/**inner definition**/
typedef struct {
  byte enPin;
  byte directionPin;
} MotorContrl;
 
const int M1 = 0;
const int M2 = 1;
const int MotorNum = 2;

const MotorContrl MotorPin[] = { {E1Pin, M1Pin}, {E2Pin, M2Pin} } ;

const int Forward = LOW;
const int Backward = HIGH;

//Sensor Connection
const int left_sensor_pin =A0;
const int right_sensor_pin =A1;
const int laser_on_sensor_pin =A2;
const int laser_off_sensor_pin =A3;

int left_sensor_state;
int right_sensor_state;
int laser_on_sensor_state;
int laser_off_sensor_state;
int turn_delay = 10;
 

/**program**/
void setup() {
 
  initMotor();
}

void loop() {
  int value;
 
  left_sensor_state = analogRead(left_sensor_pin);
  right_sensor_state = analogRead(right_sensor_pin);
  laser_on_sensor_state = analogRead(left_sensor_pin);
  laser_off_sensor_state = analogRead(right_sensor_pin);  

    if(laser_on_sensor_state  < 500)
{
  Serial.println("Laser On");
    setMotorSpeed( M1, 0 );
    setMotorSpeed( M2, 0 );

    /**Code to turn laser on**/

    delay(200);

    setMotorDirection( M1, Forward );
    setMotorSpeed( M1, 100 );
    setMotorDirection( M2, Forward );
    setMotorSpeed( M2, 100 );

    delay(500);
 
  }
 
if(laser_off_sensor_state  < 500)
{
  Serial.println("Laser Off");
    setMotorSpeed( M1, 0 );
    setMotorSpeed( M2, 0 );

    /**Code ot turn laser off**/

    delay(200);

    setMotorDirection( M1, Forward );
    setMotorSpeed( M1, 100 );
    setMotorDirection( M2, Forward );
    setMotorSpeed( M2, 100 );

    delay(500);
    }
 
   if(right_sensor_state > 500 && left_sensor_state < 500)
{
  Serial.println("turning right");

  setMotorDirection( M2, Forward );
  setMotorSpeed( M2, 100 );

  setMotorSpeed( M1, 0 );

  delay(turn_delay);
 
  }
if(right_sensor_state < 500 && left_sensor_state > 500)
{
  Serial.println("turning left");
 
  setMotorDirection( M1, Forward );
  setMotorSpeed( M1, 100 );

  setMotorSpeed( M2, 0 );
 
  delay(turn_delay);
  }

if(right_sensor_state > 500 && left_sensor_state > 500)
{
  Serial.println("going forward");

  setMotorDirection( M1, Forward );
  setMotorSpeed( M1, 100 );
  setMotorDirection( M2, Forward );
  setMotorSpeed( M2, 100 );

  delay(turn_delay);
 
  }

if(right_sensor_state < 500 && left_sensor_state < 500)
{
  Serial.println("stop");
 
  setMotorSpeed( M1, 0 );
  setMotorSpeed( M2, 0 );
 
  }

}

/**functions**/
void initMotor( ) {
  int i;
  for ( i = 0; i < MotorNum; i++ ) {
    digitalWrite(MotorPin[i].enPin, LOW);

    pinMode(MotorPin[i].enPin, OUTPUT);
    pinMode(MotorPin[i].directionPin, OUTPUT);
  }
}
 
/**  motorNumber: M1, M2
direction:          Forward, Backward **/
void setMotorDirection( int motorNumber, int direction ) {
  digitalWrite( MotorPin[motorNumber].directionPin, direction);
}

/** speed:  0-100   * */
inline void setMotorSpeed( int motorNumber, int speed ) {
  analogWrite(MotorPin[motorNumber].enPin, 255.0 * (speed / 100.0) ); //PWM
}

image

Thank you for reading my blog!! Any comments or suggestions are welcome.

As a note, the kit supplied is very generous!! Thank you very much to our sponsor TE Connectivity and Element14!!

Dale Winhold

  • Sign in to reply
  • dwinhold
    dwinhold over 3 years ago in reply to dougw

    They did come with the encoder wheel. I had these for a few years now.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • dougw
    dougw over 3 years ago in reply to dwinhold

    I have some similar yellow gearmotors but they don't have an encoder wheel - did these come with the encoder wheel?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • dwinhold
    dwinhold over 3 years ago in reply to robogary

    I’m hoping to get better motors before the project is due, but they work ok. The white wheels are for LED encoders.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • robogary
    robogary over 3 years ago

    Nice progress. How do you like the yellow gearmotors ?  Are they sturdy enough ?  Are the white wheels on the motor shaft meant for LED encoders ? 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube