connection between Arduino Ethernet Shield and dc Motor

Hello everyone........

I am actually new with Arduino. I am trying to control DC Motr with Android Application.

I have connected dc motor with Ethernet shield with GND and pin 9 but when I switch on using app it dose not work. but when I change it with LED it works for me.

this is my code

#include <SPI.h>
#include <Ethernet.h>
#include<Servo.h>
#define htons(x) ( (((x)&0xFF)<<8) | (((x)>>8)&0xFF) )
//new #include<Servo.h>
// new Servo myServo
Servo myServo;

//light pin9
//fan pi22
//garage door pin24


// Set the MAC address
int pos=0;
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
//78-31-C1-C5-3D-C8
// Set the IP address
IPAddress ip(192, 168, 1, 14);

// Start a server at port 80 (http)
EthernetServer server(80);

void setup() {
  
  // Open serial communications
  Serial.begin(9600);

  // start the Ethernet connection and the server
  Ethernet.begin(mac, ip);
  server.begin();

  // Pin 22 - 24 output (leds)
  pinMode(9, OUTPUT);
  pinMode(5, OUTPUT);

  myServo.attach(30);
  //new myServo.attach(24);
 
}


void loop() {
  // Check if client connected
  EthernetClient client = server.available();
  
  if (client) { // If there is a client...
    boolean currentLineIsBlank = true;
    String buffer = ""; // A buffer for the GET request
    
    while (client.connected()) {

      if (client.available()) {
        char c = client.read();// Read the data of the client
        buffer += c; // Store the data in a buffer
        
        if (c == '\n' && currentLineIsBlank) {// if 2x new line ==> Request ended
         
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");
          client.println(); // Blank line ==> end response
          break;
        }
        if (c == '\n') { // if New line
          currentLineIsBlank = true;
          buffer = "";  // Clear buffer
        } 
        
        else if (c == '\r') { // If cariage return...
          
          
          
         
         if(buffer.indexOf("GET /?led2=1")>=0) { // If led2 = 1
            digitalWrite(9, HIGH); // led 2 > on
          }

           if(buffer.indexOf("GET /?led2=0")>=0) { // If led2 = 0
            digitalWrite(9, LOW); // led 2 > off
          }

            if(buffer.indexOf("GET /?led3=1")>=0) { // If led3 = 1 for light
            digitalWrite(5, HIGH); // led 3 > on
          }
        
          if(buffer.indexOf("GET /?led3=0")>=0) { // If led3 = 0
            digitalWrite(5, LOW); // led 3 > off
          }

            //new 

      if (buffer.indexOf("GET /?led1=1")>=0) {
            for (pos = 0; pos < 105; pos += 3) // goes from 0 degrees to 180 degrees
            { // in steps of 1 degree
              myServo.write(pos);              // tell servo to go to position in variable 'pos'
              delay(15);                       // waits 15ms for the servo to reach the position
            }
          }
          if (buffer.indexOf("GET /?led1=0")>=0) {
            for (pos = 105; pos >= 0; pos -= 3) // goes from 180 degrees to 0 degrees
            {
              myServo.write(pos);              // tell servo to go to position in variable 'pos'
              delay(15);                       // waits 15ms for the servo to reach the position
            }
          }
          // end new


        //Read in the buffer if there was send "GET /?message=..."

          if(buffer.indexOf("GET /?message=")>=0) {
            
            if(buffer.indexOf("switch on the light")>=0) {
              digitalWrite(5, HIGH);
              
              
            }
            
            if(buffer.indexOf("switch on the fan")>=0) {
              digitalWrite(9, HIGH);
            }   

            if(buffer.indexOf("open the garage")>=0){

               for (pos = 0; pos < 105; pos += 3) // goes from 0 degrees to 180 degrees
            { // in steps of 1 degree
              myServo.write(pos);              // tell servo to go to position in variable 'pos'
              delay(15);                       // waits 15ms for the servo to reach the position
            }
            }
            
            if(buffer.indexOf("switch off the light")>=0) {
              digitalWrite(5, LOW);
              
            }
            if(buffer.indexOf("switch off the fan")>=0) {
              digitalWrite(9, LOW);
          
            }

            if(buffer.indexOf("close the garage")>=0){
                 for (pos = 105; pos >= 0; pos -= 3) // goes from 180 degrees to 0 degrees
            {
              myServo.write(pos);              // tell servo to go to position in variable 'pos'
              delay(15);                       // waits 15ms for the servo to reach the position
            }
              
            }

            
          }

        } //else closed
        
        else {
          currentLineIsBlank = false;
        }
      }
    }
    delay(1);
    client.stop();
  }
}

Please read the sticky post at the top of the topic: How to use this forum.

You failed to post a wiring diagram, links to the used hardware.

I am trying to control DC Motr with Android Application.

Forget the Android at the moment, use a standard browser on your PC. Once you got that working you might change to the Android device again.

"it does not work" is about the worst description of the problem you can provide. You might want to insert some serial debugging output into your sketch and post the output you get together with the changed code.

You cannot power a DC motor from a pin on the arduino. It can only supply about 30ma and your motor needs much more than that to run.

Simple rule of thumb: The Arduino is not a power supply it requires one! Start by getting the Arduino cookbook and reading it. Also on line there are many videos etc showing the Arduino and how to do what you want.