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

2 DC மோட்டார்களை  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 உடன் 5V 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. Node MCU உடன் Power ஐ இணைக்க வேண்டும்.
  7. Arduino program ஐ சரி பார்க்க வேண்டும்.
  8. மின்சுற்றை சரி பார்க்க வேண்டும்.
  9. 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
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);
  
  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;
  }
  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");
  }
  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("</html>");
  delay(1);
  Serial.println("Client disonnected");
  Serial.println("");
}

Usage

  1. நேரோட்ட மின்சார இயக்கி(Drive DC motors)
  2. படிநிலை இயக்கி(Drive Stepping motors)
  3. ரோபாட்டிக்ஸ்(In Robotics)

Projects

  1. திவா ரோபோட் (Diwa Robot)

Arduino Tutorials – பாடம் 31 – Micro Metal Gear Motor with Encoder

Arduino MEGA2560வை பயன்படுத்தி 2 Encoder மோட்டார்களை துல்லியமாக கட்டுப்படுத்துவது.

Required Components

  1. Arduino MEGA2560 -1 no
  2. Motor control shield(L293D) -1 no
  3. Micro Metal Gear Motor with Encoder -2 no
  4. Motor Wheel -2 no
  5. Bread Board -1 no
  6. Jumper Wires(Male to Male) -11 no
  7. Voltage Converter(5V-3.3V) -1 no
  8. 5V Battery -1 no
  9. USB cable -1 no

Steps

  1. நாம் பயன்படுத்தும் உபகரணங்கள் சரியாக வேலை செய்கிறதா என்பதை உறுதி செய்து கொள்ளவும்.
  2. Motor control shield(L293D) உடன் +5V battery இணைக்க வேண்டும்.
  3. +5V பேட்டரி இணைப்புகளை சரியாகவும் கவனமாகவும் இணைக்க வேண்டும்.
  4. Motor control shield(L293D) M4ஐ முதலாவது மோட்டார் M1, M2 உடனும், Motor control shield(L293D) M3ஐ இரண்டாவது மோட்டார் M1, M2 உடனும் இணைக்க வேண்டும்.
  5. Arduino 5V, gnd ஐ voltage converter V IN,gnd உடன் கவனமாக இணைக்க வேண்டும்.
  6. voltage converter V OUT,gnd ஐ முதலாவது மோட்டார் VCC, gnd உடனும், இரண்டாவது மோட்டார் VCC, gnd உடனும் கவனமாக இணைக்க வேண்டும்.
  7. முதலாவது மோட்டார் C1,C2 பின்களை Arduino MEGA2560 18,19 பின்களுடனும், இரண்டாவது மோட்டார் C1,C2 பின்களை Arduino MEGA2560 20,21 பின்களுடனும் இணைக்க வேண்டும்.
  8. Arduino program ஐ சரி பார்க்க வேண்டும்.
  9. மின்சுற்றை சரி பார்க்க வேண்டும்.
  10. Arduino program ஐ ரன் செய்ய வேண்டும்.

Arduino Program

#include <AFMotor.h>
#include <Encoder.h>
AF_DCMotor motor1(4);
AF_DCMotor motor2(3);
Encoder myEnc1(21,20);
Encoder myEnc2(18,19);
long oldPosition1  = -999;
long oldPosition2  = -999;
long m1Pos = 0;
long m1Dir = 0;
long m2Pos = 0;
long m2Dir = 0;
long md1=2000;
long md2=2000;

void setup()
{
  Serial.begin(9600);
  Serial.println("Motor test!");
  
  motor1.setSpeed(200);
  motor2.setSpeed(200);
  motor1.run(RELEASE);
  motor2.run(RELEASE);
  motor1Move(md1,0);
  motor2Move(md2,0);
}

void loop()
{
  checkMotor1();
  checkMotor2();
  delay(5);
}

void motor1Move(int d1,int d2)
{
  m1Pos=d1;
  m1Dir = d2;
  if (d2==0)
  {
    motor1.run(FORWARD);
  }
  else if (d2==1)
  {
    motor1.run(BACKWARD);
  }
}

