Designing a pressure sensor using Velostat

In the previous post I designed a circuit which was supposed to read in when pressure was applied to a custom sensor made from velostat.

The first post on the Piano conversion

I made a sensor out of some single sided FR4 printed circuit board material, some foam tape, two pieces of wire, a small 1 cm x 1 cm piece of velostat and some sticky tape!

Custom Pressure Sensor using Velostat

This is just a prototype and may not be my final version of the sensor. I wanted to see how well velostat worked and how it would behave. It seems to work really well!

I found from measurements with my multimeter that when the pressure sensor is not touched the resistance across the wires is 30 kΩ. When pressure is applied it drops to 1 kΩ. That should be more than good enough for the purposes of detecting a key-press!

The constructed pressure sensor

Next the PCB designed in the previous post was etched, drilled and populated. It etched well and I populated it with the designed components:

The Underside of the PCB 
The topside of the PCB with components

I then wrote some quick test code for the arduino because I’m leaning towards using an arduino for the microcontroller:


Pressure Sensor test Code
For Electronic Piano
(c) A. Lang 2016


// These constants won't change. They're used to give names
// to the pins used:
const int analogInPin = A0; // Pressure Sensor connected to A0

int sensorValue = 0; // value read from the pressure sensor via the amplifier stage
float outputValue = 0; // value output to the Serial port

void setup() {
// initialize serial communications at 9600 bps:

void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);

// print the results to the serial monitor:
Serial.print("sensor = " );

// wait 10 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:

The code is very similar to code I had written before – what is it with me and pressure sensors at the moment! I then uploaded the code to the arduino and tested it – It didn’t work as planned – I may have been a little disappointed at this point….

I then thought about my circuit and looked at the schematic:

The original Key Press schematic

I realised I had made a mistake. I didn’t account for how the velostat would behave in terms of it’s resistance. I thought it would have a resistance of around 1 kΩ and vary….it doesn’t it’s resistance is 
30 kΩ and varies down from that when pressure is applied. Because of this I need to tweak my circuit from behaving as a two stage buffer to a simple analogue comparator and buffer. Luckily it won’t be too hard to change things!
Here is the new circuit:
Add caption
The Key Press Schematic Version 2 

The new circuits works in a similar fashion as the previous one. The velostat pressure sensor makes up a voltage divider. The output of the voltage divider is connected to an analogue comparator made with the first op-amp in an LM358 dual op-amp IC. The negative input has a 2.75 V reference set by the 8.2 kΩ resistor and the 10 kΩ resistor. The output of the 1st op-amp is then connected to a buffer amplifier with a gain of two and then the output is connected to a FET and an LED. The output will be sent to the ADC of the micro-controller which will probably be an Arduino.

To test the circuit I removed a 10 kΩ resistor and then added a 7.5 kΩ resistor (because I couldn’t find an 8.2 kΩ resistor). Here is a photo of the modification:

Here is the modified PCB layout although I probably won’t etch this board again. I’m going to re-design it to use surface mount components and be a smaller form factor. It would be nice if each board fit snugly under each piano key.

The New Key Press Layout
I then connected the circuit back up to the arduino and pressed the sensor! It worked. The LED lit up – although I wish I had used a brighter LED…but SUCCESS!! So sweet...

Here is a graph I made from the serial monitor results. It looks very similar to the simulated oscilloscope trace from the first post!

The results from the serial monitor

So now we have a valid method of reading key presses we need to scale things up – and shrink a few things down. I will redesign the key press PCB layout to use surface mount components to take up as little room as possible. Then we need to look at multiplexing all of the signals together…and for that I’m going to use the 74HC4076 integrated circuit breakout board.

That’s all for now people – take care!

Converting an upright piano to an electronic midi piano

