Arduino Tutorials – பாடம் 24 – L298N Motor Driver with Node MCU

Arduino MEGA2560வை பயன்படுத்தி 2 DC மோட்டார்கள் மற்றும் 2 LED-களை ஒரே நேரத்தில் NodeMCU ஐ உபயோகப்படுத்தி கட்டுப்படுத்துவது.

Required Components

  1. Node MCU -1 no
  2. L298N Motor Driver -1 no
  3. 9V Battery -1 no
  4. 5V DC Motor -2 no
  5. Motor wheel -2 no
  6. Cable -1 no
  7. Jumper Wires -7 no

Circuit

Steps

  1. நாம் பயன்படுத்தும் உபகரணங்கள் சரியாக வேலை செய்கிறதா என்பதை உறுதி செய்து கொள்ளவும்.
  2. L298N Motor Driver உடன் 9V Battery ஐ கவனமாக இணைக்க வேண்டும்.
  3. L298N Motor Driver ENA, IN1, IN2, IN3, IN4, ENB பின்களை Node MCU D2, D0, D1, D7, D6, D5 உடன் இணைக்க வேண்டும்.
  4. L298N Motor Driver gnd உடன் Node MCU gnd ஐ இணைக்க வேண்டும்.
  5. L298N Motor Driver OUTPUT பின்களுடன் DC மோட்டார் OUTPUT பின்களை இணைக்க வேண்டும்.
  6. 2 LED Cathodes(+) & Anode (-) பின்களை Arduino MEGA 2560 Board D3, D4 பின்கள் & gnd உடன் இணைக்க வேண்டும்.
  7. Node MCU உடன் Power ஐ இணைக்க வேண்டும்.
  8. Arduino program ஐ சரி பார்க்க வேண்டும்.
  9. மின்சுற்றை சரி பார்க்க வேண்டும்.
  10. Arduino program ஐ ரன் செய்ய வேண்டும்.

Arduino Program

#include <ESP8266WiFi.h>
const char* ssid = "*****";
const char* password = "********";
int motor1pin1 = 16; //D0
int motor1pin2 = 5; //D1
int enPin1 = 4; //D2
int motor2pin1 = 13; //D7
int motor2pin2 = 12; //D6
int enPin2 = 14;//D5

int led1 = 0; //D3
int led2 = 2; //D4
WiFiServer server(80);

void setup() 
{
  Serial.begin(115200);
  delay(10);
  pinMode(motor1pin1, OUTPUT);
  pinMode(motor1pin2, OUTPUT);
  pinMode(enPin1, OUTPUT);
  digitalWrite(enPin1, HIGH);
  pinMode(motor2pin1, OUTPUT);
  pinMode(motor2pin2, OUTPUT);
  pinMode(enPin2, OUTPUT);
  digitalWrite(enPin2, HIGH);
  
  pinMode(led1,OUTPUT);
  pinMode(led2,OUTPUT);
  
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  server.begin();
  Serial.println("Server started");
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");
}

