I'm working on this project where I need some Capacity Sensors connected to an Arduino UNO.
I 've decided I will need to execute the same 'paths' with some of these Sensors.
Is it possible to hook up 2 sensors to one digital input and no matter which of the two is pressed the reading will be the same on my digital pin?
Please provide some more information on the sensors you're about to use.
Also please explain why you want to use a single GPIO for two sensors. Why not use two GPIO's and combine the results in your software?
To give a general answer at this point: no, it's generally not possible to have two sensors use the same GPIO on your microcontroller. A more nuanced answer is possible, but generally it still boils down to "it's not worth the trouble, just use two pins".
Thank you for reaching out and providing more information. I appreciate your time and assistance. Currently, I'm utilizing these sensors (https://grobotronics.com/capacitve-touch-sensor-switch-module.html). To streamline the process, my goal is to connect two of these sensors to a single pin. This setup allows me to place them in different locations for user convenience. The objective is for both sensors to trigger the same functionality when activated by a user. The reason for connecting two sensors to the same pin is to efficiently manage pin usage, especially since I'll have several pins, some serving identical purposes.
I've already attempted this setup. I connected one sensor to pin 2 and two sensors to pin 3. However, the two sensors connected to the same Arduino pin aren't functioning when pressed.
#include <Uduino.h>
Uduino uduino("uduinoButton");
void setup() {
Serial.begin(9600);
pinMode(2, INPUT); // Setup for sensor connected to digital pin 2
pinMode(3, INPUT); // Setup for sensor connected to digital pin 3
}
void loop() {
// Read and check the state of the sensor connected to pin 2
int sensorState2 = digitalRead(2);
if (sensorState2 == HIGH) {
Serial.println("Sensor 2 touched");
}
// Read and check the state of the sensor connected to pin 3
int sensorState3 = digitalRead(3);
if (sensorState3 == HIGH) {
Serial.println("Sensor 3 touched");
}
delay(100); // Delay to help with debouncing and prevent too many messages
}
(Edited by @J-M-L to replace the wrong code tags '''
by 3 backticks)
Ok, I see what you mean. Assuming that these sensors output a logic HIGH when active, you could combine the outputs of several of these sensors with an OR port. A simple way of making one is using two (Schottky) diodes:
I like to use BAT54C for this purpose since they're two diodes with a common cathode in a small package.
This will keep repeating the code within the if-block as long as the input is HIGH. I suspect that's not what you want. But it's unrelated to the question how to hook up the touch sensors.
Depending on the sensor type you can get an AND or an OR connection of the digital signals of both sensors, or with analog capacitive sensors you can not get any reasonable result.
I may not have fully grasped your initial response, possibly due to my limited knowledge. To implement your suggestion effectively, would I require an additional gadget, or can this be achieved solely through coding in my sketch?
Yes. Two of these: Schottky diode - Wikipedia
They come in many shapes, forms and sizes. Any small-signal Schottky diode will do.
PS even a generic silicon diode (e.g. 1n4148, 1n4001 etc.) will likely work, but will drop a little more voltage. This will become a problem if the sensor outputs a 3.3V signal and you're trying to read it with a 5V Arduino. That's pretty much the only situation I can think you really need a Schottky diode in particular.
i use 5V so i believe that i will be ok regarding that. I just don't know how to make your suggestion. How to connect the cables. I will need to search more about this. Really thanks for your time.
Yon need a pull down resistor R1
Do you need a picture diagram?
Yeah, I think that could be nice. Another idea I'm tossing around (and maybe it's a completely different approach) is whether it's possible to set up a capacitive sensor to pick up signals from two different spots. Here's the gist: I've got a metal part hooked up to my sensor. When I touch it, the sensor picks it up and sends a signal. So, what if I connect two metal parts, each in different places, to the same sensor? Could it then detect if either one is touched? That way, I'd only need one sensor for both users, cutting down on cables and making things simpler.
It depends how far apart the metal parts are.
The wires connecting the metal parts to the sensor board will also act as capacitive pickups
Yeah i tried that it you are correct. But why? Can i do something to fix it?
Yes but it would require building extra hardware and in the end it will just be cheaper to buy two sensor modules.
Really thanks for the image. So i must connect the GND between the two signal cables if i can see correctly. I will try it soon.
Yes the Uno GND must connect to BOTH sensor board GNDs
So i must connect GND to both sensors' GND pins, and also connect GND between the two signal lines (the one you indicated in the image on the Dn line).
What do you suggest I use for the two small black and one yellow parts? Are they Schottky diodes?
The black things are 1N5817 schottky diodes. The have a silver band on one end. Make sure you connecte them as shown.
The yellow part is a 10K ohm resistor. See the colors bands: brown, black, orange, that's 10K