Volt meter displaying on 7 segment LED display

Best forum watchers,

I’ve been busy with a voltmeter project lately and I got stuck at some point. I looked at a video of robojax where he makes a voltmeter that is able to read higher voltages than just the 5 volts of the Arduino. when I measure the voltage I want to classify different cases to lower and higher values of voltages. for example

if (voltage_sensed >0) {
int x_value = 1;

else if (voltage_sensed >30) {
int x_value = 2;

and so on
for x_value i want to light up the 7 segments LED display. so i make a switch statement where i say that a certain case should appear when it has the integer number of x_value

switch(x_value) {

case 1:
zero(); // is the funtion that represents a 0 on the 7 segment led display

case 2:


but when I do this is doesn’t execute the case that I want. But when I print the x_value on my Serial monitor is does appear to have an integer value of for example 0 or 1. It just doesn’t execute. I will post the code below here.

thanks in advance for helping me out

Volt_meter_v5.ino (4.6 KB)

Please post your code, in code tags.

Your problem is with scoping. Every time you declare 'int x_value' you declare a new variable 'x_value' within the corresponding code block. They are not all the same!

Leave the 'int x_value' at the top of your sketch (global declaration) and remove the 'int' from in front of all the assignments you make in other parts of the code.


isn't >0 true before > 30?