Hi everyone, I am a newbie in arduino and I wanted to make a pressure sensitive insole project. Currently I know how to deal with 1 force sensor using the code and set up below (created by esp32io.com). I wanted to alter the code for 8 force sensors instead of 1, where do I start? Thank you very much!
#define FORCE_SENSOR_PIN 36 // ESP32 pin GPIO36 (ADC0): the FSR and 10K pulldown are connected to A0
void setup() {
Serial.begin(9600);
// set the ADC attenuation to 11 dB (up to ~3.3V input)
analogSetAttenuation(ADC_11db);
}
void loop() {
int analogReading = analogRead(FORCE_SENSOR_PIN);
Serial.print("The force sensor value = ");
Serial.print(analogReading); // print the raw analog reading
if (analogReading < 10) // from 0 to 9
Serial.println(" -> no pressure");
else if (analogReading < 200) // from 10 to 199
Serial.println(" -> light touch");
else if (analogReading < 500) // from 200 to 499
Serial.println(" -> light squeeze");
else if (analogReading < 800) // from 500 to 799
Serial.println(" -> medium squeeze");
else // from 800 to 1023
Serial.println(" -> big squeeze");
delay(1000);
}
Ah - this must be project season. I am assuming you have been set this as some sort of assignment from some institute of education.
This is because it is a regular problem that crops up on this forum.
On the hardware side you simply duplicate that arrangement using other pins. However, that means having a lot of wires going into the insole. So you are best to make it a portable battery powered system.
On the software side you could duplicate the code using different variable names for each sensor. But that would be dumb.
A much better way would be to learn how to use arrays to define with an index what set of inputs you want to use. Then use a "for loop" to iterate through your system.
Hi Mike! Thanks alot for your suggestion! (Yes it is indeed a school assignment). I will look up how to use arrays aswell as the portable battery powered system… I will definitely update you on where I get up to soon!
In the meanwhile… do you happen to know if I could directly connect a force sensitive resistor to this circuit (as shown on the diagram in the original post - which does not seem to be working very well atm) or do I need to attach something in between to translate the signal from a pressure reading to a voltage (resistance) reading?
Thank you very much Mike!
Well it was a Fritzing diagram and that never tells the true story. Basically because it gives no idea of what chip it is, nor does it label any of the pins connected to it.
If indeed you are using red to represent 5V and black as ground and yellow as signal then it should work.
However I have no idea as to what you exactly mean by not working very well. Does this mean intermediately, or the readings fluctuating?
Solderless bread board if indeed what you have is notorious for making bad or intermediate connections.
You could also try changing that 10K resistor try 22K and the 1K to see which is better.
it is indeed fluctuating periodically on a breadboard. Will try using different values of resistors! Do you think I could add a capacitor or another component (somehow) to smooth out the noise?
Thanks alot.
I have attached the FSR data sheet above. Are there any specific values I should look out for here? I am also using a ESP-32-S2-MINI-2 for this project.
I’m not too sure if I am using the same ESP and FRS as the tutorial which might be the problem, as the tutorial did not give any specific details of what kind of ESP32 nor the FRS that they are using.
No, I doubt it. It sounds like an intermittent connection on the solderless bread board. As I said they are prone to this.
The change in resistor is only to see if the range of readings is improved. Ideally the resistor should be half the value of your sensor when it is in the rest position. That is why Jim keeps asking about the data sheet for the sensor. That will tell you.