How to make homework machine for students

How to make homework machine for students


homework machine is a Computerized Numerical Control(CNC) machine which can run through G-code.
G-code is a programming language for CNC that instructs machines where and how to move.
The G-code is based on image file, you can put a image file in Inkscape software and convert it to CNC language.
If you are using a complicate image file then you must draw an outline with the image and put it to the Inkscape.
The machine also writes the latter but only in g-code, you have to convert the latter into G-code.

Required Materials

Arduino Nano 328p
L293D IC
Servo Motor 9g

2X DVD Drive

Male & Female headers

Power supply Connector


Pen etc.





First of all you need two Standard PC OLD DVD DRIVE, The DVD drive must has 4 wire stepper motor(you can’t do this with normal DVD drive which has two wire DC motor)

Now Unscrew the DVD drive and pick out the lens slider, slider rod and Stepper motor.

Now you need to check the stepper motor is working or not, it’s an easy method , mainly stepper motor has two coils and one coil has two ends so respectively two wire has four ends so the upper side of stepper motor has 4 connection point and it connects to the two coils internally. Now you have to point out your A1B1A2B2 connections by following this image

Now you need to take your multi-meter in continuity point and check 4 wire point if stepper motor coil is in good condition then the multi-meter will buzzing two wires.



Now you have to cut the lens mount for make the slider more compact for this project, you can super glue the both cutting pars and put slider rods in the hole.



Now you cut the 2mm ACP(Aluminum Composite panel) sheet or 3mm acrylic sheet by follow the Stepper motor and Slider rod size.



You have to attach the stepper motor on the ACP sheet and screw or glue it.



Now you glue the DIY compact slider on this frame then your X-Axis Slider is ready, Now you have to do this same procedure for Y-Axis with second DVD drive.

When both axis is ready you can attach the Y-axis over the X-axis and align the axis 90 degree.




Making Pen Mechanism

It’s most revolutionary mechanism ever,
Required Materials-
Normal DVD drive ROD
One Lens Mount
One Pen
Copper Wire

Take the 3mm Rod and spiral the copper wire to make it like a spring or you can use a pen spring, now insert the rod in the cutting Lens mount and Screw the cutting pen Cap and add a enlightenment part (I made it through ACP sheet) because it hold the pen in one position, Now you can attach the servo motor



Now you have to glue the pen mechanism to the Y-axis




Making Circuit


Now you Make the circuit by Following the Circuit Diagram



Warning– You have to the circuit by following the circuit diagram wiring connection using your multi-meter in continuity Mode.



Now attach you circuit on the machine and make connections(X-axis,Y-axis,Servo)






Connect your Arduino to your computer and Open Arduino IDE,



First You have to choose the Board type Arduino Nano
Select communication port,Select Processor-> Atmega328P and Upload this Arduino nano



*If you are facing any issue with com_port or problem uploading to board

*You must have Windows10 for better driver Support(com_port issue) or update your USB driver through Device Manager
*Choose processor type Atmega328p t0 Atmega328p old boot-loader
*Remove your Arduino from the circuit and upload the code (L293D driver make create issue during uploading the code so remove the Arduino and upload)



#include <Servo.h>
#include <Stepper.h>


const int penZUp = 80;
const int penZDown = 40;

const int penServoPin = 6;

const int stepsPerRevolution = 20; 

Servo penServo;  

Stepper myStepperY(stepsPerRevolution, 2,3,4,5);            
Stepper myStepperX(stepsPerRevolution, 8,9,10,11);  