void motor2Move(int d1,int d2)
{
  m2Pos=d1;
  m2Dir = d2;
  if (d2==0)
  {
    motor2.run(FORWARD);
  }
  else if (d2==1)
  {
    motor2.run(BACKWARD);
  }
}

void checkMotor1()
{
  long newPosition1 = myEnc1.read();
  if (m1Dir==0)
  {
    if ( newPosition1>m1Pos)
    {
      m1Pos=0;
      motor1.run(RELEASE);
      myEnc1.write(0);
      motor1Move(md1,1);
    }
  }
  else
  {
    if ( abs(newPosition1)>m1Pos)
    {
      m1Pos=0;
      motor1.run(RELEASE);
      myEnc1.write(0);
      
      motor1Move(md1,0);
    }
  }
}

void checkMotor2()
{
  long newPosition2 = myEnc2.read();
  if (m2Dir==0)
  {
    if ( newPosition2>m2Pos)
    {
      m2Pos=0;
      motor2.run(RELEASE);
      myEnc2.write(0);
      motor2Move(md2,1);
    }
  }
  else
  {
    if ( abs(newPosition2)>m2Pos)
    {
      m2Pos=0;
      motor2.run(RELEASE);
      myEnc2.write(0);
      motor2Move(md2,0);
    }
  }
}

Arduino Tutorials – பாடம் 30 – Sharp Distance IR Sensor Module (2Y0A02 F 5x) using ARDUINO UNO

ஒரு குறிப்பிட்ட பொருளின் தொலைவைக் கண்டறிவது அதன் அளவெல்லை (20-150) cm.

Required Components

  1. Arduino Uno Board -1 no
  2. Sharp IR 2Y0A02 F 5x sensor -1 no
  3. Data Cable -1 no
  4. Jumper wires -3 no

Circuit

Steps

  1. நாம் பயன்படுத்தும் உபகரணங்கள் சரியாக வேலை செய்கிறதா என்பதை உறுதி செய்து கொள்ளவும்.
  2. Sharp IR sensorல் உள்ள SDA மற்றும் SCL பின்களை Arduino வில் உள்ள SDA மற்றும் SCL பின்களுடன் இணைக்க வேண்டும்.
  3. Arduino Uno Boardன் +5V மற்றும் ground சப்ளையை Sharp IR sensor உடன் இணைக்க வேண்டும்.
  4. Sharp IR sensor டேட்டா பின்னை Arduino Uno Board A0 pin உடன் இணைக்க வேண்டும்.
  5. Arduino program ஐ சரி பார்க்க வேண்டும்.
  6. மின்சுற்றை சரி பார்க்க வேண்டும்.
  7. Arduino program ஐ ரன் செய்ய வேண்டும்.

Arduino Program

#include <SharpIR.h>
#define ir A0
#define model 20150
SharpIR SharpIR(ir, model);

void setup() 
{
  Serial.begin(9600);
}

void loop() 
{
  delay(2000);   
  unsigned long pepe1=millis();
  int dis=SharpIR.distance();  
  Serial.print("Mean distance: ");  
  Serial.println(dis);
  
  unsigned long pepe2=millis()-pepe1;  
  Serial.print("Time taken (ms): ");
  Serial.println(pepe2);
}  

Usage

  1. Touch-less switch (Sanitary equipment, Control of illumination, etc.).
  2. ஆற்றல் சேமிப்பிற்கான Sensor (Sensor for energy saving e.g. ATM, Copier, Laptop computer, LCD monitor).
  3. பொழுதுபோக்கு கருவி (Amusement equipment e.g. Arcade game machine).

Arduino Tutorials – பாடம் 28 – Node MCU

LEDஇன் ஒளியை Node MCU உதவியுடன் கட்டுப்படுத்துவது. 

Required Components

  1. Node MCU Board -1 no
  2. Bread Board -1 no
  3. Data Cable -1 no
  4. LED -1 no

Circuit

