[Solved] Connecting esp8266 to Arduino brings lots of noise to motion sensor

Hi there,

Though my knowledge of electronics is close to none, I have quite some experience with using Arduinos/esp8266/WEMOS and whatever other microcontrollers/sensors you can think of. Over te past few years I've filled my house with several microcontrollers all talking to my mainframe Raspberry Pi basically controlling my house (curtains/ligts/tv/music/etc.).

The problem:
My latest project involves an Arduino hooked up with a motion sensor (HC-SR505) on the 5v of the Arduino. The motion sensing work perfectly fine and all is well untill... I connect my ESP8266-01S module to the 3.3v of the Arduino. As soon as I do this the motion sensor start randomly sensing motion, even though it is wrapped inside a hat. Whenever I take out the ESP8266-01S module the sensor works perfectly fine again.

I'll try and make a schematic of the setup, but im having a hard time using Eagle cad and importing some of the modules... attached is a picture of the actual hardware.

Here is (the simplified) version of the code running on the Arduino:

int pirInputPin = 13;
unsigned long pirDelay = 0;
bool movementDetected;

void setup() {
  pinMode(pirInputPin, INPUT);
  digitalWrite(pirInputPin, LOW);

  Serial.begin(74880);
}

void loop() {
  int pirValue = digitalRead(pirInputPin);
  
  if (pirValue && !movementDetected) {
    Serial.println("movement=1");
    movementDetected = true;
  }
  if (pirValue) {
    pirDelay = millis() + (1 * 1000);
  }
  if (movementDetected && !pirValue && millis() > pirDelay) {
    Serial.println("movement=0");
    movementDetected = false;
  }
  delay(20);
}

And (a simplified version) of the code running on the ESP-8266-01S module:

#define MAX_LEN 55
char incomingMsg[MAX_LEN];
uint8_t count = 0;

void setup() {
  Serial.begin(74880);
  setupWifi(); // not specified in this snippet
}

void loop() {
  mqttReconnect(); // not specified in this snippet
  while (Serial.available() > 0) {
    char c = Serial.read();
    if (c == '\n') {
      incomingMsg[count] = '\0';
      count = 0;
      delay(50);
      sendMessageOverMqtt(); // sends a message over MQTT if arduino detected movement
    } else {
      if (count < (MAX_LEN - 1)) {
        incomingMsg[count++] = c;
      }
    }
  }
}

I've tried a lot of things, and it is obvious that simply disconnecting the ESP8266-S01 module from the 3.3v fixes the problem.. so it's definitely there somewhere. Other forum posts suggested that running two appliances on both 3.3v and 5v shouldn't be a problem... but apparently it is? What am I not seeing, please help ^^

[SOLVED

Hi,
Welcome to the forum.
Your image was a bit big so it got distorted when set into your post.
I have resized it and this should look better.


Have you got the gnd of the ESP connected to the gnd of the Arduino?

Tom... :slight_smile:

Hi,
Thanks for the schematic, a hand drawn circuit would have been just as good, without you having to wrestle with Eagle.

You could try bypassing, that is placing 0.1uF capacitors across the Vcc and gnd connections AT the PIR and AT the ESP.

Tom... :slight_smile:

Hi,
I'm not sure what you are trying to do here;

void setup() {
  pinMode(pirInputPin, INPUT);
  digitalWrite(pirInputPin, LOW);

  Serial.begin(74880);
}

But this might be better, the PIR may need a pullup resistor on its output to give you a stable output.

void setup() 
{
  pinMode(pirInputPin, INPUT_PULLUP);
  
  Serial.begin(74880);
}

Tom.. :slight_smile:

You could try bypassing, that is placing 0.1uF capacitors across the Vcc and gnd connections AT the PIR and AT the ESP.

Hey Tom, thanks for your reply and fixing the image!

As you can see in the schamtic i have the grounds of both PIR and ESP in their own arduino ground... but i figured in effect it would just be the same ground? I've already tried connecting with an external power source (powering the arduino with the VIN pin and putting all the grounds directly to the external power source, but the problem persists.

I have also tried putting 1uF and higher capacitors over PIR and ESP... but not yet both at the same time, I'll try that now.

TomGeorge:
Hi,
I'm not sure what you are trying to do here;

void setup() {

pinMode(pirInputPin, INPUT);
 digitalWrite(pirInputPin, LOW);

Serial.begin(74880);
}





But this might be better, the PIR may need a pullup resistor on its output to give you a stable output.



void setup()
{
 pinMode(pirInputPin, INPUT_PULLUP);
 
 Serial.begin(74880);
}




Tom.. :)