struct point { 
  float x; 
  float y; 
  float z; 

struct point actuatorPos;

float StepInc = 1;
int StepDelay = 0;
int LineDelay = 50;
int penDelay = 50;

float StepsPerMillimeterX = 6.0;
float StepsPerMillimeterY = 6.0;

float Xmin = 0;
float Xmax = 40;
float Ymin = 0;
float Ymax = 40;
float Zmin = 0;
float Zmax = 1;

float Xpos = Xmin;
float Ypos = Ymin;
float Zpos = Zmax; 

boolean verbose = false;

void setup() {
  Serial.begin( 9600 );


  Serial.println("Mini CNC Plotter alive and kicking!");
  Serial.print("X range is from "); 
  Serial.print(" to "); 
  Serial.println(" mm."); 
  Serial.print("Y range is from "); 
  Serial.print(" to "); 
  Serial.println(" mm."); 

void loop() 
  char line[ LINE_BUFFER_LENGTH ];
  char c;
  int lineIndex;
  bool lineIsComment, lineSemiColon;

  lineIndex = 0;
  lineSemiColon = false;
  lineIsComment = false;

  while (1) {

    while ( Serial.available()>0 ) {
      c =;
      if (( c == '\n') || (c == '\r') ) {             
        if ( lineIndex > 0 ) {                        
          line[ lineIndex ] = '\0';                   
          if (verbose) { 
            Serial.print( "Received : "); 
            Serial.println( line ); 
          processIncomingLine( line, lineIndex );
          lineIndex = 0;
        else { 
        lineIsComment = false;
        lineSemiColon = false;
      else {
        if ( (lineIsComment) || (lineSemiColon) ) {   // Throw away all comment characters
          if ( c == ')' )  lineIsComment = false;     // End of comment. Resume line.
        else {
          if ( c <= ' ' ) {                           // Throw away whitepace and control characters
          else if ( c == '/' ) {                    // Block delete not supported. Ignore character.
          else if ( c == '(' ) {                    // Enable comments flag and ignore all characters until ')' or EOL.
            lineIsComment = true;
          else if ( c == ';' ) {
            lineSemiColon = true;
          else if ( lineIndex >= LINE_BUFFER_LENGTH-1 ) {
            Serial.println( "ERROR - lineBuffer overflow" );
            lineIsComment = false;
            lineSemiColon = false;
          else if ( c >= 'a' && c <= 'z' ) {        // Upcase lowercase
            line[ lineIndex++ ] = c-'a'+'A';
          else {
            line[ lineIndex++ ] = c;

void processIncomingLine( char* line, int charNB ) {
  int currentIndex = 0;
  char buffer[ 64 ];                                 // Hope that 64 is enough for 1 parameter
  struct point newPos;

  newPos.x = 0.0;
  newPos.y = 0.0;

  //  Needs to interpret 
  //  G1 for moving
  //  G4 P300 (wait 150ms)
  //  G1 X60 Y30
  //  G1 X30 Y50
  //  M300 S30 (pen down)
  //  M300 S50 (pen up)
  //  Discard anything with a (
  //  Discard any other command!

  while( currentIndex < charNB ) {
    switch ( line[ currentIndex++ ] ) {              // Select command, if any
    case 'U':
    case 'D':
    case 'G':
      buffer[0] = line[ currentIndex++ ];          // /!\ Dirty - Only works with 2 digit commands
      //      buffer[1] = line[ currentIndex++ ];
      //      buffer[2] = '\0';
      buffer[1] = '\0';

      switch ( atoi( buffer ) ){                   // Select G command
      case 0:                                   // G00 & G01 - Movement or fast movement. Same here
      case 1:
        // /!\ Dirty - Suppose that X is before Y
        char* indexX = strchr( line+currentIndex, 'X' );  // Get X/Y position in the string (if any)
        char* indexY = strchr( line+currentIndex, 'Y' );
        if ( indexY <= 0 ) {
          newPos.x = atof( indexX + 1); 
          newPos.y = actuatorPos.y;
        else if ( indexX <= 0 ) {
          newPos.y = atof( indexY + 1);
          newPos.x = actuatorPos.x;
        else {
          newPos.y = atof( indexY + 1);
          indexY = '\0';
          newPos.x = atof( indexX + 1);
        drawLine(newPos.x, newPos.y );
        //        Serial.println("ok");
        actuatorPos.x = newPos.x;
        actuatorPos.y = newPos.y;
    case 'M':
      buffer[0] = line[ currentIndex++ ];        // /!\ Dirty - Only works with 3 digit commands
      buffer[1] = line[ currentIndex++ ];
      buffer[2] = line[ currentIndex++ ];
      buffer[3] = '\0';
      switch ( atoi( buffer ) ){
      case 300:
          char* indexS = strchr( line+currentIndex, 'S' );
          float Spos = atof( indexS + 1);
          //          Serial.println("ok");
          if (Spos == 30) { 
          if (Spos == 50) { 
      case 114:                                // M114 - Repport position
        Serial.print( "Absolute position : X = " );
        Serial.print( actuatorPos.x );
        Serial.print( "  -  Y = " );
        Serial.println( actuatorPos.y );
        Serial.print( "Command not recognized : M");
        Serial.println( buffer );


void drawLine(float x1, float y1) {

  if (verbose)
    Serial.print("fx1, fy1: ");

  if (x1 >= Xmax) { 
    x1 = Xmax; 
  if (x1 <= Xmin) { 
    x1 = Xmin; 
  if (y1 >= Ymax) { 
    y1 = Ymax; 
  if (y1 <= Ymin) { 
    y1 = Ymin; 

  if (verbose)
    Serial.print("Xpos, Ypos: ");

  if (verbose)
    Serial.print("x1, y1: ");

  //  Convert coordinates to steps
  x1 = (int)(x1*StepsPerMillimeterX);
  y1 = (int)(y1*StepsPerMillimeterY);
  float x0 = Xpos;
  float y0 = Ypos;

  //  Let's find out the change for the coordinates
  long dx = abs(x1-x0);
  long dy = abs(y1-y0);
  int sx = x0<x1 ? StepInc : -StepInc;
  int sy = y0<y1 ? StepInc : -StepInc;

  long i;
  long over = 0;

  if (dx > dy) {
    for (i=0; i<dx; ++i) {
      if (over>=dx) {
  else {
    for (i=0; i<dy; ++i) {
      if (over>=dy) {

  if (verbose)
    Serial.print("dx, dy:");

  if (verbose)
    Serial.print("Going to (");

  Xpos = x1;
  Ypos = y1;

void penUp() { 
  if (verbose) { 
    Serial.println("Pen up!"); 
void penDown() { 
  if (verbose) { 
    Serial.println("Pen down."); 





Run Your Machine


External power supply- you have to give 5V @ 0.5amp to the circuit board for proper work.


Open Processing and copy paste the code from here, Now Run the Code, it will popup a window for all controls


Processing Software



Copy paste the code from here


import java.awt.event.KeyEvent;
import javax.swing.JOptionPane;
import processing.serial.*;

Serial port = null;

// select and modify the appropriate line for your operating system
// leave as null to use interactive port (press 'p' in the program)
String portname = null;
//String portname = Serial.list()[0]; // Mac OS X
//String portname = "/dev/ttyUSB0"; // Linux
//String portname = "COM6"; // Windows

boolean streaming = false;
float speed = 0.001;
String[] gcode;
int i = 0;

void openSerialPort()
  if (portname == null) return;
  if (port != null) port.stop();
  port = new Serial(this, portname, 9600);

void selectSerialPort()
  String result = (String) JOptionPane.showInputDialog(frame,
    "Select the serial port that corresponds to your Arduino board.",
    "Select serial port",
  if (result != null) {
    portname = result;

void setup()
  size(600, 400);

void draw()
  int y = 24, dy = 12;
  text("INSTRUCTIONS", 12, y); y += dy;
  text("p: select serial port", 12, y); y += dy;
  text("1: set speed to 0.001 inches (1 mil) per jog", 12, y); y += dy;
  text("2: set speed to 0.010 inches (10 mil) per jog", 12, y); y += dy;
  text("3: set speed to 0.100 inches (100 mil) per jog", 12, y); y += dy;
  text("arrow keys: jog in x-y plane", 12, y); y += dy;
  text("page up & page down: jog in z axis", 12, y); y += dy;
  text("$: display grbl settings", 12, y); y+= dy;
  text("h: go home", 12, y); y += dy;
  text("0: zero machine (set home to the current location)", 12, y); y += dy;
  text("g: stream a g-code file", 12, y); y += dy;
  text("x: stop streaming g-code (this is NOT immediate)", 12, y); y += dy;
  y = height - dy;
  text("current jog speed: " + speed + " inches per step", 12, y); y -= dy;
  text("current serial port: " + portname, 12, y); y -= dy;

void keyPressed()
  if (key == '1') speed = 0.001;
  if (key == '2') speed = 0.01;
  if (key == '3') speed = 0.1;
  if (!streaming) {
    if (keyCode == LEFT) port.write("G91\nG20\nG00 X-" + speed + " Y0.000 Z0.000\n");
    if (keyCode == RIGHT) port.write("G91\nG20\nG00 X" + speed + " Y0.000 Z0.000\n");
    if (keyCode == UP) port.write("G91\nG20\nG00 X0.000 Y" + speed + " Z0.000\n");
    if (keyCode == DOWN) port.write("G91\nG20\nG00 X0.000 Y-" + speed + " Z0.000\n");
    if (keyCode == KeyEvent.VK_PAGE_UP) port.write("G91\nG20\nG00 X0.000 Y0.000 Z" + speed + "\n");
    if (keyCode == KeyEvent.VK_PAGE_DOWN) port.write("G91\nG20\nG00 X0.000 Y0.000 Z-" + speed + "\n");
    if (key == 'h') port.write("G90\nG20\nG00 X0.000 Y0.000 Z0.000\n");
    if (key == 'v') port.write("$0=75\n$1=74\n$2=75\n");
    //if (key == 'v') port.write("$0=100\n$1=74\n$2=75\n");
    if (key == 's') port.write("$3=10\n");
    if (key == 'e') port.write("$16=1\n");
    if (key == 'd') port.write("$16=0\n");
    if (key == '0') openSerialPort();
    if (key == 'p') selectSerialPort();
    if (key == '$') port.write("$$\n");
  if (!streaming && key == 'g') {
    gcode = null; i = 0;
    File file = null; 
    println("Loading file...");
    selectInput("Select a file to process:", "fileSelected", file);
  if (key == 'x') streaming = false;

void fileSelected(File selection) {
  if (selection == null) {
    println("Window was closed or the user hit cancel.");
  } else {
    println("User selected " + selection.getAbsolutePath());
    gcode = loadStrings(selection.getAbsolutePath());
    if (gcode == null) return;
    streaming = true;

void stream()
  if (!streaming) return;
  while (true) {
    if (i == gcode.length) {
      streaming = false;
    if (gcode[i].trim().length() == 0) i++;
    else break;
  port.write(gcode[i] + '\n');

void serialEvent(Serial p)
  String s = p.readStringUntil('\n');
  if (s.trim().startsWith("ok")) stream();
  if (s.trim().startsWith("error")) stream(); // XXX: really?




p:select serial port
1:set speed to 0.001 inches
2:set speed to 0.010 inches
3:set speed to 0.100 inches
$:display grbl settings
h:go home
0:set home to the current location
g:stream a g-code file
x:stop streaming g-code




Now type p

select com_port

Now type g to select g-code file by browsing your file and press enter




Congratulations you made an awesome project.

If you face any problem then comment below…..


Thank you so much for watching…..


Follow me on



  1. thank you so much for your help to do this. but i got a problem that while executting gcode processing shows an error that M18 (drives off)
    Command not recognized : M18. please help me to overcome this error. Thankyou.

  2. i want to do this project using atmega32(not using ardiuno) and I have to write the code using atmel studio 7 in C language..Can u help me with the code?? what changes I have to do???

  3. I don’t even understand how I finished up here, but I thought
    this post used to be great. I do not realize who you might be however certainly you are
    going to a famous blogger in case you are not already.

  4. Hello there! Do you know if they make any plugins to assist with
    Search Engine Optimization? I’m trying to get my blog
    to rank for some targeted keywords but I’m not seeing very good success.
    If you know of any please share. Thank you!

  5. Hey there! This is kind of off topic but I need some guidance from an established blog.
    Is it very difficult to set up your own blog?
    I’m not very techincal but I can figure things out
    pretty fast. I’m thinking about creating my own but I’m not sure
    where to start. Do you have any points or suggestions?


  6. I was curious if you ever thought of changing the page layout of your site?
    Its very well written; I love what youve
    got to say. But maybe you could a little more in the way of content so people could connect with
    it better. Youve got an awful lot of text for only having one or two pictures.
    Maybe you could space it out better?

  7. certainly like your web-site however you have to check the spelling on quite a few of your posts.
    Many of them are rife with spelling problems and I
    in finding it very bothersome to inform the reality
    however I’ll certainly come again again.

  8. I will right away take hold of your rss feed as I can not find your email subscription link or newsletter service.
    Do you’ve any? Kindly allow me recognise in order that I may
    just subscribe. Thanks.

  9. You really make it seem so easy with your presentation but I find this topic
    to be really something that I think I would never understand.
    It seems too complicated and very broad for me. I am looking forward for your next post, I’ll try
    to get the hang of it!

  10. Hi there! I just wanted to ask if you ever have any trouble with hackers?
    My last blog (wordpress) was hacked and I ended up losing months of hard work due
    to no backup. Do you have any methods to prevent hackers?

  11. You can definitely see your skills in the article you write.

    The world hopes for even more passionate writers such as you who are not afraid to mention how they believe.
    All the time follow your heart.

  12. Hello there! This blog post could not be written any better!

    Going through this post reminds me of my
    previous roommate! He continually kept preaching about this.
    I am going to forward this post to him. Fairly
    certain he’ll have a great read. Thanks for sharing!

Leave a reply

Please enter your comment!
Please enter your name here

Related Articles