void setup() {
Serial.begin(9600);
}
void loop() {
int check = digitalRead(A0);
if(check == HIGH){
Serial.println("TOUCHED");
}
else{
Serial.println("NOT TOUCHED");
}
delay(50);
}
I wanted to know whether softpot is touched, but this outcome seems not what I expected.
It prints out the TOUCHED words even though I didn't even touched the softpot.
Can I please know the way that I can check if softpot is touched
What softpot?
Wired how exactly? (schematic - no Fritzing crap, even crappy hand drawn schematic is so much better than that).
Pot - that implies analog output. Why are you taking digital readings rather than analog readings?
And please post code between code [/] tags. Makes it much more readable.
Thanks for the reply
I used softpot membrane potentiometer made by 3M.
I connected 5V, GND, and A0 analog pin directly to the softpot.
I just wanted to check whether it was touched or not, like true or false.
When it is not touched, the serial prints out close to 1023 value.
But I want to print out the "softpotReading" value when it is touched as you see in the image.
Can't I get the digital value of softpot membrane potentiometer?
void setup() {
Serial.begin(9600);
digitalWrite(A0, HIGH);
}
void loop() {
int softpotReading = analogRead(A0);
int check = digitalRead(A0);
if(check == HIGH){
Serial.println("TOUCHED");
}
else{
Serial.println("NOT TOUCHED");
}
}
Please copy/paste code and place it between code [/] tags.
Images are best added to the body, see this image guide on how it works.
The softpod image from #2:
First thing to do would be to determine the values of touch:
reading = analogRead(A0);
Serial.println(reading);
Now you know the min/max values for touch/not touch. So to make it a digital reading you can simply do something like this:
reading = analogRead(A0);
if (reading < 1000) touched = true;
else touched = false;
Change the value of 1000 to something sensible based on your experiments.
Your digital pin will return LOW when it's below half or 2/3 of Vcc (I forgot the actual number - see spec sheet if you want to know it exactly). So that'd be an analog reading of <512 or <666. The point is, as long as your softpot keeps it above that number, you'll see HIGH on the pin.
I appreciate for your advice.
It really helped me.