PIR Sensor analog value oscillation?

I am creating an Arduino Uno controlled controller for an animated Halloween decoration. I plan to have a PIR sensor trigger the Arduino to turn on two relays and use an attached MP3 board to play a sound. One of the two relays controls a 12vdc output to a couple of LEDs. The other relay controls a standard 110vac outlet which will have a motor plugged into it.

My goal is to have one standard PC power cable provide 110vac power to my project and then have that voltage converted to the various voltages I need for the other components. The 110vac coming into my project enclosure is run to the standard outlet and fed into a LED Driver which converts it to 12vdc. The 12vdc powers the Arduino and is fed into a DC buck converter to step it down to 5vdc. The 5vdc powers my PIR sensor, the MP3 player board, and a USB jack I'm using to supply power to an external speaker.

The PIR sensor is connected to the controller by a standard Ethernet cable. Three of the wires in the Ethernet cable provide ground, 5vdc, and input to the PIR sensor.

The first problem I'm running into is that my PIR sensor doesn't work when it's powered by the 5vdc coming out of my buck converter. It DOES work if it is powered by the Arduino's 5V pin. For testing purposes I'm running a sketch that does nothing but put the analog value received on the PIR input pin out to serial. At this point the relays and audio board are not connected to the Arduino at all. When the PIR is powered by the 5V pin on the Arduino it works as expected: it normally shows a value of 0 and shows values of ~620 when something moves in front of the sensor. When the PIR sensor is powered by the buck converter output, the PIR values oscillate from 0 to 1023 and back every 5 seconds or so and there is no apparent reaction to motion in front of the sensor.

I have used my multimeter to check the voltages coming out of the LED driver (steady 12vdc) and out of the buck converter (steady 5vdc). I have checked the voltage at both ends of my PIR Ethernet connection (steady 5vdc) and on the input pin from the PIR sensor (0 when not triggered, ~3.2vdc when triggered). The voltage on the PIR's input pin looks correct regardless of how the sensor is being powered, but as I said, if the power is coming from the buck converter instead of the Arduino then the analog values being read by the Arduino are oscillating nonsense.

This is my largest Arduino project to date. I'm a software guy by trade so I'm much more comfortable with the code than the physical pieces. I suspect that I am running into some sort of interference due to my combination of AC & DC voltages, but I'm not sure how to go about troubleshooting further or fixing it. Any advice would be appreciated.

Thanks,
Mike

If you wired it the way you show in the picture, this shouldn't be a problem.

HOWEVER, you should make sure that the GND on the output side of the DC-DC converter is connected to GND on the input side. So the 12V GND must be connected to the 5V GND.
While you're at it, I would forego the 12V input on the Arduino and feed it with 5V from your DC-DC converter; you've got that anyway, why not use it to its full effect? Coincidentally this would also work around the issue I mentioned, but I'd actually solve it if I were you.

Hi, @silverlock
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

Have you developed your code in stages?'

If so you must have some code that JUST looks at the PIR.
If not then forget you existing code for the moment and write a code to read the PIR.

Have you got the gnds of the PIR connected to the gnd of the controller and DC-DC supply?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Hi,
Can you post your code?
Can you post a link to data/specs of the PIR?
A link to to the LED driver to please, they are not designed for use as a general power supply, only LED loads that require current control.
A hand drawn circuit diagram would be better using blocks and labeling pins and components.

Thanks.. Tom.. :smiley: :+1: :australia:

Yes I agree, first thing I saw was that LED driver.
Quite possible it is not an isolated type supply as well which would make it downright dangerous.

'Led driver' is often a bit of an awkward/misused term. More often than not what is sold as a 'led driver' is just a fixed-voltage switch-mode power supply. If I squint, I think I see "12Vdc" printed on the one in the picture, which would mean it's not a fixed-current led driver but just an ordinary power supply sold for led-applications.

Hi,

I think the image is a collection of cut and paste images, look at the PIR???

Tom... :smiley: :+1: :coffee: :australia:

the PIR in the schematic does not have a ground to complete the signal.

EDIT ADD :

the PIR and Sound module draw very little power. they could be powered by the Arduino.
the speaker might be better with a separate power supply.

ps : if you had a second post on pirate Halloween, you should delete it. this is very well presented and has very little room for guess work.

The OP clearly did a cut and paste of unrelated objects. the idea is to put a thing there.

guess we would prefer to see
image

but my suggestion is that it is typically bad to switch the neutral (white) on 120 mains and it is safer to switch the hot (black wire)

also, I would have used the receptacle as the only 120V connection and added spade terminals and separated the two (upper/lower) receptacles by breaking off the hot (brass, and smaller slot) tab to isolate the two receptacles.
image

then you could plug in a wall-wort in the always-hot receptacle and have the second one on the relay.
one more thin, ADD a light of any sort on the 120VAC side to show power is on.

Hi all,

Thank you very much for taking the time to reply. I'll try to respond to each of the questions & comments I saw in the replies. Here is a block diagram of what I'm trying to do (with pin names):


