Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: analogWrite() question on: February 10, 2013, 11:27:00 pm
PeterH and Learning,
Thank you for the suggestions. And yes PeterH I am definitely new to this... Below is how I changed it to a three digit value and from reading the serial it looks like its getting the correct variable now (also below). Learning, I also tried to change that if statement to !=0 and that didn't seem to change anything after I flashed the ard.

Change to digit string...
  // If desired, use more server.print() to send http header instead of just sending the analog value.
  int pwmPin = param1[0] - '0'; // Param1 should be one digit analog port
  int pwmState = param2[000] - '000'; // Param2 should be between 0 and 255
  analogWrite(pwmPin, pwmState);

And here is the output of the serial.
in ParseReceivedRequest
GET /analogWrite/3/255 HTTP/1.1

slash1=analogWrite/3/255 HTTP/1.1

slash2=3/255 HTTP/1.1

slash3=255 HTTP/1.1


new client
client disonnected
2  Using Arduino / Programming Questions / Re: analogWrite() question on: February 10, 2013, 09:27:09 pm
I am not sure I understand the question - I believe I am just defining my functions in that line.
3  Using Arduino / Programming Questions / Re: analogWrite() question on: February 10, 2013, 08:16:57 pm
In addition I set the values pwmPin = 5 and pwmState = 200 and the light just flashes once, and due to the "meta refresh" towards the top of the code the light will blink every ten seconds.
4  Using Arduino / Programming Questions / Re: analogWrite() question on: February 10, 2013, 08:12:03 pm
Thank you for that. I have tried changing that value to a 3 digit string and it still doesn't work... fun times...
5  Using Arduino / Programming Questions / Re: analogWrite() question on: February 10, 2013, 07:29:56 pm
pretty sure... the Uno board, Pin5. Like I said I turned on the led on pin5 with a short little script (below) and it worked just fine.

int ledPin = 5;    // LED connected to digital pin 9

