LED not lighting when Arduino is used as a webclient

Hi All,

Im a real Arduino beginner, but I am trying to make a simple webclient that parses an http GET response and lights up an led (for this simple example i’m just trying to light up the built in led on pin 13) if the http response include a certain keyword. A lot of the code was copy and pasted from other examples. Im using an arduino uno r3 with the ethernet shield.

I was able to successfully start and run the blink example that is bundled with the ide. The below code works, receives a response, parses it and enters the block and prints “TRUTH” to the serial if the condition is met. The issue is that the LED does not turn on when I call the digitalWrite. What am I missing!!! Sorry if I am missing something obvious… I have replaced some of the urls/data with dummy urls/data but i have seen it working all the way through the part where “TRUTH” is printed, the led just doesn’t turn on (but if I switch it to the blink example the led turns on so I know the hardware is ok). Thanks so much for any help/guidance.

/*
  Web client
 
 This sketch connects to a website (http://www.google.com)
 using an Arduino Wiznet Ethernet shield. 
 
 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 
 created 18 Dec 2009
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe, based on work by Adrian McEwen
 
 */

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

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 
  0x90, 0xA2, 0xDA, 0x0E, 0x03, 0x33 };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
char server[] = "example.com";    // name address for Google (using DNS)

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192,168,0,166);

// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

String readString = String(1000);

int led = 13;

void setup() {
  pinMode(led, OUTPUT);
  // start the serial library:
  Serial.begin(9600);
  // start the Ethernet connection:
  Ethernet.begin(mac);
  
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /booleancheck HTTP/1.0");
    client.println();
  } 
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }
  
  
}

void loop()
{
  // if there are incoming bytes available 
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
    readString += c;
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    if(readString.indexOf("true")>0) {
      digitalWrite(led, HIGH);
      Serial.println("TRUTH");
    }
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    for(;;)
      ;
  }
}

According to your comments, the ethernet shield is already using pin 13.

Use a different pin.

-br

I knew it must have been obvious... Thanks so much! I'll make sure that works tonight and reply to this thread...