I am trying to determine whether two or more analog input/outputs by holding hands are connected to each other by looping through them (on Arduino UNO). The problem seems to be that the voltage is too low.
For this setup, would an op-amp work to drive up the voltage range? As the analog pins are both in- and outputs, I'm not sure if this will work.
It works perfectly when I connect the wires, although I still get ~550, while you'd think it shouldn't have any resistance so should be 0.
First I set the first five analog inputs to be an input, and write a high voltage to them.
Then, every loop:
- Set A0 as an output and drive it low voltage
- See which other pins are now low voltage -- they are connected to A0
- Return A0 to be an input.
- Set A1 as an output and drive it low voltage
- See which other pins are now low voltage -- they are connected to A1
...
When A4 has been reached, repeat.
Thanks in advance!
static const uint8_t analog_pins[] = {A0,A1,A2,A3,A4};
void setup() {
Serial.begin(9600);
for (int thisPin = 0; thisPin < 5; thisPin++) {
pinMode(analog_pins[thisPin], INPUT);
analogWrite(analog_pins[thisPin], 1023);
}
Serial.println("starting up!");
}
void loop() {
for (int thisPin = 0; thisPin < 5; thisPin++) {
pinMode(analog_pins[thisPin], OUTPUT);
analogWrite(analog_pins[thisPin], 0);
delay(200);
for (int checkPin = 0; checkPin < 5; checkPin++) {
if (checkPin != thisPin) {
int curCheck = analogRead(analog_pins[checkPin]);
Serial.println(curCheck);
if (curCheck < 900) {
Serial.print("PINS CONNECTED: ");
Serial.print(thisPin);
Serial.print("&");
Serial.println(checkPin);
}
}
}
delay(200); // delay per pin check
pinMode(analog_pins[thisPin], INPUT);
analogWrite(analog_pins[thisPin], 1023);
Serial.println("...");
}
Serial.println("===");
delay(2000); // delay between rounds
}