The Manchester Hackspace has recently moved.  When the move occurred there were two old upright piano fortes found in the corner of the new place…I asked to keep them!  I have been meaning to attempt a conversion from an acoustic mechanical piano to an electronic one for a very long time. Tuning my old walnut cased iron framed piano is becoming too difficult.  I miss being able to play in tune and with other instruments.  I also seriously miss being able to compose music and I used to use midi extensively to achieve that.  I haven’t the space to write, play and record every instrument….so instead I used to use midi software on an external computer and have that record, notate and sequence the different parts to make create my opus!  Years ago I had access to an Atari ST 520FM which had built in midi ports – it made this very easy, I also had access to a Clavinova CLP-360 Yamaha electronic piano.  It was awesome and I miss it dearly…

So rather than let my creative talents go to waste I plan on tuning one of the pianos up as much as possible and restoring it to as near working condition as possible.  This can then be kept for posterity or donated to a worthy cause…It was looking a little shabby when I found it but I have cleaned it up and opened up the panels:

Here are some photos of the piano:

A classic Upright Piano with the covers off!

The iron frame and the strings

The pedals, the sustain has definitely seem some action!

Another side shot of the slightly…better piano!

There are actually two pianos physically they look very similar but one was in much better shape than the other.  Here is a video of the better one…One of the D flat keys does not have a bridal strap and so won’t play or return.  I’m going to replace that strap but other than that it’s got a nice action and is very easy to play…better than my own!  It was however horribly out of tune…

I have a piano tuning kit I bought off ebay for doing my own tuning so I broke it out and set to it. Tuning a piano is an art…it’s difficult and takes skill and practice.  I did get it mostly in tune, some of the higher and lower notes beat me and I will spend a bit more time on it.  I am jealous of how easily played this piano is…my own keys are much stiffer and harder to play…mine also is in B flat…this piano tuned to A (440 Hz) without too much issue.

Here is the piano now tuned…hopefully it sounds better! EDIT – I haven’t got a video of the tuned piano to share yet – I will upload one soon.  The internet needs more of my poor piano playing skills shared!

The plan with other piano is to remove the hammer action and strings and place some sensors underneath the keys. The sensors will connect to a microcontroller which will then send out midi data which can be used to drive a midi based synthesizer which will in turn be connected to an audio amplifier and a couple of speakers mounted inside the cabinet. The benefits of doing this are:

  • The piano will always be in tune!
  • A midi synthesizer can produce thousands of different voices – a whole orchestra and more!
  • The piano can be used as a midi Jukebox and a band in the box.
  • It is a great excuse to investigate touch pressure sensor technology.

Here is the current plan in a diagram

There are many aspects and parts to the project which will need careful thought and consideration.  I don’t want to lose the piano’s playability. If I remove the action – the mechanical part of the piano which converts the key press to strike a note the piano won’t play as well. Here is a video I found on youtube which shows how a piano key functions:

I think in order to make this work it will be necessary to add a spring mechanism to where the key would normally pivot the action mechanism to get the key to return to it’s original position. I am not great at mechanical engineering – here is my chance to improve!

It will also be necessary to sense the note being played. Most electronic pianos have a maximum number of keys being able to be played at the same time – this is known as polyphony.

An explanation on Note Polyphony

It would be nice to be able have at least a 32 note polyphony without any noticeable lag or delay. I’m not going to be playing pieces like this but being able to play 32 notes a once puts this device in the category of a reasonable electronic piano.

So lets recap the requirements of the input section:

  • Sense at least 32 simultaneous key presses
  • record how long each note was held for 
  • record how hard the note was pressed

To do this we will need a pressure sensor which can easily be built and placed underneath the key of the piano.

I recently took some inspiration from this project:

Liam used a sensor material known a velostat. It is a very interesting material which converts pressure into an electrical signal – it’s electrical resistance changes as pressure is applied. I bought some from Proto-Pic

Velostat from Proto-pic

My plan is to combine the velostat into a simple resistive divider circuit which is then connected to the analogue input of a microcontroller and use this to ‘sense’ the note or notes being played.

A piano has 88 keys! If we want to sense them being played we need a way of reading in 88 analogue inputs. An arduino has six analogue inputs….an arduino mega has a few more but still not enough! We could use multiple microcontrollers but that makes things awkward and expensive as we need to then to synchronize them all…yikes!

I think this will require some analogue multiplexing in order to work well and not be overly cumbersome….I looked at a couple of the analogue multiplexers available and settled on this one:

74HCT4067 – Analogue Multiplexer

It’s basically a single throw sixteen throw switch which can be controlled by a microcontroller. There lots of breakout boards available on the internet. I bought this one:

Ebay shop – 74HC4067 breakout board

I haven’t used it yet….my first plan is to test and model the analogue input stage…then connect it to the multiplexer and then use that to scale up for 88 keys.

In order to make this work we will need a lot of multiplexers:

88 keys / 16 channels = Number of multiplexer devices needed

therefore 5.5 devices (six) in reality.

Before that we need to make a sensor measurement stage.  I’ve decided to use a buffered simple resistive divider circuit:

The Sensor Measurement Stage

The above circuit is an approximation of how the electronics will read a key press.  The circuit functions as follows:

The momentary switch and the 10 kΩ potentiometer model the behaviour of the velostat material. I don’t have much information on the resistivity of the velostat but I have tried it and I do know that it’s resistance does vary with pressure – I measured it with a multimeter. The resistor R1 makes up a voltage divider circuit. When the piano key is pressed the resistance of the velostat changes which is detected by the LM358 Op-Amp. The resistor R5 and the capacitor C1 make up a low pass filter. It might not be necessary but I’m trying to ensure that no external electronic noise is presented to the op-amp. I only want to measure key presses, nothing else. The first op-amp is configured as a non-inverting amplifier with a gain of two. The 100 pF capacitor limits the bandwidth of the op-amp restricting it’s operation to low frequencies, another way to limit noise being passed on to other parts of the circuit. The second op-amp stage is again a simple non-inverting op-amp stage with a gain of two. The output signal presented to the next stage will be between zero and three and a half volts. That should be more than enough range present to detect key presses with good sensitivity. The output will be connected to an analogue to digital converter which will probably be a ten bit ADC integral to the microcontroller. The op-amp is an LM358 but just about any op-amp will do for this circuit…There is nothing inherently special about that component. The circuit has been simulated connected to an oscilloscope. Here is the output:

The oscilloscope output – the pulses represent a unique keypress

The simulation appears to work perfectly which is always good…This circuit will have to be reproduced eighty-eight times so we will need to design a small and easy to build circuit.  For now I’m going to make a though-hole version because it’s easy to prototype.  Once I’m happy everything works I will probably make a sixteen input version which will be connected to the analogue switch.

The Schematic of the key press circuit

I added an LED because I think it would be nice to see when the key has been pressed without having to attach it to a measurement device like an oscilloscope. It makes it easier to test the circuit. I also added a screw terminal to input the power – nearly forgot that.

The Top Layer of the PCB
The bottom Layer with dimensions in mm

Just for fun here is the circuit rendered in 3D:

ISO render of the populated PCB

Top render of the populated PCB

If the circuit works as intended I will re-engineer this board with surface mount components to reduce the physical size of the board and have eighty-eight boards made…

Here is the parts list for the key press circuit:

Qty Value Device Parts Description Farnell Code Unit Price (£) Cost for Circuit (£)
1 N/A 5 mm LED – Red LED1 LEDs 2335725 0.051 0.051
1 100 pF Capacitor C2 25 V Ceramic Capacitor 1141765 0.0709 0.0709
6 10 kΩ Resistor R1, R2, R3, R4, R5, R6 5% 1/4 Watt Carbon Film Resistor 2329474 0.024 0.144
2 10nF Capacitor C1, C3 25 V Ceramic Capacitor 1216435 0.275 0.55
1 220 Ω Resistor R7 5% 1/4 Watt Carbon Film Resistor 2329899 0.037 0.037
1 LM358 Dual Operational Amplifier IC1 Jellybean op-amp 2295980 0.34 0.34
3 N/A 5 mm Screw terminal connector JP1_SENS, JP2, JP3_POWER Standard 2-pin 0.1 pitch 2493614 0.16 0.48
1 2N7000 N Channel MOSFET Q1_2N7002 Jellybean N-Channel MosFET 9845178 0.158 0.158
Total in £ 1.8309

