how to control an analogOUTPUT of an arduino PWM pin from an HTML web page?

hi, i want to learn how to control an analogOUTPUT of an arduino PWM pin from an HTML web page. since the data that comes from the client to the arduino server is a string data i dont know how change it to a format (i think it must be an integer). that the pins could understand and output it.. for example controlling a servo from the HTML web page.. could you please help me?!!

Have a look at the atoi() function - it converts a char to an integer. I have had a bit of trouble with this function, I've have had more luck with atof() (convert to float).

    float output_FLOAT = constrain(atof(singleChar), 0.000, 99.999);

You could also subtract 48 from the character - this converts from ASCII char to digit.

int output_INTEGER = constrain((((charArray[0]-48)*1000)
 + ((charArray[1]-48)*100) + ((charArray[2]-48)*10)
 + (charArray[3]-48)), 0, 9999);

As far as my [limited] experience goes, these 2 options will only work when converting single char at a time.

I'm sure there's an easier way, but this both of these have worked for me. Hope this helps!

thank you very much @sandraOos

The below is some servo web control test code. You might use something similar to send values for a motor. Open the serial monitor to see what is received from the browser.

//zoomkat 6-13-15
//get submit box code
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html or use a '
//address will look like when submited
//for use with W5100 based ethernet shields
//Powering a servo from the arduino usually *DOES NOT WORK*.

#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 
//int n; //value to write to servo

byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 
  192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 
  192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 
  255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port

String readString, newString;


void setup(){

  //start Ethernet
  Ethernet.begin(mac, ip, gateway, gateway, subnet);

  //enable serial data print 
  myservo.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7, 500, 2500);  //the pin for the servo control, and range if desired
  Serial.println("server text box servo test"); // so I can keep track of what is loaded

void loop(){
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c =;

        //read char by char HTTP request
        if (readString.length() < 100) {

          //store characters to string 
          readString += c; 

        //if HTTP request has ended
        if (c == '\n') {

          Serial.print(readString); //see what was captured

          //now output HTML data header

          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");

          client.println("<TITLE>Arduino GET test page</TITLE>");

          client.println("<H1>HTML form GET example</H1>");

          client.println("<FORM ACTION='/' method=get >"); //uses IP/port of web page

          client.println("Set servo position: <INPUT TYPE=TEXT NAME='LED' VALUE='' SIZE='25' MAXLENGTH='50'>

          client.println("<INPUT TYPE=SUBMIT NAME='submit' VALUE='Send servo position'>");




          //stopping client

          if (readString.length() >0) {
            //Serial.println(readString); //prints string to serial port out
            int pos1 = readString.indexOf('=');
            int pos2 = readString.indexOf('&');
            newString = readString.substring(pos1+1, pos2);
            Serial.print("newString is: ");
            int n = newString.toInt();
            Serial.print("The value sent is: ");
            readString=""; //clears variable for new input    
            newString=""; //clears variable for new input
            // auto select appropriate value
            if(n >= 500)
              Serial.print("writing Microseconds: ");
              Serial.print("writing Angle: ");