My pins arnt working in my esp2866

my eso8266 is working becuase it has voltage in and out but the pins in my on my board wont work

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ArduinoJson.h>




const char* ssid = "";
const char* password = "";


int red = 2;
int yellow = 1;
int green = 3;

int onred = 1;
int off = 0;


String host = "dweet.io";

WiFiClient client;

//Dweet dweet(client);

void connectToWiFi() {

  Serial.begin(115200);
  Serial.println();
  Serial.println();
  Serial.print("connect to wifi");
  Serial.print("...");

  WiFi.begin(ssid, password);
  int retries = 0;
  while ((WiFi.status() != WL_CONNECTED) && (retries < 15)) {
    retries++;
    delay(500);
    Serial.print(".");
  }

  if (retries > 14) {
    Serial.println(F("WiFi connection failed "));
  }
  if (WiFi.status() == WL_CONNECTED) {
    Serial.println(F("wifi conneted"));
    Serial.println("IP adress");
    Serial.println(WiFi.localIP());
  }
  Serial.println(F("setup"));
}

void setup() {
  Serial.begin(115200);

  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(yellow, OUTPUT);
  connectToWiFi();
}




void loop() {

  Serial.println("");
  Serial.println("-----");
  Serial.println("data run #");


  client.setTimeout(10000);
  if (!client.connect(host, 80)) {
    Serial.println(("connection failed"));
    return;
  }

  client.println(F("GET /get/latest/dweet/for/thomastech HTTP/1.0"));
  client.println(F("Host:dweet.io"));
  client.println(F("connection closed"));
  if (client.println() == 0) {
    Serial.println(F("failed to send request"));
    return;
  }
  char endOfHeaders[] = "\r\n\r\n";
  if (!client.find(endOfHeaders)) {
    Serial.println(F("invaild response"));
    return;
  }
  StaticJsonDocument<395> doc;

  DeserializationError error = deserializeJson(doc, client);

  if (error) {
    Serial.print(F("deserializeJson() failed: "));
    Serial.println(error.f_str());
    return;
  }


  JsonObject with_0 = doc["with"][0];
  const char* with_0_thing = with_0["thing"];      // "thomastech"
  const char* with_0_created = with_0["created"];  // "2022-11-17T22:43:33.471Z"

  int ledstatus = with_0["content"]["led status"];  // 1
  Serial.print("ledstatus:");
  Serial.println(ledstatus);

  if (ledstatus = onred) {
    digitalWrite(red, HIGH);
    digitalWrite(green, LOW);
    digitalWrite(yellow, LOW);
    Serial.println("led is on ");

  }
   else if (ledstatus = off) {
    digitalWrite(red, LOW);
    digitalWrite(green, LOW);
    digitalWrite(yellow, LOW);
    Serial.println(" leds are off ");
  }

  else {
    digitalWrite(red, LOW);
    digitalWrite(green, LOW);
    digitalWrite(yellow, LOW);
    Serial.println(" leds are off ");
  }

  delay(5000);
}

Post a schematic.

1 Like

I will have enclose a photo
And I’ve only attached one led to make it easier to see
One is in d1 and the other is in the ground

I do not read pictures or word problems, post an annotated schematic. Your picture has wires going into la-la land, not much help. If you do not have a schematic capture program you can download KiCad for free or many other cad program demos.

if (ledstatus = onred)
else if (ledstatus = off)

You should use the comparison operator == instead of the assignment operator =.

if (ledstatus == onred)

When you use 'if (ledstatus = onred)' you are assigning the value of onred to ledstatus, rather than comparing the two values.

Steve

Did you mean:

int red = D2;
int yellow = D1;
int green = D3;

Note: The mapping of D0-Dn to GPIO numbers will vary according to the board layout and labeling. Your board might be a clone of a "NodeMCU 1.0"

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.