Raspberry Pi Volume in Node Red

Over the course of my many experiments with the Raspberry Pi and similar I have had constant problems with volume – I remember wasting ages with the Orange Pi – no WAY could I get sound to come out of the analog output.

Things are a bit better with the Raspberry Pi if you’re using the graphical desktop otherwise you have to get to grips with AMIXER.

And so it was that I’ve been trying to get to grips with volume control in Node-Red.

The command to control the analog output(3.5mm jack assuming you have nothing connected to the HDMI output) is simple enough..

amixer cset numid=1 – 100%

Two problems with this – 50% is almost silent.. and that % sign isn’t ideal.

So a quick SUBNODE…

Volume Control on Raspberry Pi

The content of that function (yellow) was entirely experimental

if (msg.payload>0) msg.payload+=66;
return msg;

Basically unless the volume is 0, I shove it right up into the 66+ region. I then add % onto the end and fire that into an EXEC node containing the following:


Note the space at the end of the command… so that appending the incoming message will produce our desired volume control levels with only a number 0-100 input.

And here’s my test.

Volume control on Raspberry Pi - Peter Scargill

At the top – a quick speech test (I’ve described Ivona speech previously in the blog)

And a range of test values – you can use these mid-speech. Works a treat.

So now when powering up Node-Red I can ensure a fixed volume and have scope to have different levels for different applications – a low level for general speech or sounds – and a high level for, say, alarms.



Leave a Reply

Your email address will not be published. Required fields are marked *