Note 1: this block diagram doesn't show the second 12VDC output which will be connected to the relay module. I couldn't figure out a good way to include it without severely cluttering the diagram and it's not relevant to the problem I'm asking about right now.
Note 2: for the PIR issue I'm troubleshooting right now I'm powering the Arduino via USB and the relay module is not attached to power or the Arduino's analog pins. I will come back to powering and switching the receptacle once I have the low voltage side working.

koraks: The picture accurately shows how I have things connected.


The LED Driver came from Amazon (120VAC to DC 12V 1A LED Driver). I'm having trouble finding an official data sheet for it, but I will keep looking. Here is a better view:
LEDDriver
I have the "Output -" terminal on the LED driver connected to the "Input -" terminal on the DC-to-DC converter and to the GND pin on the Arduino. The "Output -" terminal on the DC-to-DC converter is connected to the GND pins on my PIR and audio board. Here's a better picture of the converter:
DcToDc
Should I be ignoring the DC-to-DC converter's Output- and using the one from the LED driver to make sure all of my low-voltage stuff has a common ground? I hadn' t heard of a fixed-current led driver, so that was not part of my parts search and I probably didn't end up getting one.

I chose to power the Arduino through the VIN pin using 12VDC because I wanted the 5V pin to power the relay module. I also found a lot of conflicting (or at least confusing) information about whether the 5V pin can be used to power the Arduino or only as an output. My understanding is that the VIN pin goes through the Arduino's regulator, which can cause the input voltage to drop, so I thought the input needed to be higher than 5V for that to work.

TomGeorge and dave-in-nj: I missed reading the forum guidelines before, but I have read them now. I have been developing the code in stages; and as you suggested I have been troubleshooting this PIR issue with code that does nothing but read the PIR and put the read-in analog value out to serial.

#define PIR_1_INPUT_PIN               A5    // PIR 1, analog input pin

int bOn = HIGH;
int triggerCount = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200); //we talk to the PC at 115200
  delay(100);

  pinMode(PIR_1_INPUT_PIN, INPUT);
  pinMode(13, OUTPUT);

  Serial.println("Starting up...");
}

void loop() {
  // put your main code here, to run repeatedly:

  int aPirValue = analogRead(PIR_1_INPUT_PIN);

  Serial.print("Pir 1 value: ");
  Serial.println(aPirValue);

  digitalWrite(13, bOn);
  if (bOn == HIGH)
  {
    bOn = LOW;
  }
  else
  {
    bOn = HIGH;
  }

  delay(500);
}

The images pasted into the diagram in my original post (other than the generic 110vac receptacle) are pictures of the actual components I'm using. The object labeled 'To PIR' is the Ethernet port I plug the PIR cable into. It is wired so that it uses 3 conductors out of the cable's 8 (5VDC, GND, and signal). I forgot that the PIR itself isn't in the diagram. Here it is - I got it from eBay several years ago and it is not clearly marked with any part number so I don' t have a datasheet readily accessible:
PIR

I can modify the design so that it switches the hot wire instead of the neutral. The receptacle I'm using is a GFCI outlet so there isn't a tab between the two outlets to break off or I would definitely take that advice. When I did plug everything in as shown in the block diagram above I had another issue with the GFCI, but I figured I would save that for another post once I make sure the Arduino side is running and activating the relays properly. For the PIR issue I'm looking into now I have the Arduino out of the box, powered by a USB cable so I can see the serial output, and running the simplified sketch above. Nothing is connected to it other than the PIR.

I haven't plugged a lamp or anything into the outlet yet, but I'm sure that house power is reaching the LED driver; I measured 110VAC going in one side and 12VDC coming out the other. The DC-to-DC converter has an LED on it which lights up and I measured 12VDC in and 5VDC out.

I chose not to power the PIR and sound module from the Arduino just due to a shortage of output pins.

bluejets: when you say the LED driver could be downright dangerous, can you clarify? Is the danger to me, my other components, or all of the above? :slight_smile:

Thanks again for all of your help, and I will try to clarify anything that I've made confusing.

Mike

Powering the Arduino with 12 volt and tapping the Arduino 5 volt to power a relay board is wrong. The Arduino 5 volt converter will not give enough current for that.

Feed the Arduino with the 5 volt You have in the build. Connect to the 5 volt pin.

Very bad guess!

This is a big problem with the Arduino project information.

The only too real real danger here is that the obsolete tutorials on the Arduino site and others misleadingly imply that the largely ornamental "barrel jack" and "Vin" connections to the on-board regulator allow a usable source of 5 V power. This is absolutely not the case. It is essentially only for demonstration use of the bare board back in the very beginning of the Arduino project when "9V" transformer-rectifier-capacitor power packs were common and this was a practical way to power a lone Arduino board for initial demonstration purposes. And even then it was limited because an unloaded 9 V transformer-rectifier-capacitor supply would generally provide over 12 V which the regulator could barely handle.

This is because the on-board regulator is essentially capable of powering only the microcontroller itself and no more than a couple of indicator LEDs. The on-board regulator might be able to power a few other things if it had a heatsink, but on the (older) Arduinos, it does not.

