Controlling a voltmeter

This project demonstrates how to connect a voltmeter to the ThinkerShield and basics of how to get it working so you can use it in your own project. For the purposes of demonstration the potentiometer is used to vary the voltage sent to it via PWM.

Step 1

Step 1

The first thing you need to do it identify a voltmeter which is suitable for the project. The most important thing is to find a “5 volt” voltmeter since pins on the board are capable of between 0 and 5 volts. If you got a 20 volt one it will only be possible to get the needle to go to 5 volts.

Tip: Once setup there is usually a calibration screw on the front you can use if your voltmeter is lining up correctly.

 

 

Step 2

Step 2

The next is to work out which pin to use. To get a range of reading (rather than just 0 or 5) you need to use a pin which supports PWM. On an arduino board beside pins which support there is a ~. On the ThinkerShield with a standard Arduino UNO D5 and D6 on the top are suitable for it.

I am going to use D6.

Step 3

Step 3

Then you need to use alligator clips to connect the voltmeter to the ThinkerShield.

I am using black for ground and red for power.

Connect the black alligator clip to gnd and the red to D6.

Step 4

Step 4

Then on the back of the voltmeter connect the black to negative and the red to positive.

Then you need upload some code to the board to make it all work.

We are going to use the potentiometer to vary the voltage sent to D6/voltmeter.

First we need to define the pins we will use

//define variables
int voltmeterPin = 6;

int potentiometerPin = A5;

Then we need read in the value of the potentiometer

 // Read potentiometer value
 int sensorValue = analogRead(potentiometerPin);

The potentiometer gives values of 0 to 1023 PWM accepts values of 0 to 254. To make this work easily I am going to use the map function.
 //convert pin value to scale of 0 to 254 to suit PWM
 int voltmeterValue = map(sensorValue, 0, 1023, 0, 254);

finally you need to write that value to the pin

 //send value to pin using analog write
 analogWrite(voltmeterPin, voltmeterValue);

Now when you turn the potentiometer knob it should show up on the voltmeter!

Full source code available on the github.

Add a comment