Pages: [1]   Go Down
Author Topic: Piezoelectric sensors and 4051 mux  (Read 1008 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everybody!

I'm buliding a drumpad with piezoelectric sensors, which I know is a really popular project, but I still have problems with multiplexing: sometimes (mainly when the hit is over a certain strenght) values from a piezo influence the others values read from the same mux

This is my setup

4 piezo with 1M res in parallel connected to the first 4 inputs of a 4051 mux, other mux inputs are grounded

I have 2 circuits like the one above, each mux's output goes to an arduino analog pin.

3 digital pins from the arduino go to both address pin of the muxs

all the unused analog arduino pin are grounded

and these are relevan parts of my arduino code. I tried to play with delays in between different analogRead and also between different writing to the address pins of the mux, but no success...

Code:
  for (int i=0; i<4; i++)
  {
    setMuxAddress(i);

    sensorValue[i] = analogRead(A0);
    delay(delReadAnalog);
 
    sensorValue[i+4] = analogRead(A1);
    delay(delReadAnalog);
   
  }

void setMuxAddress(int var)
{

  digitalWrite(2, bitRead(var, 2));
  delay(delSetMuxAddress);
  digitalWrite(3, bitRead(var, 1));
  delay(delSetMuxAddress);
  digitalWrite(4, bitRead(var, 0));
  delay(delSetMuxAddress);
}





Thanks in advance!
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 627
Posts: 34246
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
and these are relevan parts of my arduino code.
I doubt it.

Code:
delay(delSetMuxAddress);
Is not needed, it fact it is rather detrimental to the performance.

Any supply decoupling on the chips?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi thanks,

so ok, I took away delay(delSetMuxAddress) and added a decoupling cap (0.01u and 1u) as close as possible to the supply/ground pins of the 4051 but still when I hit one piezo over some strenght other values are affected... and I also noticed that this happens differently with different mux inputs. Some are more robust (I need to hit really strong for having other signals affected) while with others a much lighter hit would affect other signals

 I'm planning to put a 5v zener diode for not to get from the piezo voltages above that value. Could this be the issue?

Quote
I doubt it.

this is the rest of the code

Code:
//4051 mux piezo test

//int delSetMuxAddress = 1;
int delReadAnalog = 8;

int sensorValue[8];        //4 values get from the mux

void setup() {
  // initialize serial communications at 9600 bps:
  for (int i=0; i<4; i++) sensorValue[i] =0;
  for (int i=0; i<10; i++) pinMode(i, OUTPUT);
 
  Serial.begin(9600);
}

void loop() {
  // read the analog in value:
 
 
  for (int i=0; i<4; i++)
  {
    setMuxAddress(i);

    sensorValue[i] = analogRead(A0);
    delay(delReadAnalog);
 
    sensorValue[i+4] = analogRead(A1);
    delay(delReadAnalog);
   
  }
 

     
  Serial.print(sensorValue[0]);
  Serial.print('*');
  Serial.print(sensorValue[1]);
  Serial.print('*');
  Serial.print(sensorValue[2]);
  Serial.print('*');
  Serial.print(sensorValue[3]);
  Serial.print('*');
  Serial.print(sensorValue[4]);
  Serial.print('*');
  Serial.print(sensorValue[5]);
  Serial.print('*');
  Serial.print(sensorValue[6]);
  Serial.print('*');
  Serial.print(sensorValue[7]);
  Serial.println();



   
               
}

void setMuxAddress(int var)
{

  digitalWrite(2, bitRead(var, 2));
  //delay(delSetMuxAddress);
  digitalWrite(3, bitRead(var, 1));
  //delay(delSetMuxAddress);
  digitalWrite(4, bitRead(var, 0));
  //delay(delSetMuxAddress);
}


I use the serial print for displaying the signals with an external software.. 
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 627
Posts: 34246
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm planning to put a 5v zener diode for not to get from the piezo voltages above that value. Could this be the issue?
It could, but also the input impedance could be the trouble and there is not much you can do about it.

Again:-
Code:
sensorValue[i] = analogRead(A0);
    delay(delReadAnalog);
 
    sensorValue[i+4] = analogRead(A1);
That delay is doing absolutely nothing for you. If you want some time for the reading to settle use:-
Code:
sensorValue[i] = analogRead(A0);
    delay(delReadAnalog);
   sensorValue[i] = analogRead(A0);
    ...........
That is read twice with a delay in between. However I don't think that is your problem.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok, thanks for your advice...
Logged

texas
Offline Offline
God Member
*****
Karma: 27
Posts: 862
old, but not dead
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you have anything to limit the voltage coming out of the piezo?  It could be 10s or even 100s of volts into an open circuit.  The mux only has so much isolation between the channels so a large signal will always bleed into the other channels.
Logged

Experience, it's what you get when you were expecting something else.

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi!

Yes, that is something I'll try, as soon as I receive the 5v Zener diodes I've ordered. But I was displaying the signals while trying the system and the strange thing is that with some piezos the signal would show up in other channels even though I hit it lightly... But I'm gonna write back after I get those diodes...



Logged

texas
Offline Offline
God Member
*****
Karma: 27
Posts: 862
old, but not dead
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you have some "ordinary" diodes laying around, you could put them in so they clip the piezo signal at ~600mV by routing the excess to ground when they conduct in the forward direction.  Of course you'll have to account for it in the arduino when you read the pin value with the ADC.  This should help greatly with crosstalk on the channels.  Like I said, just try it on one piezo.  This is the one you hit to test it of course.  Your 1M resistors are in series (piezo->resistor->ADC pin), not parallel right?
Logged

Experience, it's what you get when you were expecting something else.

Pages: [1]   Go Up
Jump to: