Rotate motor when http request hit with Arduino



Purpose 
Main purpose of this project is to rotate a motor when http request is hit

Equipment needed
Stepper motor,Arduino UNO R3 , Ethernet Shield W5100 R3 UNO , Wires

Steps
Set up the circuit as below 



On top of that you have to plug Ethernet Shield to Arduino UNO R3 as below

Then open the arduino IDE and paste the below codes


#include <SPI.h>
#include <Ethernet.h>
#include <Stepper.h>

#define STEPS 32
Stepper stepper(STEPS, 6, 8, 7, 9);
boolean incoming = 0;
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDA, 0x02 };
IPAddress ip(192,168,XX,XX); //<<< ENTER YOUR IP ADDRESS HERE!!!
EthernetServer server(80);
String currentLine = "";


void setup()
{
  Ethernet.begin(mac, ip);
  server.begin();
  stepper.setSpeed(1000);
  Serial.begin(9600); 
}

void loop()
{             
  EthernetClient client = server.available(); 
  if (client) {
    char inChar = client.read();
    currentLine += inChar; 
      if (inChar == '\n') {
        currentLine = "";
      } 

      if (currentLine.endsWith("start")) { 
               stepper.step(1024);
              delay(2000);
      }

      if (currentLine.endsWith("stop")) {
      }
  }

  }

Then deploy the code to circuit. 
Then hit the web request. Motor should rotate 360 degrees.


No comments:

Post a Comment