Thursday, 18 October 2012

Analogue Gauge Jitter with an Arduino


You know that classic movie moment when some pipe or other critical component is about to burst and explode? Most commonly used in submarine movies.

They normally show the impending doom with a gauge, with the needle WAY past the "Super Dangerous: Seek shelter if pointer is past this point!" mark.

Of course, the needle won't just stay in that position, it will bounce around (within the above mentioned mark) to give that extra edge of "shit's going down, yo!".

Imagine dramatic music playing

So, today, you will learn how to replicate this effect!

How to connect the analogue gauge:

You should have two wires coming out from the gauge. One positive and one negative.
Connect the positive end to Arduino's Pin 9 and the negative to Arduino's GND.

Now upload this code:
int gaugePin = 9;    

void setup(){}

void loop()

  analogWrite(gaugePin, random(7,10));

 ...and you're set!

 This is a quick 'n' dirty solution, but I'm happy with it as it only needs one line of code to work!

How it works:

The code generates a random number and sends that to the gauge, changing it's position. The delay() determines the speed of the jitter. Change the speed (marked red) and random number range (marked in blue) for varying effects!

Keep in mind:
You will need to experiment around to see where your gauge's maximum range is.
Mine was around 11, so I used the range between 7 and 10 for a more pronounced jitter!

It's awesome coolio.

Have fun and let me know if you build this into any of your projects!


  1. This is so cool Jay, you're obviously a very intelligent man to know this, thanks for sharing with us.

  2. cool, i gotta try this