void loop() 
{
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();
  int value,value1 = LOW,value2 = LOW,value3 = LOW,value4 = LOW;
  if (request.indexOf("/MotorForward") != -1)
  {
    digitalWrite(motor1pin1, HIGH);
    digitalWrite(motor1pin2, LOW);
    digitalWrite(motor2pin1, HIGH);
    digitalWrite(motor2pin2, LOW);
    delay(1000);
    value1 = HIGH;
    value2 = LOW;
    value3 = HIGH;
    value4 = LOW;
  }
  if (request.indexOf("/MotorBackward") != -1)
  {
    digitalWrite(motor1pin1, LOW);
    digitalWrite(motor1pin2, HIGH);
    digitalWrite(motor2pin1, LOW);
    digitalWrite(motor2pin2, HIGH);
    delay(1000);
    value1 = LOW;
    value2 = HIGH;
    value3 = LOW;
    value4 = HIGH;
  }
  if (request.indexOf("/MotorLeft") != -1)
  {
    digitalWrite(motor1pin1, LOW);
    digitalWrite(motor1pin2, HIGH);
    digitalWrite(motor2pin1, HIGH);
    digitalWrite(motor2pin2, LOW);
    delay(1000);
    value1 = LOW;
    value2 = HIGH;
    value3 = HIGH;
    value4 = LOW;
  }
  if (request.indexOf("/MotorRight") != -1)
  {
    digitalWrite(motor1pin1, HIGH);
    digitalWrite(motor1pin2, LOW);
    digitalWrite(motor2pin1, LOW);
    digitalWrite(motor2pin2, HIGH);
    delay(1000);
    value1 = HIGH;
    value2 = LOW;
    value3 = LOW;
    value4 = HIGH;
  }
  if (request.indexOf("/MotorStop") != -1)
  {
    digitalWrite(motor1pin1, LOW);
    digitalWrite(motor1pin2, LOW);
    digitalWrite(motor2pin1, LOW);
    digitalWrite(motor2pin2, LOW);
    delay(1000);
    value1 = LOW;
    value2 = LOW;
    value3 = LOW;
    value4 = LOW;
  }
  
  if (request.indexOf("/LedOn") != -1)
  {
    digitalWrite(led1,HIGH);
    digitalWrite(led2,HIGH);
    delay(2000);
    value = HIGH;
  }
  
  if (request.indexOf("/LedOn") != -1)
  {
    digitalWrite(led1,LOW);
    digitalWrite(led2,LOW);
    delay(2000);
    value = LOW;
  }
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println(""); //  do not forget this one
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");
  client.print("motor is now: ");
  
  if(value1 == HIGH && value2 == LOW && value3 == HIGH && value4 == LOW ) {
    client.print("Forward");
  }
  else if(value1 == LOW && value2 == HIGH && value3 == LOW && value4 == HIGH  ) {
    client.print("Backward");
  }
  else if(value1 == LOW && value2 == HIGH && value3 == HIGH && value4 == LOW  ) {
    client.print("Left");
  }
  else if(value1 == HIGH && value2 == LOW && value3 == LOW && value4 == HIGH  ) {
    client.print("Right");
  }
  else if(value1 == LOW && value2 == LOW && value3 == LOW && value4 == LOW  ) {
    client.print("Stop");
  }
  else if( value = HIGH) {
    client.print("LedOn");
  }
  else if( value = LOW) {
    client.print("LedOff");
  }
  client.println("<br><br>");
  client.println("<a href=\"/MotorForward\"\"><button>Forward </button></a>");
  client.println("<a href=\"/MotorBackward\"\"><button>Backward </button></a><br />");
  client.println("<a href=\"/MotorLeft\"\"><button>Left </button></a>");
  client.println("<a href=\"/MotorRight\"\"><button>Right </button></a><br/>");
  client.println("<a href=\"/MotorStop\"\"><button>Stop </button></a>");
  client.println("<a href=\"/LedOn\"\"><button>LedOn </button></a>");
  client.println("<a href=\"/LedOff\"\"><button>LedOff </button></a>");
  client.println("</html>");
  delay(1);
  Serial.println("Client disonnected");
  Serial.println("");
}

Projects

  1. DIWA Robot

Arduino Tutorials – பாடம் 11 – DC motor control by Ultrasonic Sensor Using Arduino UNO

Ultrasonic sensor உடன் இணைக்கப்பட்ட DC மோட்டாரை Arduino UNO உதவியுடன் கட்டுப்படுத்துவது.

Required Components

  1. Ultrasonic sensor board -1 no
  2. Arduino Uno board -1 no
  3. DC Motor -1 no
  4. 12V Battery -1 no
  5. Data Cable -1 no
  6. Connecting Wires -8 no
  7. DC motor driver(L298N) -1 no

Circuit

