Hi there, so this is more of a double question. First of all some background info of what i'm trying to achieve. i want to be able to roll a ball past some sensors, each triggered a different sound from seperate speakers, with the last sensor triggering a new sound in all speakers. the set up consists of 5 proximity sensors (4 PNP, 1 NPN ), 4 DFPlayer Mini devices, and an arduino. This all works with a one senor setup, but im not sure how to glue it all together.
So my questions are:
Can you even control these 5 sensors simultaneously?
can you control 4 DFPlayer simultaneously via SoftwareSerial
You aren't new, but you seem to have forgotten how to use the forum. A picture of a hand drawn wiring diagram is usual.
How far apart are the PIR sensors? These are very gross measurement devices, you will need lots of seperation in order to 'hear' them individually.
Get rid of the delay and read about state machines and/or how to do multiple things at once. Those articles are in the Tutorials section.
Good luck.
Microcontrollers like Arduino can read multiple digital inputs in a loop just like you’re already doing with the digitalRead() calls. The main limitation comes from timing, responsiveness, or polling frequency, but for proximity or motion sensors (like PIR or PNP/NPN sensors), polling in a fast loop is usually more than sufficient.
I have a couple of ideas but I think the easiest if not the least expensive, would be to use one Arduino to read your sensors as a central controller to accessory Arduinos, one for each DFPlayer. Just have the accessory Arduinos poll an I/O for a digital signal from the central one and play the thing you want.
As for outputting each one or all together to the same amplifier, maybe some relays or even a custom audio cable, but I'd have to see all the audio gear to come up with something.
Impossible to say if we don't know what type of sensors they are. You say "proximity" but that could mean various things. @sonofcy thinks you mean PIR sensors. @xfpd thinks you mean ultrasonic sensors. Are either of them correct?
If PIR sensors are correct, the Arduino can't control them at all. There are often one or two small potentiometers on the PIR's PCB so that a human can control the sensitivity and on-period. But there's nothing the Arduino can control.
If ultrasonic sensors are correct, the Arduino can control when the sensors take a reading. It is possible for the Arduino to tell all sensors to take a reading simultaneously, but that would be pointless because the Arduino can't read the results from all 5 sensors simultaneously. Also it might cause incorrect readings because the sensors might detect each others audio signals.
Good point, I didn't read the code that was posted yet, it seemed premature.
But PIR sensors don't detect proximity. They detect warm objects moving in their field of view. They cannot tell you how far away the object is. A large warm object moving far away would be detected the same as a small warm object moving nearby. (I'm explaining this for @countessaflufforossa's benefit, of course.)
Directional or not, at least HC-SR04 sensors can be accurately described as proximity sensors: they sense the distance between the sensor and the object.
( translated)
If by "simultaneously" we don't mean "at the exact same moment", but rather "together" on a single controller unit, then yes, it can be done. Of course, the program handles one thing at a time in (rapid) succession, so it becomes more of a software design issue than a hardware limitation.
If you're comfortable with basic electronic assembly, you could control multiple DFPlayers without using all those pin pairs by using just 4 pins to drive an external decoder:
Ok, thanks for the link. It would have to been good to have that in the original question.
"PIR" normally stands for Passive Infra-Red which is a sensor which does not emit any IR light itself (hence "Passive"), but detects IR light given off by warm objects.
Your sensors are IR but not passive, they emit a beam of IR light which reflects off objects and the sensor then detects that reflected light.
So to answer your original question: no, the Arduino cannot control these sensors, there is nothing to control.
EDIT: I suppose the Arduino could control them by switching their power on and off. Is that what you meant? If so, why is that needed?
( translated)
I’d say that by “control” he means “reading” or “managing the readings” of five sensors. The ones mentioned might also require a pull-down resistor on their output. However, we don’t have any information about the NPN sensor (which he mentioned at the beginning).
What sort of ball are we talking about, wooden, stainless steel ball bearing or what? Also how big is this ball?
This drip drip of information is not very helpful.
I once wrote a series of three articles about detecting balls and making sounds using the GraviTraks system for the MagPi magazine. This is the first one:-
You might see part 2 come up at the end of the video. That was all about using lighting effects triggered by the balls. Part 3 was about combining both lights and sound but I couldn't get a video good enough to post.