Introduction: Controlling DC Motors With the L298N Using CloudX Microcontroller

In this project we'll explain how to use our L298N H-bridge to increase and decrease speed of DC motor. The L298N H-bridge module can be used with motors that have a voltage of between 5 and 35V DC.

There is also an onboard 5V regulator, so if your supply voltage is up to 12V you can also source 5V from the board.
These L298 H-bridge dual motor controller modules are inexpensive and available HERE

Step 1: Components

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

you can online here

Step 2: Circuit Diagram

follow the circuit up

Step 3: Code

copy this code to your CloudX IDE

#include <CloudX/M633.h><br>#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;
      }
}
}