Not too bad at all…It does not take into account the cost of the PCB or my time building and testing the circuit.  I intend having the PCB for the surface mount version made professionally – eighty – eight times so that will cost a little more!

That’s all for now – next post on this will probably show the board in operation and a prototype key press sensor:

555 Flyback Driver and Plasma Speaker Part III

So here is the complete Plasma speaker circuit in all it’s glory!

It actually creates a significant amount of high voltage and works very well.  I would caution anyone else attempting to replicate this circuit to please be very careful.  I haven’t given myself a shock yet but it could happen and will hurt if it does….Exercise sensible precautions please!

Here is the previous post in case people need to catch up:

555 flyback driver and plasma speaker part II

I have found that the 3D printed HV probe holders work quite well.  I also have found that setting the distance between the probes is critical to obtaining a reproducible arc and that the constant re-strike of the arc causing the audio to sound terrible.  From experimentation I have found that the audio signal from my mobile phone is more than enough to drive the 555 modulation pin when it isn’t capacitively coupled.  When capacitive coupling is added the audio is barely heard.  The capacitor on the audio input reduces the hissing considerably.  Here is a video showing the current audio output of the plasma speaker…it sounds pretty terrible but it does work:

I have decided to do two things….improve the HV probes and provide a simple class A audio amplifier to the pin 5 input of the 555.  This should improve the sound and get rid of the horrible hissing!

So to that end I have designed a very simple single transistor class A amplifier using a BC548 transistor.  Here is the schematic:

In designing the circuit I referred to this website…which is rather useful for this kind of thing:

I knew how to design a Class A amplifier well enough but I had forgotten how to select the components values correctly…in particular I wanted to increase the low frequency response and limit the bandwidth of the amplifier to reduce the high frequency response.

The circuit works fairly simply…An audio signal from a suitable source is presented at the 3.5 mm headphone jack input – only one side of the audio signal is provided – this amplifier is mono. This is then passed to C1 – a 1 uF electrolytic capacitor which is used to remove any dc offset and chosen in such a way as to not overly affect the bass response of the amplifier (more on this later).  The next components in the circuit are R3 and R4 which bias the NPN BC548 transistor into constantly being ON.  These values are set by ohms law.  We need at least 0.7 volts to turn an NPN transistor ON. Lets do the maths just for fun:

Ohms Law; V / R = I

In this case:

V: 12 Volts
Rt: R3 + R4 which is 120 kΩ + 10 kΩ = 130 kΩ

I = V / Rt

I = 12 V / 130 kΩ

I = 9.23076923077 * 10^-5 A or 92.3 µA

The voltage applied to the base of the BC548 transistor can be calculated by = I * R4
therefore the voltage applied to the base of the BC548 transistor:

92.3 *10^-6 A * 10 kΩ

The voltage applied to the base of the BC548 transistor is 0.923 Volts or 923 mV

The circuit has been designed so that 0.923 volts is always applied to the base pin of the transistor to ‘bias’ the transistor ON.  The audio signal applied will increase this voltage and be amplified.  The next components applied to the collector of the transistor are a 10 kΩ potentiometer and a 100 Ω resistor.  At the emitter of the transistor we have another 10 kΩ  potentiometer and a 10 uF capacitor. All of these components combined set the gain of the amplifier. There are formulae that can be applied to calculate the amount of gain.  I guessed at it…It’s not particularly important in this case. When the potentiometers are at maximum (according to my simulations) the input signal is amplified roughly 130 times greater than the input…the amount of gain is controlled both 10 kΩ  potentiometers which can be set by the operator.  The 10 uF electrolytic capacitor C3 is known as the emitter decoupling capacitor and is added to prevent any stray audio signal being present on the emitter pin of the transistor.