Steps

  1. நாம் பயன்படுத்தும் உபகரணங்கள் சரியாக வேலை செய்கிறதா என்பதை உறுதி செய்து கொள்ளவும்.
  2. Ultrasonic sensorல் உள்ள ECHO மற்றும் TRIG பின்களை Arduino வில் உள்ள 9 மற்றும் 10 பின்களுடன் இணைக்க வேண்டும்.
  3. +5V மற்றும் ground சப்ளையை DC மோட்டார் மற்றும் Ultrasonic Sensor உடன் இணைக்க வேண்டும்.
  4. DC மோட்டார் மற்றும் Ultrasonic Sensor ஐ Bread board உடன் இணைக்க வேண்டும்.
  5. Resistor ஐ பயன்படுத்தி DC மோட்டாரை Bread boardல் இணைக்க வேண்டும்.
  6. Arduino UNO வின் 11 வது பின்னை DC மோட்டார் உடன் இணைக்க வேண்டும்.
  7. Arduino program ஐ சரி பார்க்க வேண்டும்.
  8. மின்சுற்றை சரி பார்க்க வேண்டும்.
  9. Arduino program ஐ ரன் செய்ய வேண்டும்.

Arduino Program

#define echopin 2
#define trigpin 3
long duration;
int distance;
int motorpin1 = 10;
int motorpin2 =11;
int enpin1 = 9;

void setup()
{
  pinMode(trigpin, OUTPUT);
  pinMode(echopin, INPUT);
  Serial.begin(9600);
  Serial.println("Ultrasonic Sensor HC-SR04 Test");
  Serial.println("with Arduino UNO R3");
  pinMode(motorpin1, OUTPUT);
  pinMode(motorpin2, OUTPUT);
  pinMode(enpin1, OUTPUT);
  analogWrite(enpin1,70);
}

void loop() 
{
  digitalWrite(trigpin,LOW);
  delay(2000);
  digitalWrite(trigpin,HIGH);
  delay(5000);
  digitalWrite(trigpin,LOW);
  
  duration = pulseIn(echopin,HIGH);
  distance = duration * 0.034 / 2;
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");
  
  if(distance > 20)
  {
    forward();
    delay(1000);
  }
  else if(distance <= 20)
  {
    stop();
    delay(1000);
  }
}

void stop ()
{
  digitalWrite(motorpin1,LOW);
  digitalWrite(motorpin2,LOW);
}

void forward()
{
  digitalWrite(motorpin1,HIGH);
  digitalWrite(motorpin2,LOW);
}

Usage

  1. ரோபோ வாகனங்கள்(Robot vehicles)
  2. பாதுகாப்பு வாகனம்(Defence vehicle)

Projects

  1. பந்து எடுக்கும் ரோபோ(Ball picking robot)

Arduino Tutorials – பாடம் 10 – DC Motor Control Using Arduino UNO

Arduino UNO வை பயன்படுத்தி DC மோட்டாரை கட்டுப்படுத்துவது.

Required Components

  1. DC motor -1 no
  2. L293D Driver sheild -1 no
  3. Arduino UNO -1 no
  4. Bread board -1 no
  5. Connecting wires -1 set

Circuit

Steps

  1. நாம் பயன்படுத்தும் உபகரணங்கள் சரியாக வேலை செய்கிறதா என்பதை உறுதி செய்து கொள்ளவும்.
  2. மோட்டார் டிரைவர் போர்டை Arduino உடன் இணைக்க வேண்டும்.
  3. மோட்டார் டிரைவர் போர்டு உடன் +12V battery இணைக்க வேண்டும்.
  4. +12V பேட்டரி இணைப்புகளை சரியாகவும் கவனமாகவும் இணைக்க வேண்டும்.
  5. Arduino பின்களான 8 ,9 ,10 ஐ மோட்டார் உடன் இணைக்க வேண்டும்.
  6. Arduino program ஐ சரி பார்க்க வேண்டும்.
  7. மின்சுற்றை சரி பார்க்க வேண்டும்.
  8. Arduino program ஐ ரன் செய்ய வேண்டும்.

Arduino Program

#include <AFMotor.h>
AF_DCMotor motor1(3);

void setup() 
{
  motor1.setSpeed(200);
  motor1.run(RELEASE);
}

void loop()
{
  motor1.run(FORWARD);
  motor1.setSpeed(255);
  delay(1000);
  motor1.run(BACKWARD);
  motor1.setSpeed(255);
  delay(1000);
}

Usage

  1. நகரும் ரோபோ சக்கரம்(Moving  wheel Robot)
  2. சுழலும் ரோபோ ஆயுதங்கள்(Rotating Robot Arms)
  3. பம்ப் தொடர்பான பயன்பாடுகள்(For pump related applications)