

This can be easily accomplished by using conditional statements. Once we have a variable which can calculate the voltage reading, we then move on and write our instructions to detect the trip points. Simply, divide 5 by 1023 and then multiply it by the the potentiometer analog read:įloat voltage = analogRead(A0) * (5.0 / 1023.0) To change the values from 0-1023 to a range that corresponds to the voltage the pin is reading, we need to scale the the numbers from 0.0 and 5.0. We will create a new variable, float, and assign a variable name to it because this variable will be our voltage reading. The resistance value range between 0 - 1023. Loop - The first step we will take in writing our main program is to be able to calculate a voltage reading from the potentiometer. And then we will initialise the timer library first, followed by the MFS library which is initialised in conjunction with the timer. Setup - In the program setup, we will configure the pin modes as outputs for both our LEDs. Assign relevant variable names to each pin. These will include the two LED pins for the upper and lower trip points. Also in the global scope, we will declare our global variables which can be accessed by all the functions in the program. We will only require libraries to use the 4x7 segment display, so therefore we will include the MFS library and the timer one library. Global Scope - To begin with, in the global scope you want to include all the required libraries for this program. Remember on the MFS the digital commands are reversed, HIGH = LOW and LOW = HIGH.
#Voltage meeter code#
The final source code will be included at the end. Note: We will be going through the steps in completing this program as all programming techniques and functions required for this program have already been covered in previous lesson through the course.

Similarly, when the lower trip point is activated, a relevant message is to be displayed and an alternative LED visual indication. But when the upper trip point is activated, a relevant message is to be displayed as wells as a visual LED indication.ĥ. When the meter reads the voltage within the trip point boundaries, the reading must be displayed to the 4x7 segment display.Ĥ. The upper trip point is set at 3 volts and lower trip point is set at 2 volts.ģ. The voltage reading must have an upper and lower trip point.

Using the variable resistor on the Multi Functional Shield, read the analog voltage.Ģ. This trip points are used to ensure that the voltage level is not below the required level and also does not exceed the required level.ġ. However, this system will include upper and lower trip points, which are defined in the specification. We will be able to adjust the voltage reading between 0 and 5 volts. The program we will be coding in this lesson is a Voltage Meter.

This will allow us to apply what we have learnt throughout the course.
