0

So I have and arduino uno that is firing an output on pin 8. This code is not in this file just to be clear. From there Im taking that output and using it to fire pin 0 on the wifi module. Im using pin 0 because from what I understand all other pins have a pullup or pulldown resistor. When pin 0 is hot I want to print that value. Sometimes it works when I do it other times the analog values reads very low. I am using the 3.3v from the arduino uno and I plan to get a voltage regulator for the wifi module but would this cause this kind of issue? I am very very new to arduino so if anyone has any ideas I would appreciate a very dumbed down explanation. Thanks a lot. Also the reason why I have the delay turned down so low is because it seemed to make the analog signal pick up more often. Im not sure why this would matter but at a delay of 3000 it would almost never change analog value but when I turned the delay down to one the value came through much more consistently. Currently the code just outputs low analog numbers and occasionally pops up 1023 when voltage is applied but not consistently. And sometimes it just stops altogether until I keep trying for a while. I am getting voltage to the pin however so I know I have a complete circuit and power.

include

#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>

const char* ssid = "ENDOWED Underwear";
const char* password = "endowwear";

HTTPClient http;

static const uint8_t D0   = 16;
static const uint8_t D1   = 5;
static const uint8_t D2   = 4;
static const uint8_t D3   = 0;
static const uint8_t D4   = 2;
static const uint8_t D5   = 14;
static const uint8_t D6   = 12;
static const uint8_t D7   = 13;
static const uint8_t D8   = 15;
static const uint8_t D9   = 3;
static const uint8_t D10  = 1;

int featherPin = D3;

void setup() {
  Serial.begin(115200);
  pinMode(featherPin, INPUT);

  WiFi.begin(ssid, password);

  while(WiFi.status() != WL_CONNECTED) {
    delay(10);
    Serial.println("Waiting for connection");
  }
}

void loop() {
  int sensorValue = analogRead(featherPin);

  if (WiFi.status() == WL_CONNECTED) {
        Serial.println("yay connect");

        http.begin("http://10.150.40.121:3000/");
        http.addHeader("Content-Type", "text/plain");

        int httpCode = http.POST("Message from ESP8266");
        String payload = http.getString();
//        Serial.println(payload);
        http.end();

    } else {
        Serial.println("Error in Wifi connection"); 
    }

    if (sensorValue > 850) {

      http.begin("http://10.150.40.121:3000/home");
      http.addHeader("Content-Type", "text/plain");

      int httpCode = http.POST("Message from ESP8266");
      String payload = http.getString();
      Serial.println(payload);
      Serial.print("hi");
      http.end();
      } else if (sensorValue < 850) {
        Serial.print(sensorValue);
//        Serial.println("I am not hot");
      } 


//  digitalWrite(trigPin, LOW);
//  delayMicroseconds(1);
//  digitalWrite(trigPin, HIGH);
//  delayMicroseconds(2);
//  digitalWrite(trigPin, LOW);
//
//  pinMode(echoPin, INPUT);
//  duration = pulseIn(echoPin, HIGH);
//
//  inches = (duration / 2) / 74;
//  Serial.println(inches);
//
//  spaceIntruded = inches;
//  
//  if (spaceIntruded <= 50 || spaceIntruded >= 900){
//      digitalWrite(ledPin, HIGH);
//      digitalWrite(hornPin, HIGH); 
//      Serial.println("Intruder Detected!");
//      Serial.println("Sending text Notification...");
//      delay(500);
//      Serial.println("Armed...");
//  }
//  
//  else{
//    digitalWrite(hornPin, LOW);
//    digitalWrite(ledPin, LOW);
//  }
    delay(1);

}
  • When pin 0 is hot I want to print that value...? What value? What do you mean by "hot"? – Majenko Jan 5 at 22:27
  • When pin 0 on the Arduino uno is hot meaning it has 3.3v applied to it I want to analogRead the change in value. If no voltage is applied it should read as a lot number and when voltage is applied it should read as a high number and sometimes it does but it in no way consistent. Im not sure if its because Im taking the 3.3v from the arduino uno but i also tried taking it from the 5v on the arduino uno and steeping it down with a voltage regulator and Im getting the same issue. However it was adjustable voltage regulator. Im going to get one that is specifically for 3.3v. – user52703 Jan 5 at 22:39
  • Do you have the pin connected to the analog input pin as well as pin 0? You do know that the ESP8266 has only one analog input, and that is a special pin and not one of the normal Dx pins, yes? – Majenko Jan 5 at 22:43
  • No I didnt and I not to clear on what you mean by DX pin and I have pins soldered for each pin and im am maunally touching the output from the arduino uno to the 0 pin and no consistent change occurs. As of right now its working at all but at times it does. But the pin is not connected to an analog pin its just a pin. All the pins are soldered on and im only using pin 0 cause it doesnt have a pullup pulldown internal resistor. When tried using the other pins I couldnt get the value to change at all. Only when I chnaged to 0 did it read the change sometimes. – user52703 Jan 5 at 22:58
  • microcenter.com/product/460313/feather-huzzah-with-esp8266-wifi This is the wifi module I am using – user52703 Jan 5 at 22:59
0

Analog to Digital conversion is one aspect1 where the ESP8266 is very poor. It has a single ADC pin which can read a maximum of 1V.

That pin is the only pin you can use with analogRead(). Any attempts to use any other pin just use that pin instead. The parameter (pin number) to analogRead(pin) is ignored and no matter what you do that one single ADC pin is what is being read. Also the pin cannot be used for anything else. None of the digital functions can be used with it since the pin doesn't have a GPIO number associated with it.

Some boards include a simple voltage divider on the ADC pin to allow higher voltages to be read, such as the NodeMCU:

enter image description here

If your board doesn't have such a divider you will have to implement it (or something similar) to be able to read the 3.3V incoming voltage.


1 The ESP8266 is great for WiFi but pretty poor for everything else. It is seriously starved of internal peripherals (it doesn't even have I²C). For a more feature-rich solution you might consider upgrading to the ESP32.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.