I'm using a touch sensor to use for if statements but when used two if statement it doesn't work, it starts printing "right" from time to time without me even touching as intended but printing "left" works fine when touched or vice versa. It works when when i only use one touch sensor in one if statement. how to solve this or is something wrong in my code?
code here:
''''''''''
#define touchpin1 T8
#define touchpin2 T9
int touchvalue1;
int touchvalue2;
const int threshold = 10;
void setup() {
Serial.begin(115200);
delay(1000);
}
void loop() {
touchvalue1 = touchRead(touchpin1);
touchvalue2 - touchRead(touchpin2);
Serial.println(touchvalue1);
Serial.println(touchvalue2);
if (touchvalue1 < threshold) {
Serial.println("left");
delay(500);
}
if (touchvalue2 < threshold) {
Serial.println("right");
delay(500);
}
}
''''''''
output here:
Welcome. Both your code and output are improperly posted. Please read:
See also FAQ - Arduino Forum for general rules on forum behaviour and etiquette.
Hello,
Welcome to the Arduino Forum.
This guide explains how to get the best out of this forum. Please read and follow the instructions below.
Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is fru…
You left out other details, too. Like, what board you are using.
Where are T8 and T9 defined? Those are not standard pin numbers on any Arduino I know of. Thus, I suspect maybe you didn't post the entire sketch.
guix
November 20, 2022, 9:32pm
3
Welcome,
Don't you see a mistake in the second line ?
touchvalue1 = touchRead(touchpin1);
touchvalue2 - touchRead(touchpin2);