Ah yes indeed that seems a bit silly, it can be explained in this post from stackexchange. TLDR:

Anyway, you MUST tell that PIN to be ZERO at the start, otherwise, it's hell brake loose... Therefore, please write the PIN with 0 and then it should all work fine after that:

Would I achieve the same thing using INPUT_PULLUP?
(PS: Might respond a bit slow, can only post once every 5 mins)

Hi,
Telling an input pin to go low, does nothing.
Telling it INPUT_PULLUP switches in an internal resistor between the input pin and Vcc of the controller.

The PIR may have what is called OPEN CIRCUIT COLLECTOR and it needs a resistor between its output and Vcc to make it work properly.
Usually the internal pullup is enough.

Do you have a DMM?

Tom... :slight_smile:
PS, I'm off to bed its after midnight here, so other forum member may see your thread and help.

The PIR may have what is called OPEN CIRCUIT COLLECTOR and it needs a resistor between its output and Vcc to make it work properly.
Usually the internal pullup is enough.

Indeed, the PIR works perfectly fine without writing the digital input to low and using INPUT_PULLUP.... unfortunately it doesn't keep functioning perfectly fine as soon as I connect the ESP again :frowning:

Do you have a DMM?

Yes, i have a DMM.

If you have an ESP, why are you using an Arduino?

Paul__B:
If you have an ESP, why are you using an Arduino?

The pir sensor is one of the things the arduino will be controlling, it's also powering two ledstrips and a relay. The code I provided is heavily simplified.

casjonker:
The PIR sensor is one of the things the Arduino will be controlling, it's also powering two ledstrips and a relay. The code I provided is heavily simplified.

Four I/O. So why do you need an Arduino?

Each ledstrip is three I/O and the esp can only handle up to 3.3v while the sensors and the leds need 5v. Also the power supply is 12 volts so having the arduino there just makes everything so much easier.

Maximum current draw on 3.3 V pin = 50 mA

casjonker:
Each ledstrip is three I/O and the esp can only handle up to 3.3v while the sensors and the leds need 5v. Also the power supply is 12 volts so having the arduino there just makes everything so much easier.

How many 5V LEDs?
Are they in a strip, I hope you are going to control them with a MOSFET and not power them from the output pin if their current consumption is over 30 - 40 mA?
A complete schematic might be needed here.
Tom... :slight_smile:

TomGeorge:
I hope you are going to control them with a MOSFET and not power them from the output pin if their current consumption is over 30 - 40 mA?

Oh my this got out of hand quickly... Yes, the LEDstrips are definitely controlled through three MOSFETs (red, green and blue). These MOSFETs need a logic control of 5v, which is why i want to use the arduino. All of this works perfectly fine already...
The only part im struggling with is the motion sensor reading random values whenever I plug in the ESP8266 module.

You cannot use the 3.3 V from the Arduino as Vcc for the esp8266.

I agree with ZX80, pretty sure ESP8266 needs more 3.3V current than the 150mA regulator on the Arduino can supply.
Use an offboard 3.3V regulator to power it.
Datasheet tells the story:

Use an offboard 3.3V regulator to power it.

Wow thanks guys! Let’s hope this works… Im gonna try later tonight. Curious though that the ESP seems to be working just fine.

... 3.3 V generated by the on-board FTDI chip max current = 50 mA

Right, while setting it up in a way the ESP is powered from the 5v Arduino pin, which is then lowered with to 3.3v with an LDO regulator (MCP1702) i realised I had tried powering it all with an external power source before... And alas, the problem persists. See schematic for the current setup (ignore the text MCP270312MB, in reality that is and MCP1702-3.3v)