Finally at the output of the amplifier we have a 1 nF ceramic capacitor C4 and a 10 uF electrolyitic capacitor C2.  The electrolytic capacitor C2 prevents any dc voltage being passed to the next stage of the circuit, in our case, pin 5 of the 555 timer. C4 is used to limit the bandwidth of the amplifier.  In this case I have set all of the capacitor values to set the amplifier’s frequency bandwidth to be between 200 Hz and 20 kHz which is roughly the range of human hearing.

I simulated the circuit in order to check what the output would be like and check the gain would be sufficient and to verify the frequency response.  It was helpfully not clipped and gave a good amplified approximation of what was to be expected.

Here are the results of the simulation…I have placed probes at the more interesting points in the circuit:

Simulation Schematic

Here is the simulated oscilloscope output:

The input signal is shown with the blue trace, the red trace shows the amplified output.  The output is inverted but that won’t matter in this case.

The really good thing about simulating circuits is that the frequency bandwidth can be checked without actually building the circuit.  Here is the simulated audio frequency response of the amplifier:

If the capacitor values C1, C3 and C4 are changed for different values the frequency response of the amplifier is significantly affected.  C1’s value changes the bass frequency responses, C3 changes the treble response and C4 changes the bandwidth of the amplifier.  In this case I have tweaked the values to try to give the best response between 200 Hz and 20 kHz without losing too much bandwidth.

Because its me I’ve designed a simple single sided PCB for this circuit.  It could easily be made on veroboard (stripboard) or using some other method.

Top Layer of PCB
Bottom Layer of PCB

Here is a render of the PCB to show how it will look once etched and populated:

Top View of Class A Amplifier Render
ISO view of Class A Amplifier Render

Here is the bill of materials:

Part Value Device Description Vendor Part Number Quantity Cost
12VDC_INPUT N/A M025MM Standard 2-pin 5mm screw terminal Farnell 9632972 1 0.245
AUDIO_OUT N/A M025MM Standard 2-pin 5mm screw terminal Farnell 9632972 1 0.245
C1 1uF CAP_POLPTH1 Electrolytic Capacitor Farnell 1236686 1 0.0464
C2 10uF CAP_POLPTH1 Electrolytic Capacitor Farnell 9451056 1 0.034
C3 10uF CAP_POLPTH1 Electrolytic Capacitor Farnell 9451056 1 0.034
C4 1nF CAPPTH1 Ceramic Capacitor Farnell 1141779 1 0.0758
C5 100uF CAP_POLPTH1 Electrolytic Capacitor Farnell 1902882 1 0.0345
C6 100nF CAPPTH1 Ceramic Capacitor Farnell 1141775 1 0.0721
JP1 N/A AUDIO-JACKPTH 3.5mm Audio Jack Farnell 1608405 1 0.534
R2 100 RESISTORPTH-1/4W ? Watt Carbon Film Resistor Farnell 9342397 1 0.0523
R3 120k RESISTORPTH-1/4W ? Watt Carbon Film Resistor Farnell 9342540 1 0.0492
R4 10k RESISTORPTH-1/4W ? Watt Carbon Film Resistor Farnell 9342419 1 0.0523
RV1 10k POTALPS-KIT PCB Mount Variable Resistor Farnell 1191725 1 1.4
RV2 10k POTALPS-KIT PCB Mount Variable Resistor Farnell 1191725 1 1.4
T1 BC549 BC549-NPN-TO92-CBE BC549 NPN Transistror Farnell 2453797 1 0.238
Total 4.5126

Again I haven’t factored in the cost of the PCB or it’s manufacture but it would be reasonable to estimate the total cost of the project to be around £6.00

Here is a quick video showing the circuit in operation with the plasma speaker.  The audio is very much improved!

Now I need to get back to putting the HV section and the electronics into some sort of casing.  That’s all for now – take care people!

The Particle Electron – First Impressions

A while ago I backed the kickstarter campaign for Particle (formerly Spark)’s Electron board, a IOT (internet of things) with a built in 3G modem (2G are available) with global data coverage, recently they shipped, Setup was as easy as getting it out the box, wiring it up and following the instructions on (mine is […]