Steps

  1. நாம் பயன்படுத்தும் உபகரணங்கள் சரியாக வேலை செய்கிறதா என்பதை உறுதி செய்து கொள்ளவும்.
  2. Node MCU Boardஐ Bread Board உடன் இணைக்க வேண்டும்.
  3. LED இன் Anode (+) pin ஐ Node MCU D7 (13) உடன் இணைக்க வேண்டும்.
  4. LED இன் அடுத்த இணைப்பை ground உடன் இணைக்க வேண்டும்.
  5. Arduino program ஐ சரி பார்க்க வேண்டும்.
  6. மின்சுற்றை சரி பார்க்க வேண்டும்.
  7. Arduino program ஐ ரன் செய்ய வேண்டும்.

Arduino Program

#include <ESP8266WiFi.h>
const char* ssid = "******";
const char* password = "********";
int ledPin = 13; // GPIO13
WiFiServer server(80);

void setup() 
{
  Serial.begin(115200);
  delay(10);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  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 = LOW;
  if (request.indexOf("/LED=ON") != -1)  {
    digitalWrite(ledPin, HIGH);
    value = HIGH;
  }
  if (request.indexOf("/LED=OFF") != -1)  {
    digitalWrite(ledPin, LOW);
    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("Led pin is now: ");
  
  if(value == HIGH) {
    client.print("On");
  } 
  else {
    client.print("Off");
  }
  client.println("<br><br>");
  client.println("<a href=\"/LED=ON\"\"><button>Turn On </button></a>");
  client.println("<a href=\"/LED=OFF\"\"><button>Turn Off </button></a><br/>");
  client.println("</html>");
  delay(1);
  Serial.println("Client disonnected");
  Serial.println("");
}

Usage

  1. Internet of Things சாதனத்தின் மூலப்படிமம் (Prototyping of Internet of Things devices).
  2. குறைந்த ஆற்றல் மின்கலம் இயக்குதல் (Low power battery operated applications).
  3. வலையமைப்பு (Network).

Arduino Tutorials – பாடம் 25 – L298N Motor Driver Module using Arduino UNO

L298N Motor Driver ஐ பயன்படுத்தி 2 DC மோட்டார்களை  கட்டுப்படுத்துவது.

Required Components

  1. L298N Motor Driver Module -1 no
  2. Arduino UNO -1 no
  3. DC Motor(gear) -2 no
  4. 12V Battery -1 no
  5. Data Cable -1 no
  6. Connecting Wires -4 no

Circuit

Steps

  1. நாம் பயன்படுத்தும் உபகரணங்கள் சரியாக வேலை செய்கிறதா என்பதை உறுதி செய்து கொள்ளவும்.
  2. மோட்டார் Driver போர்டு உடன் +12V battery இணைக்க வேண்டும்.
  3. +12V பேட்டரி இணைப்புகளை சரியாகவும் கவனமாகவும் இணைக்க வேண்டும்.
  4. மோட்டார் Driver போர்டு ENA, IN1, IN2, IN3, IN4, ENB பின்களை Arduino பின்களான 4,2,3,5,6,7 உடன் இணைக்க வேண்டும்.
  5. மோட்டார் Driver போர்டு OUTPUT பின்களை DC மோட்டார் பின்களுடன் இணைக்க வேண்டும்.
  6. மோட்டார் Driver போர்டு gnd ஐ Arduino UNO board gnd உடன் இணைக்க வேண்டும்.
  7. Arduino program ஐ சரி பார்க்க வேண்டும்.
  8. மின்சுற்றை சரி பார்க்க வேண்டும்.
  9. Arduino program ஐ ரன் செய்ய வேண்டும்.

Arduino Program

int motor1pin1 = 2;
int motor1pin2 = 3;
int enPin1 = 4;

int motor2pin1 = 5;
int motor2pin2 = 6;
int enPin2 = 7;


void setup() 
{
  pinMode(motor1pin1, OUTPUT);
  pinMode(motor1pin2, OUTPUT);
  pinMode(enPin1, OUTPUT);
  digitalWrite(enPin1, HIGH);
  
  pinMode(motor2pin1, OUTPUT);
  pinMode(motor2pin2, OUTPUT);
  pinMode(enPin2, OUTPUT);
  digitalWrite(enPin2, HIGH);
}

void loop() 
{
  digitalWrite(motor1pin1, HIGH);
  digitalWrite(motor1pin2, LOW);
  digitalWrite(motor2pin1, HIGH);
  digitalWrite(motor2pin2, LOW);
  delay(1000);
  
  digitalWrite(motor1pin1, LOW);
  digitalWrite(motor1pin2, HIGH);
  digitalWrite(motor2pin1, LOW);
  digitalWrite(motor2pin2, HIGH);
  delay(1000);
}

Usage

  1. நேரோட்ட மின்சார இயக்கி(Drive DC motors)
  2. படிநிலை இயக்கி(Drive Stepping motors)
  3. ரோபாட்டிக்ஸ்(In Robotics)

Arduino Tutorials – பாடம் 26 – Accelerometer sensor with servo motor control using Arduino UNO

Accelerometer sensor உடன் இணைக்க பட்ட Servo மோட்டாரை Arduino mega 2560 உதவியுடன் கட்டுப்படுத்துவது. 

Required Components

  1. Accelerometer sensor (MPU 6050) -1 no
  2. Arduino UNO board -1 no
  3. Jumper cable -4 no
  4. Servo motor -1 no

Circuit

Steps

  1. நாம் பயன்படுத்தும் உபகரணங்கள் சரியாக வேலை செய்கிறதா என்பதை உறுதி செய்து கொள்ளவும்.
  2. Accelerometer sensorல் உள்ள SDA மற்றும் SCL பின்களை Arduino வில் உள்ள SDA மற்றும் SCL பின்களுடன் இணைக்க வேண்டும்.
  3. Arduinoன் +5V மற்றும் ground சப்ளையை servo மோட்டார் மற்றும் Accelerometer sensor உடன் இணைக்க வேண்டும்.
  4. Servo மோட்டார் மற்றும் Accelerometer Sensor ஐ Bread board உடன் இணைக்க வேண்டும்.
  5. Servo மோட்டார் டேட்டா பின்னை Arduino mega 2560 வின் 2 வது pin உடன் இணைக்க வேண்டும்.
  6. Arduino program ஐ சரி பார்க்க வேண்டும்.
  7. மின்சுற்றை சரி பார்க்க வேண்டும்.
  8. Arduino program ஐ ரன் செய்ய வேண்டும்.

Arduino Program

#include <Wire.h>
#include <MPU6050.h>
#include <Servo.h>   
Servo sg90;          
int servo_pin = 2;
MPU6050 sensor ;
int16_t ax, ay, az ;
int16_t gx, gy, gz ;

void setup ()
{ 
  sg90.attach ( servo_pin );
  Wire.begin ( );
  Serial.begin  (9600); 
  Serial.println  ( "Initializing the sensor" ); 
  
  sensor.initialize ( ); 
  Serial.println (sensor.testConnection ( ) ? "Successfully Connected" : "Connection failed"); 
  delay (1000); 
  Serial.println ( "Taking Values from the sensor" );
  delay (1000);
}

void loop () 
{ 
  sensor.getMotion6 (&ax, &ay, &az, &gx, &gy, &gz);
  ax = map (ax, -17000, 17000, 0, 180) ;
  Serial.println (ax);
  sg90.write (ax); 
  delay (200);
}

Usage

  1. அலைபேசி (Mobile phones).
  2. ட்ரோன் நிழற்படக்கருவி உறுதிப்படுத்தல் (Drone camera stabilization).
  3. ரோட்டேட்டர் இயந்திரத்தில் உள்ள தவறுகளைக் கண்டறிய (To detect faults in rotator machine).
  4. இலக்கமுறை நிழற்படக்கருவியின் திரையில் செங்குத்தான நிலையில் காட்சி படிமம் காண (To display images in an upright position on screens of digital cameras).

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 – பாடம் 23- L293D Motor Driver Control Shield with Arduino MEGA 2560

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

Required Components

  1. L293D Motor Driver Control -1 no
  2. Arduino MEGA 2560 Board -1 no
  3. 5V DC Motors -2 no
  4. Servo -2 no
  5. LED -2 no
  6. 9V Battery -1 no
  7. Bluetooth -1 no
  8. USB cable -1 no
  9. Jumper Wires -10 no

Circuit

Steps

  1. நாம் பயன்படுத்தும் உபகரணங்கள் சரியாக வேலை செய்கிறதா என்பதை உறுதி செய்து கொள்ளவும்.
  2. Motor control shield(L293D) உடன் +5V battery இணைக்க வேண்டும்.
  3. +5V பேட்டரி இணைப்புகளை சரியாகவும் கவனமாகவும் இணைக்க வேண்டும்.
  4. Motor control shield(L293D) M3,M4 ஐ 2 DC மோட்டார்களுடன் இணைக்க வேண்டும்.
  5. Motor control shield(L293D) Servo1,Servo2 ஐ 2 Servo மோட்டார்களுடன் இணைக்க வேண்டும்.
  6. 2 LED Cathodes(+) & Anode (-) பின்களை Arduino MEGA 2560 Board 50,52 பின்கள் & gnd உடன் இணைக்க வேண்டும்.
  7. Bluetooth VCC & gnd ஐ Arduino MEGA 2560 Board 5V & gnd உடன் இணைக்க வேண்டும்.
  8. Bluetooth RXD,TXD ஐ Arduino MEGA 2560 Board TXD,RXD உடன் முறையே இணைக்க வேண்டும்.
  9. Arduino MEGA 2560 Board உடன் +5V battery இணைக்க வேண்டும்.
  10. Arduino program ஐ சரி பார்க்க வேண்டும்.
  11. மின்சுற்றை சரி பார்க்க வேண்டும்.
  12. Arduino program ஐ ரன் செய்ய வேண்டும்.

Arduino Program

#include <AFMotor.h>
#include <Servo.h>
AF_DCMotor motor1(3);
AF_DCMotor motor2(4);
Servo servo1;
Servo servo2;
Servo servo3;
int pos1=20;
int pos1min=50;
int pos1max=110;
int pos2=90;
int pos2min=110;
int pos2max=170;
int pos3=80;
int pos3min=50;
int pos3max=110;
int i=0;
int delaytime=10;
int led1 = 50;
int led2 = 52;
String inputString = "";
boolean stringComplete = false;

void setup() 
{
  Serial1.begin(9600);
  motor1.setSpeed(200);
  motor2.setSpeed(200);
  motor1.run(RELEASE);
  motor2.run(RELEASE);
  servo1.attach(9);
  servo2.attach(10);
  servo3.attach(48);
  servo1.write(pos1);
  servo2.write(pos2);
  servo3.write(pos3);
  pinMode(led1,OUTPUT);
  pinMode(led2,OUTPUT);
  ledsOn();
}

void loop()
{
  ledsOn();
  serialEvent();
  if (stringComplete)
  {
    processCmd(inputString);
    inputString = "";
    stringComplete = false;
  }
}

void processCmd(String st1)
{
  st1.remove(st1.length());
  String cmd = st1.substring(0,1);
  st1="";
  if (cmd == "f")
  {
    motorForward();
  }
  else if (cmd == "b")
  {
    motorBackward();
  }
  else if (cmd == "r")
  {
    motorRight();
  }
  else if (cmd == "l")
  {
    motorLeft();
  }
  else if(cmd == "s")
  {
    motorStop();
  }
  else if(cmd == "1")
  {
    servoAction1();
  }
  else if(cmd == "2")
  {
    servoAction2();
  }
  else if (cmd=="o")
  {
    eyesBlink();
  }
}

void serialEvent()
{
  while (Serial1.available())
  {
    char inChar = (char)Serial1.read();
    inputString += inChar;
    if (inChar == '$')
    {
      stringComplete = true;
    }
  }
}
for(int i=0;i<5;i++)
{
  moveHandServoMotors(1);
}
delay(2000);
for(int i=0;i<5;i++)
{
  moveHandServoMotors(0);
}
delay(2000);


void motorForward()
{
  motor1.run(FORWARD);
  motor2.run(FORWARD);
  motor1.setSpeed(255);
  motor2.setSpeed(255);
}

void motorBackward()
{
  motor1.run(BACKWARD);
  motor2.run(BACKWARD);
  motor1.setSpeed(255);
  motor2.setSpeed(255);
}

void motorLeft()
{
  motor1.run(BACKWARD);
  motor2.run(FORWARD);
  motor1.setSpeed(255);
  motor2.setSpeed(255);
}

void motorRight()
{
  motor1.run(FORWARD);
  motor2.run(BACKWARD);
  motor1.setSpeed(255);
  motor2.setSpeed(255);
}

void motorStop()
{
  motor1.run(RELEASE);
  motor2.run(RELEASE);
}

void ledsOn()
{
  digitalWrite(led1,HIGH);
  digitalWrite(led2,HIGH);
}

void ledsOff()
{
  digitalWrite(led1,LOW);
  digitalWrite(led2,LOW);
}

void eyesBlink()
{
  for(int i=0;i<8;i++)
  {
    ledsOn();
    delay(250);
    ledsOff();
    delay(250);
  }
}

void servoAction1()
{
  for(int i=0;i<5;i++)
  {
    moveHandServoMotors(0);
  }
}

void servoAction2()
{
  for(int i=0;i<5;i++)
  {
    moveHandServoMotors(1);
  }
}

void moveHeadServoMotor(int tp)
{
  if (tp==0)
  {
    servo3.write(pos3min);
    delay(1000);
    servo3.write(pos3max);
    delay(3000);
  }
  if (tp==1)
  {
    for(int i=0;i<60;i++)
    {
      servo3.write(pos3min+i);
      delay(delaytime);
    }
    delay(1000);
    for(int i=0;i<60;i++)
    {
      servo3.write(pos3max-i);
      delay(delaytime);
    }
    delay(3000);
  }
}

void moveHandServoMotors(int tp)
{
  if (tp==0)
  {
    servo1.write(pos1min);
    servo2.write(pos2min);
    servo3.write(pos3min);
    for(int i=0;i<60;i++)
    {
      servo1.write(pos1min+i);
      servo2.write(pos2min+i);
      servo3.write(pos3min+i);
      delay(delaytime);
    }
    delay(200);
    for(int i=0;i<60;i++)
    {
      servo1.write(pos1max-i);
      servo2.write(pos2max-i);
      servo3.write(pos3max-i);
      delay(delaytime);
    }
    delay(200);
  }
  else if (tp==1)
  {
    servo1.write(pos1min);
    servo2.write(pos2max);
    servo3.write(pos3min);
    for(int i=0;i<60;i++)
    {
      servo1.write(pos1min+i);
      servo2.write(pos2max-i);
      servo3.write(pos3min+i);
      delay(delaytime);
    }
    delay(200);
    for(int i=0;i<60;i++)
    {
      servo1.write(pos1max-i);
      servo2.write(pos2min+i);
      servo3.write(pos3max-i);
      delay(delaytime);
    }
    delay(200);
  }
}

Usage

  1. நேரோட்ட மின்சார இயக்கி(Drive DC motors)
  2. படிநிலை இயக்கி(Drive Stepping motors)
  3. ரோபாட்டிக்ஸ்(In Robotics)

Projects

  1. திவா ரோபோட்(DIWA Robot)

Arduino Tutorials – பாடம் 22 – Micro Metal Gear Motor with Encoder

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

Required Components

  1. Arduino MEGA2560 -1 no
  2. Motor control shield(L293D) -1 no
  3. Micro Metal Gear Motor with Encoder -1 no
  4. Motor Wheel -1 no
  5. Bread Board -1 no
  6. Jumper Wires(Male to Male) -11 no
  7. Voltage Converter(5V-3.3V) -1 no
  8. 5V Battery -1 no
  9. USB cable -1 no

Steps

  1. நாம் பயன்படுத்தும் உபகரணங்கள் சரியாக வேலை செய்கிறதா என்பதை உறுதி செய்து கொள்ளவும்.
  2. Motor control shield(L293D) உடன் +5V battery இணைக்க வேண்டும்.
  3. +5V பேட்டரி இணைப்புகளை சரியாகவும் கவனமாகவும் இணைக்க வேண்டும்.
  4. Motor control shield(L293D) M3ஐ மோட்டார் M1,M2உடன் இணைக்க வேண்டும்.
  5. Arduino 5V, gnd ஐ voltage converter V IN,gnd உடன் கவனமாக இணைக்க வேண்டும்.
  6. voltage converter V OUT,gnd ஐ மோட்டார் VCC, gnd உடன் கவனமாக இணைக்க வேண்டும்.
  7. மோட்டார் C1,C2 பின்களை Arduino MEGA2560 18,19 பின்களுடன் இணைக்க வேண்டும்.
  8. Arduino program ஐ சரி பார்க்க வேண்டும்.
  9. மின்சுற்றை சரி பார்க்க வேண்டும்.
  10. Arduino program ஐ ரன் செய்ய வேண்டும்.

Arduino Program

#include <AFMotor.h>
#include <Encoder.h>
AF_DCMotor motor1(4);
Encoder myEnc1(18,19);
long oldPosition1  = -999;
long m1Pos = 0;
long m1Dir = 0;
long md1=2000;


void setup()
{
  Serial.begin(9600);
  Serial.println("Motor test!");
  motor1.setSpeed(200);
  motor1.run(RELEASE);
  motor1Move(md1,0);
}

void loop()
{
  checkMotor1();
  delay(5);
}

void motor1Move(int d1,int d2)
{
  m1Pos=d1;
  m1Dir = d2;
  if (d2==0)
  {
    motor1.run(FORWARD);
  }
  else if (d2==1)
  {
    motor1.run(BACKWARD);
  }
}


void checkMotor1()
{
  long newPosition1 = myEnc1.read();
  if (m1Dir==0)
  {
    if ( newPosition1>m1Pos)
    {
      m1Pos=0;
      motor1.run(RELEASE);
      myEnc1.write(0);
      motor1Move(md1,1);
    }
  }
  else
  {
    if ( abs(newPosition1)>m1Pos)
    {
      m1Pos=0;
      motor1.run(RELEASE);
      myEnc1.write(0);      
      motor1Move(md1,0);
    }
  }
}

Arduino Tutorials – பாடம் 21 – Stepper motor control Using Arduino UNO

Stepper மோட்டாரை Arduino UNO கொண்டு கட்டுப்படுத்துவது.

Required Components

  1. Stepper Motor (NEMA17) -1 no
  2. A4988 Stepper Driver -1 no
  3. 12V 2A Adapter -1 no
  4. Arduino Board UNO or MEGA -1 no
  5. Connecting wires -1 set

Circuit

Steps

  1. நாம் பயன்படுத்தும் உபகரணங்கள் சரியாக வேலை செய்கிறதா என்பதை உறுதி செய்து கொள்ளவும்.
  2. Stepper மோட்டார் Driver ஐ Arduino UNO உடன் இணைக்க வேண்டும்.
  3. Stepper மோட்டாரை Driver உடன் இணைக்க வேண்டும்.
  4. Stepper மோட்டார் உடன் வெளிப்புற power supply இணைக்க வேண்டும்.
  5. Arduino UNO பின்னான 3 &4 ஐ motor driver உடன் இணைக்க வேண்டும்.
  6. motor driver உடன் +5V மற்றும் Ground ஐ இணைக்க வேண்டும்.
  7. Arduino program ஐ சரி பார்க்க வேண்டும்.
  8. மின்சுற்றை சரி பார்க்க வேண்டும்.
  9. Arduino program ஐ ரன் செய்ய வேண்டும்.

Arduino Program

#include <Stepper.h>
const int stepPin = 3;
const int dirPin = 4;

void setup( )
{
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
}
void loop( )
{
  digitalWrite(dirPin,HIGH);
  for(int x = 0; x < 200; x++)
  {
    digitalWrite(stepPin,HIGH);
    delayMicroseconds(500);
    digitalWrite(stepPin,LOW);
    delayMicroseconds(500);
  }
  delay(1000);
  digitalWrite(dirPin,LOW);
  for(int x = 0; x < 400; x++)
  {
    digitalWrite(stepPin,HIGH);
    delayMicroseconds(500);
    digitalWrite(stepPin,LOW);
    delayMicroseconds(500);    
  }
  delay(1000); 
}

Usage

  1. பையகப்படுத்துதல்(Packaging)
  2. தொழில் தானியங்குமயம் (industry automation)
  3. கொணரிப்பட்டை (conveyer belt)

Projects

  1. ரோபோ கை (Robot arm)
  2. குப்பைத்தொட்டி(Dustbin)