Powering via the "barrel jack" or "Vin" connections is asking for trouble. The "5V" pin is not by any means an output pin, if anything a "reference" pin but most certainly the preferred pin to which to supply a regulated 5 V.

So you can simply forget the on-board regulator and "Vin" and when you have a nice regulated supply of 5 V - generally from a switchmode "buck" regulator as you have - you want to convey it to where it is actually required - the "5V" pin and your other modules.

The problem specifically with the UNO and Mega 2560 is that if the PC is connected to the USB port while you are powering it through the "5V" pin, it may feed a slightly higher voltage to the PC's USB system and cause it to shut down, so you need to disconnect the "5V" pin while connected to USB.

1 Like

Non-isolated supplies can be all of the above.
Normally designed to be inside of a purpose design self contained system.
Bring anything from them into the real world and a fault results in mains supply on the low voltages.

Did someone already tell you that a PIR sensor outputs a digital signal, not an analogue value.
Leo..

Thanks for the additional replies.

Can you give me an example of a better component I could use to get from 110VAC to 12VDC in this application?

This is another thing that I have read conflicting opinions on. In my limited experience I haven't had problems with the Arduino powering the relay board, but my experience is definitely limited. I'll re-work this.

Paul_B: Are you saying that the only acceptable ways to power an Arduino Uno are by USB or by feeding already-regulated 5VDC into the 5V pin? I don't mean to be difficult or ungrateful for the advice, but that goes against a lot of what I've read. All of the 'how to power an Uno' articles list the barrel jack and Vin as acceptable alternatives.

How would you connect the PIR and audio board to the Arduino to get power from it? I thought I had an idea of how this would be done but some of the other replies I got have made me doubt what I thought I understood.

I missed replying to this earlier - I haven't made any posts anywhere else about this project.

Based on the feedback I've gotten, I've updated my design to this:


So far the only part of the udpated design I've tested is the PIR - it is reliably triggering the Arduino only when there is motion.

Not explicitly, but I kind of knew that. My final sketch is based on a project I found online for an Arduino-based animatronic controller and that design treats its PIR as an analog input. It samples the analog value as a rudimentary test to see if a PIR is present on a certain PIN. I've tried this both ways and gotten the same results.

I have not directly connected the LED driver Output- to the Output- of the DC-to-DC converter, but when I test for continuity between those two points they measure as connected. Does this mean that they already share a common ground or am I missing something?

Thanks,
Mike

Almost every day some helper explains how limited the Vin to +5 onboard converter is. It's small and it has no heatsink. Many projects work for some seconds or minutes until that tiny converter is overheated and shuts down.
There's a lot of bad "advice" given by complete amateurs out there.
Rely on @Paul_B!

Dave-in-nj already showed you one above, or are you not reading all the replies..??

I have said what I have said and - as have koraks and Railroader - explained precisely why the nonsense propagated through various Arduino topics is entirely misleading. Again, the on-board regulator is essentially only for demonstration use of the bare board if nothing else is to be "powered".

Good. Cross-posting is a nuisance as different people may end up helping with matching advice on two versions of the same project and the duplication just wastes their efforts.

Essentially any "buck" converter unless specifically and deliberately isolated, has the same ground on input and output. But it is important to run the 12 V input and ground together from the 12 V power supply, and the output 5 V and ground together from the converter to the parts requiring 5 V.

In particular, you must run 5 V and ground together from the converter to "JD-VCC" and "GND" on the relay board with the link removed, and 5 V and ground together but separately from the converter to the Arduino and then connect your control outputs from the Arduino together as a bundle with the 5 V from the Arduino to the "IN" pins and "VCC" on the relay module.

I am reading all of the replies - it's possible I missed something, however. If this is the device you meant:

then I don't see it helping my project. My goal is to have one power cord - the 110VAC PC power cord - running from a house outlet to my project box and then convert to any other voltages I need internally. All of the other jacks on the outside of the box are for power output only to various parts of the animatronic I'm building (lights, motor, speaker). I don't want the animatronic to have multiple power cords coming into it. If this design is unrealistic then I'll reconsider, but I don't want to give up on that goal unless I have to. The boxy part of that adapter also just won't physically fit in the project enclosure I'm using if I were to split the 110VAC coming in to go to it. I was hoping for a suggestion of a small converter that I could drop in in place of the LED driver I'm using now.

OK. I did not mean to impugn your knowledge; it's just hard for me, an amateur, to filter the nonsense from the valuable advice.

I can remove the JD-VCC/VCC jumper on my relay module and connect JD-VCC and GND to the output on my converter. I know how to connect the control outputs from the Arduino (A0-A3) to the relay module's IN pins, but can you please clarify how I connect the 5V from the Arduino to VCC on the relay module? Based on the discussion in this thread I was going to have the Arduino's 5V pin connected to the output of the converter to power the Arduino, so where would another wire from the Arduino to the relay module's VCC be connected on the Arduino end?

Thanks once again to everyone for all of the help,
Mike

If you have an actual duples receptcle in you enclosure, you can turn that into two separate receptacles.
One would be hot and powered by the one cord into your box.
The other would be plugged into the hot receptacle and the second receptacle would be powered thruogh the relay.