How to read out information from a force sensitive sensor

Hey guys.

I am really frustrated right now. I am working on a project for university. For this project I want to create sound with a piezo, while pushing a self built force sensitive sensor.
I tried programming all day, but nothing is working … So I hope somebody can help me.

Right now my main goal is just to read out the information from the force sensitive sensor. I want the serial monitor to show the resistance values in the beginning without pressing it and then I want to watch it decreasing… I hope you know what I mean.

As stated above, I want to connect sensor and piezo. While the sensor is pushed, the piezo should make special sounds…
This is the code I got right now:

int PressurePin = A0;
int piezoPin = 12;
int length = 15;
char notes[] = "ccggaagffeeddc ";
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
int tempo = 200;
void playTone(int tone, int duration) {
  for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(piezoPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(piezoPin, LOW);
    delayMicroseconds(tone);
  }
}

void playNote(char note, int duration) {
  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };

  for (int i = 0; i < 8; i++) {
    if (names[i] == note) {
      playTone(tones[i], duration);
    }
  }
}


void setup() {
  pinMode(piezoPin, OUTPUT);
    for (int i = 0; i < length; i++) { //plays activation sound 
    if (notes[i] == ' ') {
      delay(beats[i] * tempo); // rest
    } else {
      playNote(notes[i], beats[i] * tempo);
    }

    // pause between notes
    delay(tempo / 2); 
  Serial.begin(9600);
 pinMode(PressurePin,INPUT);
}}

void loop() 
{
  PressurePin = analogRead (0);
  Serial.println(PressurePin);

if (PressurePin > 15)
{ 
  tone (12, 800, 200);
  delay (200);
  tone (12, 1200, 200);
  delay (200);
  tone (12, 800, 200);
  delay (200);
  tone (12, 1200, 200);
  delay (200);
 
}

 else {

 noTone(12);
}
}

But the serial monitor doesn’t show ANY values… just zeros. Even if I attach a force sensitive sensor I bought to the circuit, it does not work…

I will shortly describe, how I built the circuit:

I connected the piezo with a 220 ohms resistor directly to pin12, and the other wire to ground

I included my self built sensor (HOW TO GET WHAT YOU WANT) as follows:

I put one wire to 5V, to power the sensor, I attached the other wire to my breadboard. From there i connected the sensor with a 10k resistor to ground (to create a voltage divider) and took another wire to A0.

All in all my project already made sounds! But right now I am not able to receive any signals to my serial monitor, while pushing the sensor.

If my programming, or my circuit is wrong please tell me, I hope somebody can help me…

Have a nice one and many thanks in advance!

Simon

The biggest problem that I can see is that you didn't enclose your code in [code]code tags[/code], so it and everything after it is now in italics, plus the code here is corrupted where the italics starts:-

if (names == note) {

Code tags not only make it easier to read and avoid corruption, but also make it easier to copy the code for pasting into an IDE and testing/verifying.

If you're unsure about code tags, read this, paying particular attention to item #7:-
How to use this forum - please read.

Edit: If you edit your opening post and add the code tags, it will get rid of those hard-to-read italics. My eyesight isn't good, and is struggling to read even the description of the problem.

(deleted)

2392402422402402432422412422422432412422432432413496327107087017057285083871516323942257561862267266163453005631121001061259410910911712911410510510310212110499104109111106106991051121051031291261191161161131061121149911612011699105110108116109104122130123118125117123124118118119121125118120117121127130115131137129132136146140131133131138134137143144137143145134134142135136144139137122133128124129120115116111112109113116114111113112111112109113106110107103108110113107112115115

Just this column of numbers... ANd if I push my sensor nothing happens ...

spycatcher2k:

void setup()

{
Serial.begin(9600);
}
void loop()
{
Serial.println(analogRead(A0));
delay(100);
}




Can you try this and tell us what you see.

I was just typing to say the same, but aborted. :slight_smile:

SimzZafari:
2392402422402402432422412422422432412422432432413496327107087017057285083871516323942257561862267266163453005631121001061259410910911712911410510510310212110499104109111106106991051121051031291261191161161131061121149911612011699105110108116109104122130123118125117123124118118119121125118120117121127130115131137129132136146140131133131138134137143144137143145134134142135136144139137122133128124129120115116111112109113116114111113112111112109113106110107103108110113107112115115
Just this column of numbers... ANd if I push my sensor nothing happens ...

Are you sure you're using 'println()' and not just 'print()'? It shouldn't look like that with 'println()'

Edit: It should look more like this, with each value on a separate line:-

463
463
462
462
461
461
460
459
459
458
457
456
456
455
454

(That's the result of running spycatcher2k's code, with nothing attached to A0.)

Edit2: And the values in your's do appear to be changing. They start in the 200s, then appear to rise.

(deleted)

Println() gives this :
162
163
154
162
159
153
157
163
161
164
168
165
168
166
163
164
161
167
160
155
160
168
166
165
167
169
168
163
160
157
159
162
161
163
167
616
588
584
581
614
599
588
635
527
262
28
117
69
69
93
63
95
73
94
82
78
76
77
70
101
90
94
83
80
81
85
96
104
120
130
116
109
109
100
98
99
85
100
107
95
99
101
103
104
106
113
109
111
105
107
112
105
102
114
109
115
120
124
125
129
125
119
114
120
124
120
122
126
125
137
136
129
127
131
130
135
134
125
134
132
125
128
130
129
124
128
124
127
135
130
123
127
132
139
141
141
142
133
120
120
135
136
126
126
126
127
112
109
112
101
103
116
109
103
117
112
114
122
113

Pictures will be posted in a second.

Another interesting side note may be: If I attach my multimeter to the sensor, I receive changing resistance. So the sensor is definitely working...

(deleted)

@spycatcher2k, there's no point in us both continuing to post since we're saying the same things. I'll leave you to it.

After changing it to 1k it prints out this (when the numbers get in the 100's, I pushed the sensor):

2
2
3
3
1
0
1
1
0
1
1
1
1
1
0
1
1
3
1
2
1
2
2
2
3
3
3
3
3
4
3
3
3
3
108
296
350
432
485
505
520
510
521
481
497
519
526
520
528
525
505
508
516
537
550
524
458
249
0
0
2
4
4
7
5
6
4
4
3
3
3
2
4
4
5
3
3
5
4
4
4
5
5
8
6
6
6
6
5
5
6
5
5
4
3
3
5
4
3
4
6
6
5
4

(deleted)

YES! IT WORKS!!! THANKS!!!

But nevertheless it is somehow a bit strange, because first when the project was working, the serial monitor printed just high numbers and when i put pressure on the sensor, the values dropped. Now they are rising…