Tinkercad - DC Motor Speed Control




In this article, we will interface a DC motor with an Arduino UNO using TinkerCAD software. Simulating a circuit before implementing the circuit manually helps to visualize the connections and it also provides the output under different conditions and constraints which would help to cross-check the output of the circuit implemented manually.

What is Tinkercad?

Tinkercad is a free, easy-to-use app for 3D design, electronics, and coding. It's used by teachers, kids, hobbyists, and designers to imagine, design, and make anything! Since it became available in 2011 it has become a popular platform for creating models for 3D printing, electronics simulation, coding as well as an entry-level introduction to constructive solid geometry in the schools.

Why we are using it?

We are using Tinkercad for saving money, learning & microcontroller coding. In this project, we have used the circuits facility of Tinkercad for simulating our project DC Motor Speed Control Using Arduino.

The DC motor speed in general is directly proportional to the supply voltage, so if reduce the voltage from 9 volts to 4.5 volts then our speed becomes half of what it originally had. But in practice, for changing the speed of a dc motor we cannot go on changing the supply voltage all the time. The speed controller PWM for a DC motor works by varying the average voltage supplied to the motor.

A list of components required to implement the circuit both manually and using TinkerCAD are given below

Hardware Requirements:

  1. Arduino - We can use any Arduino development board for this project whether it is UNO, MEGA, NANO etc. 
  2. Motor -  We have to use a DC motor for this project to see clear variations.
  3. Breadboard & wires - Use any normal breadboard & Jumper wires, Male-to-Female & Male-to-Male.
  4. Resistor - We will use a 220-ohm resistor in this project.
  5. Diode - We are going to use a diode to prevent reverse current otherwise it will going to damage our circuit. 
  6. Transistor - We want an NPN BC-547 transistor in this project

Software Requirements:

  1. Tinkercad: Click Me
  2. Arduino IDE: Click Me

       Note: Arduino IDE is optional you can code in Tinkercad also.

Code Description:

Let us learn the code to control the speed of the DC motor.

const int Motor_pin = 3;

The Motor pin is set as 3 since we have used the 3rd pin of the PWM signal as the input to the DC motor.

int flag,Speed;

We initialize two integer type variables viz., flag and speed.

void setup()
{
 Serial.begin(9600);
 pinMode(Motor_pin, OUTPUT);
 Serial.println("Enter a value from 50 to 225"); // Why not from one ?, 
 Because motor will not get enough current below 50 so the motor will not 
 move.  
}

void setup is a function and in this, we initiated the serial communication at the baud rate of 9600. Now, the motor pin is defined as the output, and we print the statement Enter value from 50 to 225. If the PWM value is less than 50 then the motor will not rotate due to less current.

void loop() 
{
  if (Serial.available()>0)                   
  {
    Speed=Serial.parseInt();                 
    Serial Buffer.
    flag=0;
  }
}

Here, we check if the data is available in the serial port or not. If it is available then the data will be parsed into the integer format and will be stored in the speed variable. The Flag variable will be set to zero.

if (Speed>=50 && Speed<=255)                
  {
    analogWrite(Motor_pin,Speed);           
    if (flag==0)
    {
      Serial.print("Current speed is ");
      Serial.print(Speed);
      Serial.println(" PWM");
      flag=1;
    }
  }
}

If the speed variable carries a value that lies between 50 and 255 then the next line of the code will be executed. Here analogWrite function is an output type function that will give output to the Motor_pin i.e., PIN number 3. It will generate a PWM signal with a duty cycle that we have given to the speed variable. Now, we check the condition-if flag variable is zero or not. If it is zero, then we will print the speed of the motor and set back the flag variable to zero.

Complete Code:

const int Motor_pin = 3;
int flag,Speed;

void setup()
{
 Serial.begin(9600);
 pinMode(Motor_pin, OUTPUT);
 Serial.println("Enter value from 50 to 225"); // Why not from one ?, Because motor will not get enough current below 50 so motor will not move.  
}

void loop() 
{
  if (Serial.available()>0)                   // Checking if data is present in serial buffer or not.
  {
    Speed=Serial.parseInt();                  // Reading data from Serial Buffer.
    flag=0;
  }

  if (Speed>=50 && Speed<=255)                
  {
    analogWrite(Motor_pin,Speed);             // Sending the PWM signal to arduino pin 3.

    if (flag==0)
    {
      Serial.print("Current speed is ");
      Serial.print(Speed);
      Serial.println(" PWM");
      flag=1;
    }
  }
}

Comments

Popular posts from this blog

Home Automation Using AWS | MQTT | NodeMCU