Controlling DC Motors using L298 (H-Bridge) with CloudX M633 CloudX

  • img
Project Details

In this tutorial we are gonna be interfacing a dc motor with CloudX

When current is passed through the DC motor, it spins continuously in one direction until the current stops and if the polarity is exchanged, the motor begins to move in opposite direction. DC motors have no polarity except they are specifically indicated by the manufacturer, meaning that you can switch the two wires over to reverse the direction of the motor.

 

L298N Motor Driver

The L298N Motor Driver Board is built around the L298 dual full-bridge driver, made by STMicroelectronics. With this motor driver you can control DC motors, stepper motors, relays and solenoids. It comes with two separate channels, called A and B, that you can use to drive 2 DC motors, or 1 stepper motor when combined.

The L298N is usually mounted on a (red) breakout board, which makes wiring a lot easier. The breakout board also includes a 78M05 5 V power regulator.

 

ELECTRONIC COMPONENTS:

  • CloudX M633
  • CloudX Softcard
  • V3 USB cable
  • L298N H-bridge
  • Breadboard
  • Jumper wires
  • DC motor
  • 10k resistor
  • 4* push Button

 

 

Circuit Diagram

CloudX M633

 

CODE

#include <CloudX\PWM.h>


signed char i , j;
bit flag;





setup(){
           //setup here
           
            for(i=1; i<5; i++){
                pinMode(i , INPUT);
            }
            PWM1_Init(5000);
            PWM2_Init(5000);
            PWM1_Start();
            PWM2_Start();
            PWM1_Duty(0);
            PWM2_Duty(0);
            i=j=0;

    
    
    
loop(){
           //Program here
             if( !readPin(1) )
             {
                 delayMs(200);
                 if(flag==0)
                 {
                 PWM1_Duty(i);
                 PWM2_Duty(0);
                 }
                 if(flag==1)
                 {
                 PWM2_Duty(j);
                 PWM1_Duty(0);
                 }
                 flag = ~ flag;
             }
             
            if( !readPin(2) )
            {
                delayMs(200);
                if(flag==1)
                {
                 //i -= 10;
                    i--;
                 if(i <= 0) i=0;
                 PWM1_Duty(i);
                 PWM2_Duty(0);
                }
                if(flag==0)
                {
                 //j -= 10;
                    j--;
                    if(j <= 0) j=0;
                    PWM2_Duty(j);
                    PWM1_Duty(0);
                }
            }
            if( !readPin(3) )
            {
                delayMs(200);
                if(flag==1)
                {
                 //i += 10;
                    i++;
                    if(i >= 100) i=100;
                 PWM1_Duty(i);
                 PWM2_Duty(0);
                }
                if(flag==0)
                {
                 //j += 10;
                    j++;
                    if(j>=100) j=100;
                 PWM2_Duty(j);
                 PWM1_Duty(0);
                }
            }
            if( !readPin(4) )
            {
               delayMs(200);
               PWM1_Duty(0);
               PWM2_Duty(0);
               i=0;
               j=0;
            }
}
}

 

 

Share this with friends