Other Arduino Codes and Videos by Robojax

How to use YYNMOS-4 4ch MOSFET to control 5A to 20A DC Motor or LED light strip

How to use YYNMOS-4 4ch MOSFET to control 5A to 20A DC Motor or LED light strip

This tutorial shows you how to use the YYNMOS-4 4 Channel MOSFET Module to control intensity of LIGH or speed of 4 motors. Module is explained, Arduino code explained and testd.

Topic timing in the video

YYNMOS-4 Main module image

YNMOS-4: ready
Click on image to enlarge

YYNMOS-4 With Arduino 1

YNMOS-4: with Arduino 1
Click on image to enlarge

YYNMOS-4 With Arduino 2

YNMOS-4: with Arduino 2
Click on image to enlarge

YYNMOS-4 Arduino Wiring Close up

YNMOS-4: Arduino Wiring Close up
Click on image to enlarge

YYNMOS-4 Arduino Wiring with LED Strip

YNMOS-4: Arduino Wiring with LED Strip
Click on image to enlarge

YYNMOS-4 Arduino Wiring with DC Motors

YNMOS-4: Arduino Wiring with DC Motors
Click on image to enlarge

Components used in this module

  1. Robojax Crash Course on Arduino: Learn Arduino in 30 Minutes (code and video)
  2. Robojax Arduino Course on Udemy
  3. Get Early Access to my videos via Patreon

Arduino code for Sharp GP2Y0A51SK0F Distance Sensor


 /*

 * This is Arduio code to control 4 DC motor's speed or 4 LED light strip or other DC load
 * buy utilizing YYNMOS-4 4 channel mosfet module

We can control 4 DC Motors with voltage of 5V to 35V and 5A each.

 * Written by Ahmad Shamshiri on July 13, 2020
 * in Ajax, Ontario, Canada. www.robojax.com
 * 
 * 
 * Watch video instruction for this code: https://youtu.be/G9uHVcITHf8
 * 

If you found this tutorial helpful, please support me so I can continue creating 
content like this. You can support me on Patreon http://robojax.com/L/?id=63

or make donation using PayPal http://robojax.com/L/?id=64

 * This code has been download from Robojax.com
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

int pin1 = 3;//pwm
int pin2 = 5;//pwm
int pin3 = 6;//pwm
int pin4 = 9;//pwm
int ON = HIGH;
int OFF = LOW;
int motor[]={NULL,pin1, pin2, pin3, pin4};


void setup() {
  Serial.begin(9600);
  Serial.println("Robojax.com 4 DC Motor or LED");
  pinMode(motor[1], OUTPUT);
  pinMode(motor[2], OUTPUT);
  pinMode(motor[3], OUTPUT);
  pinMode(motor[4], OUTPUT);    

}

void loop() {
   motorON(1, 75);//run motor 1 at 75% speed
   delay(4000);//for 4 seconds

   motorON(4, 100);//run motor 4 at 100% speed (or 100% light intensity)
   delay(4000); //for 4 seconds

   stop(1);//stop motor 1
   delay(3000);//keep it stopped for 3 second

   stop(4);//stop motor 4 
   delay(3000);  //keep it stopped for 3 seconds 
   for(int i=0; i<=100; i++)
   {
     motorON(1,i); //change speed of motor 1  
     delay(100);
   }
  delay(3000);//keep running for 3 seconds
  stop(1);//stop motor 1
  delay(3000);//keep it stopped for 3 seconds
  
     for(int i=100; i>=0; i--)
   {
     motorON(1,i);  //change speed of motor 1    
     delay(100);
   }
   delay(3000); //keep it running for 3 seconds

    
   for(int i=0; i<=100; i++)
   {
     motorON(4,i);    
     delay(100);
   }
  delay(3000);//keep it at for 3 seconds
  
    for(int i=100; i>=0; i--)
   {
     motorON(4,i);    
     delay(100);
   }   
  
}// loop


/*
   motorON(int n, int sp)
 * @brief runs the specific motor n with speed sp
 * @param n, is integet from 1 to 4
 * @param sp, is speed in % from 0 to 100
 * @return does not return anything
 * Written by Ahmad Shamshiri
 * www.Robojax.com code July 13, 2020 in Ajax, Ontario, Canada
 */
void motorON(int n, int sp)
{
  if(n >=1 && n <=4)
  {
  int speed=map(sp, 0, 100, 0, 255);
  analogWrite(motor[n],speed);
  Serial.print("Load ");
  Serial.print(n);
  Serial.print(" @");
  Serial.print(sp);
  Serial.println("%");
  
  }else{
    Serial.println("Motor/load number should be between 1 and 4");
    while(1);// stop forever
  }
    
}//motorON(int n)


/*
   stop(int n)
 * @brief stops the specific motr
 * @param n, is integet from 1 to 4
 * @return does not return anything
 * Written by Ahmad Shamshiri
 * www.Robojax.com code July 13, 2020 in Ajax, Ontario, Canada
 */
void stop(int n)
{
  if(n >=1 && n <=4)
  {

  digitalWrite(motor[n], LOW);
  Serial.print("Load ");
  Serial.print(n);
  Serial.println(" Stopped");

  }else{
    Serial.println("Motor/load number should be between 1 and 4");
    while(1);// stop forever
  }
    
}//stop(int n)
 				

If you found this tutorial helpful, please support me so I can continue creating content like this. support me via PayPal