void setup()  {
  // nothing happens in setup

void loop()  {
    analogWrite(ledPin, 200);                                     
6  Using Arduino / Programming Questions / analogWrite() question on: February 10, 2013, 07:17:29 pm
Hi all,
I have the below code that is taken and adapted from other members of this forum and the www. Everything works great with it except the analogWrite() function towards the bottom of the file. The way it works is that I hit an IP (ie. http: and it parses it and sets the pwm pin 5 to a setting of 200. I guess the only problem is that the analogWrite doesn't work, the digitalWrite works beautifully though. What actually happens when I visit the analogWrite link mentioned above is that the led, which is in a low pass filter, flashes briefly and doesn't stay on. I know it isn't a filter problem because I wrote a really simple sketch that just sets the analogWrite values outright and it behaves fine. Any ideas? I know its a little messy and the stuff towards the top is just so I can see the pin states while I am working with it. Thanks for any suggestions.


#include <Ethernet.h>
#include <SPI.h>
boolean reading = false;

  byte ip[] = { 192, 168, 0, 30 };   //Manual setup only
  byte gateway[] = { 192, 168, 0, 1 }; //Manual setup only
  byte subnet[] = { 255, 255, 255, 0 }; //Manual setup only

  // if need to change the MAC address (Very Rare)
  byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

  EthernetServer server = EthernetServer(80); //port 80
int ledPin = 13;         
#define bufferMax 128
int bufferSize;
char buffer[bufferMax];

char cmd[15];    // Nothing magical about 15, increase these if you need longer commands/parameters
char param1[15];
char param2[15];

void setup(){

  //Pins 10,11,12 & 13 are used by the ethernet shield

  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);

  Ethernet.begin(mac, ip, gateway, subnet); //for manual setup



void loop(){
  // listen for incoming clients, and process qequest.
 // checkForClient();

  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c =;
        if(reading && c == ' ') reading = false;
        if(c == '?') reading = true; //found the ?, begin reading the info

        char d = 'a';
          char d = c;
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connnection: close");
          client.println("<!DOCTYPE HTML>");
                    // add a meta refresh tag, so the browser pulls again every 10 seconds:
          client.println("<meta http-equiv=\"refresh\" content=\"10\">");
          // output the value of each analog input pin
          //client.print("this is a test");
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(" is ");
            client.println("<br />");       
          for (int digitalChannel = 0; digitalChannel < 10; digitalChannel++) {
            int sensorReading = digitalRead(digitalChannel);
            client.print("Digital PinMode ");
            client.print(" is ");
            client.println("<br />");       
          client.println("<br />");       
          client.println("<br />");       
          client.println("<br />");       


    // give the web browser time to receive the data
    // close the connection:
    Serial.println("client disonnected");



void WaitForRequest(EthernetClient client) // Sets buffer[] and bufferSize
  bufferSize = 0;
  while (client.connected()) {
    if (client.available()) {
      char c =;
      if (c == '\n')
        if (bufferSize < bufferMax)
          buffer[bufferSize++] = c;
  PrintNumber("bufferSize", bufferSize);

void ParseReceivedRequest()
  Serial.println("in ParseReceivedRequest");
  //Received buffer contains "GET /cmd/param1/param2 HTTP/1.1".  Break it up.
  char* slash1;
  char* slash2;
  char* slash3;
  char* space2;
  slash1 = strstr(buffer, "/") + 1; // Look for first slash
  slash2 = strstr(slash1, "/") + 1; // second slash
  slash3 = strstr(slash2, "/") + 1; // third slash
  space2 = strstr(slash2, " ") + 1; // space after second slash (in case there is no third slash)
  if (slash3 > space2) slash3=slash2;

  // strncpy does not automatically add terminating zero, but strncat does! So start with blank string and concatenate.
  cmd[0] = 0;
  param1[0] = 0;
  param2[0] = 0;
  strncat(cmd, slash1, slash2-slash1-1);
  strncat(param1, slash2, slash3-slash2-1);
  strncat(param2, slash3, space2-slash3-1);

void PerformRequestedCommands()
  if ( strcmp(cmd,"digitalWrite") == 0 ) RemoteDigitalWrite();
  if ( strcmp(cmd,"analogWrite") == 0 ) RemoteAnalogWrite();

void RemoteDigitalWrite()
  int ledPin = param1[0] - '0'; // Param1 should be one digit port
  int ledState = param2[0] - '0'; // Param2 should be either 1 or 0
  digitalWrite(ledPin, ledState);

void RemoteAnalogWrite()
  // If desired, use more server.print() to send http header instead of just sending the analog value.
  int pwmPin = param1[0] - '0'; // Param1 should be one digit analog port
  int pwmState = param2[0] - '0'; // Param2 should be between 0 and 255
  analogWrite(pwmPin, pwmState);         

void PrintString(char* label, char* str)
void PrintNumber(char* label, int number)
  Serial.println(number, DEC);
7  Using Arduino / Project Guidance / Re: temperature controller on: January 19, 2013, 06:45:00 pm
Thanks everyone. I think that I definitely have enough to get started with and if/when I have questions I'll be back.
8  Using Arduino / Project Guidance / Re: temperature controller on: January 18, 2013, 05:17:01 pm
Thanks for the help! the furnace is ceramic covered coil. It runs off 120V and 15 amp... the standard stuff.
9  Using Arduino / Project Guidance / Re: temperature controller on: January 18, 2013, 03:15:42 pm
Sorry, should have specified... they are just ceramic furnaces. You send current to them and they get hot.
10  Using Arduino / Project Guidance / temperature controller on: January 18, 2013, 02:44:11 pm
Hi All,
I am new to arduino and am looking to use the product as a temperature controller for a furnace that runs some of our reactions in the lab. I am more comfortable on the software side of things than the hardware side of things, but basically what I want to do is mimic an Omega CN4800 temperature controller ( However I would also like it to be web accessible or at the very least remotely accessible through the computer nearby. The way I envision this working is the uno card with a thermostat and a relay to control the furnace with the ethernet shield. Any thoughts? recommendations? As I said before I am really just needing some help on the hardware side and trying to get everything wired up properly.

Thank you
Pages: [1]