movement sensor not working properly with 12v adapter connected to circuit

Hi.

I built a circuit using arduino nano as seen in the attached picture.

There is a strange issue with the movement sensor and i can't figure out why:

If i connect the arduino to my PC with USB cable only, everything works fine (just the LED won't turn on because there is no 12v input). so the movement sensor is working and reacting as expected.

Then i connect the 12v power supply and everything works well except for the movement sensor - it is always 0 - even if there is movement near it. the strange thing is that if i turn on the RGB
LED just a little bit (making it not completely 0,0,0), the movement sensor starts to react as it should.

what could be the cause for this? i want the sensor to work even if the RGB is completely off.

  • No current limit resistors on RGB LED.
  • No current limit resistors on transistor bases.
  • Buttons connected to 5 V instead of ground.
  • LDR connected to 5 V instead of ground.
  • Transmit line of ESP-01 connected directly to Nano output.
  • Since the LDR, buttons, potentiometer and ESP-01 as well as the RGB LED, require your 12 V supply to operate, I am puzzled as to how you think anything functions when the Nano is powered only by USB.

1 and 2 - do you think they are related to the problem?
3. pushing them gets them high why is that a problem?
4. why is that a problem?
5. ESP is working fine - i send and receive data with no problem
6. you're right - sorry - i only tested the movement sensor with only the usb cable connected.

with the 12v connected, the ESP, LDR, push buttons are all working well - there is only the strange issue i mentioned with the RGB LED.

impeham:
1 and 2 - do you think they are related to the problem?

Well, overloading your port pins and the supply can't be good!

impeham:
3. pushing them gets them high why is that a problem?

It's bad engineering. While it may be (indeed is) the proper way to wire the lights in your house, connecting switches to the supply rail is a bad practice in digital circuits. Unfortunately, those writing the Arduino tutorials seemed to think they were indeed, wiring the lights in their house or else have some particularly unhelpful fantasy that they are making it "easier to understand" if the input goes HIGH when the switch is closed.

You do not want the 5 V line to be taken to any part of the circuit that it does not need; if nothing else this offers a point of failure if it is accidentally shorted to ground (and of course, complicates the wiring as the ground connection is virtually always present). If switches are wired to ground, then at worst, a short to ground will appear as a spurious actuation of the switch. The essential difference between switches used as inputs to logic systems and those in mains wiring is that these switches control next to no power and essentially harmless low voltages, whereas the primary purpose of those in your mains wiring is to render the circuit safe when turned off.

Microcontrollers such as the ATmegas are specifically designed to provide an internal pull-up to interface with switches or "open-collector" logic, which along with "negative logic", has been used from the beginning of digital logic design.

The only two reasons for providing an additional pull-up (which can be conveniently provided at the microcontroller end of the wiring where the +5 V line is already present) are to provide "wetting current" or to suppress the pick-up of interference on the wiring to switches at a distance.

impeham:
4. why is that a problem?

Ditto.

impeham:
5. ESP is working fine - I send and receive data with no problem

But feeding 5 V into a 3.3 V rated input - well, you may get away with it but this is a hot topic on the ESP8266 discussions - it may be bad for reliability. Put a diode with cathode to the Arduino and anode to the ESP input.

impeham:
6. you're right - sorry - I only tested the movement sensor with only the USB cable connected.

I want to know with no LED, no ESP to talk to, how you know that it is in fact responding. What is your output device to tell you?

In short, you haven't posted your code!

thanks for the detailed info.

i'm printing its value through serial

i made a test with an oscilloscope today:
i disconnected the wire from the output pin of the movement sensor to the arduino input pin and connected the oscilloscope to GND and output pin of the sensor.

when there is a movement, the high voltage gets to 3.5v which should be fine. but when i reconnect the arduino pin, a movement gets the voltage to 2v only which is not enough to get the arduino pin to high- that is why is do not see high through the serial monitor.

what can be the cause for that?

Hi,
Have you checked and rectified the suggestions in post#2.

If not please rectify them before you damage your Nano and the other hardware.

Can you please tell us your electronics, programming, Arduino, hardware experience?
Do you have a DMM?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Not a Fritzy picture please.

Thanks.. Tom.. :slight_smile:

just one - added current limit resistor of 120ohm to transistors bases. the others are not a risk and i don't believe related to the current issue.

i also replaced the power source to another new 12v DC adapter, the arduino nano and the motion sensor - just to make sure none of them was defected.

the behavior now is always as i described in #5 - the output voltage of the sensor at movement is ~2v when it is connected to the arduino pin and ~3.5v when not connected to it.

i am a software engineer for many years now. electronics along with software coding are something i really like - you can see some of my projects at my Web Site

i've already designed and built many circuits already using arduino.
i don't have CAD design - only using fritzing - sorry.

impeham:
When there is a movement, the high voltage gets to 3.5v which should be fine. but when I reconnect the arduino pin, a movement gets the voltage to 2v only which is not enough to get the Arduino pin to high - that is why is do not see high through the serial monitor.

What can be the cause for that?

Well, one would be setting that pin on the Arduino as OUTPUT in the code you have kept secret.

But I note for some peculiar reason you have used D13 for this. Use a different pin!

impeham:
just one - added current limit resistor of 120ohm to transistors bases. the others are not a risk and i don't believe related to the current issue.

I think you need to add current limit to the LED too, that is related to you destroying your LED and possibly the driver transistors.
Calculate what value you need, check the data on the LED for volt drop and current consumption.
Thanks.. Tom.. :slight_smile:

Paul__B:
Well, one would be setting that pin on the Arduino as OUTPUT in the code you have kept secret.

But I note for some peculiar reason you have used D13 for this. Use a different pin!

about D13 - i can switch to another, but why is there problem with it?

the code is not secret of course - just didn't think it's required as it is an electronic issue

D13 is being set as output of course.

about the LEDs - the scenario i described about the movement sensor is when they are completely off so no current is being drawn.

Paul__B:
Well, one would be setting that pin on the Arduino as OUTPUT in the code you have kept secret.

But I note for some peculiar reason you have used D13 for this. Use a different pin!

Paul man - you're my hero! changed to pin 6 instead of 13 and it works perfectly!

my question is - WHY???

Paul__B:
Well, overloading your port pins and the supply can't be good!
It's bad engineering. While it may be (indeed is) the proper way to wire the lights in your house, connecting switches to the supply rail is a bad practice in digital circuits.

I'm going to unpack this, because its not true now.

In the days way back when the common logic families were TTL and LS-TTL, it was definitely
a no-no to wire a logic input to the supply rail - easiest way to fry TTL there is, as inputs are
barely able to handle 5V (5.5V absolute max, whereas the the supply itself could handle 7V)

Normally pins that were pulled up had a 1k (or 10k for 74LSxx) resistor between the pin and the 5V
rail to prevent destruction of the device (due to small voltage glitches on the supply).

However these days everything is CMOS, and CMOS is totally happy with inputs strapped to the supply,
its symmetrical w.r.t. supply and ground after all.

You can arrange push buttons to connect to Vcc or to ground, the choice is yours. Often the
hardware is simpler with buttons pulled down to ground as this removes the need to route the
supply voltage to all the buttons, and normally a groundplane is already available.

In a complex system connecting buttons to ground is advangeous as you don't even need to
worry about which supply rail is the right one (you might have 5V and 3.3V circuitry in the same
project for instance).

It also makes sense if some of the logic circuitry can be powered down - you don't want the risk
of phantom-powering via a push button in this circumstance.

But its certainly not bad practice to wire a button to the supply per se...

impeham:
Paul man - you're my hero! changed to pin 6 instead of 13 and it works perfectly!

my question is - WHY???

It's pin 13. There is a LED and resistor (to ground) connected to it. Clearly, the output from your PIR (and again, you have not specified which one but used the picture for the common HC-SR501 variety below) is a weak "logic" output which is not capable of driving the LED, so the LED holds the voltage down to about its forward drop.

Remember the Tx line to the ESP8266 that I said you were connecting wrongly? When your 12 V power supply and down-regulators are not corrected, the ESP8266 is being "phantom powered" from the Tx pin and drawing a dangerous current from that pin, which is pulling down the USB-derived 5 V. This lowers the logic thresholds of the Arduino so that the weak voltage from the PIR is just enough to be seen as HIGH. When you power up the ESP8266 properly (seems they are reasonably rugged), it no longer loads the Tx pin as much so the HIGH threshold is higher and the PIR is unable to trigger it. Unless perhaps some other part of the circuit - such as your missing base resistors to the RGB transistors - loads the Arduino down instead.


Note the 1k resistor in series with the output line. This allows you to connect it directly to a LED if that is the only indication you want, but that is what is limiting your voltage. The HC-SR505 which I rather like, has a different IC but the same resistor in the output lead.

I already added the base resistors and will definitely take the info i learned from here and implement in my circuits.

Thanks a lot :slight_smile:

Exactly what Paul__B said.
Big-board Arduinos (Uno/Mega) have an opamp buffer between pin13 and the buildin LED,
so pin13 behaves (almost) like any other input pin.
Smaller boards (Nano) don't have the opamp, and the buildin LED is connected directly to the pin.
That could give problems if you drive that pin with a weak signal (PIR).
Leo..

Paul__B:
Remember the Tx line to the ESP8266 that I said you were connecting wrongly? When your 12 V power supply and down-regulators are not corrected, the ESP8266 is being "phantom powered" from the Tx pin and drawing a dangerous current from that pin

Paul - what is the best way you think to prevent this from happening?

Thanks.

impeham:
Paul - what is the best way you think to prevent this from happening?

Apparently, the Rx pin in the ESP8266 has an internal pull-up so that a simple diode with cathode to Arduino and anode to the ESP cures both the level conversion and phantom powering considerations.

How do I know that? Well, that is what they used in the Adafruit Huzzah ESP8266 breakout.

Clearly, the ESP8266 does contain an internal pull-up, so you might or might not need to add a pull-up to the 3.3 V line. You are driving it with an Arduino, so if needed, pick your value - 1k, 3k3 - whatever. This will in any case be faster than a resistive divider.

Cathode to arduino pin and anode to ESP's Rx? but that would block all arduino transmissions to ESP.

impeham:
Cathode to arduino pin and anode to ESP's Rx? but that would block all arduino transmissions to ESP.

OK, so you are a total "newbie" when it comes to digital logic and electronics. Fair enough, that's what we are here for.

Take a look at this article, and perhaps do some more research on the term "open collector". If that does not explain it well enough, I may have more time later. (few jobs to do first!) :grinning: