'Serial' does not name a type ERROR

Hey guys,

I am trying to make a DC ammeter and voltmeter using a current and voltage sensor. I used the voltage sensor and it works perfectly. I added a few lines for the current sensor but now it does not work and gives me an error. I have attached the code below. Please help if you can.

/*
DC Voltmeter & Ammeter
*/

int voltageInput = 5;
int currentInput = 0;
float vout = 0.0;
float vin = 0.0;
float R1 = 30000.0; // resistance of R1 (100K)
float R2 = 7500.0; // resistance of R2 (10K)
int voltageValue = 0;
int currentValue = 0;

void setup()
{
pinMode(voltageInput, INPUT);
pinMode(currentInput, INPUT);
Serial.begin(9600);
Serial.print(“DC MULTIMETER”);
}

void loop()
{
// read the value at analog input
voltageValue = analogRead(voltageInput);
vout = (voltageValue * 5.0) / 1024.0; // see text
vin = vout / (R2/(R1+R2));
if (vin<0.09) //statement to quash undesired reading !
{
vin=0.0;
}

currentValue = analogRead(currentInput); // read analog input pin 0

}

Serial.print("INPUT V = ");
Serial.println(vin,2);
Serial.print(currentValue);
Serial.println(“mA”);

}

I get these errors

Analog_input_read:37: error: ‘Serial’ does not name a type
Analog_input_read:38: error: ‘Serial’ does not name a type
Analog_input_read:39: error: ‘Serial’ does not name a type
Analog_input_read:40: error: ‘Serial’ does not name a type
Analog_input_read:42: error: expected declaration before ‘}’ token
‘Serial’ does not name a type

Hello and welcome,

Remove the } at line 35

Remove the } at line 35

Why? Because all executable code MUST be inside a function. The code from 36 on is not IN a function. The } closes the loop() function.

1 Like

I get the same thing

Removal of line 35 (the close brace) will make the sketch compile, and also make it make sense.

As written above, the code sets the variable currentValue but does nothing with it. By removing the brace, it will then show the number(s) on the serial monitor. That brace on line 35 is spurious.

ewold12:
I get the same thing

Post the code that causes the error using code tags when you do

ewold12:
I get the same thing

Then do the same fix.

Steve

slipstick:
Then do the same fix.

My thought too but I’ll go out on a limb and say the NOP (new original poster :wink: ) means they have the same error but are unlikely to be using the OOP’s (original original poster…) code.

I was rather hoping to persuade the “NOP” to give us a bit more detail, like the actual code s/he is having trouble with. Because in my mind if s/he isn’t using the same code then s/he doesn’t have the same problem.

Steve

slipstick:
I was rather hoping to persuade the "NOP" to give us a bit more detail, like the actual code s/he is having trouble with. Because in my mind if s/he isn't using the same code then s/he doesn't have the same problem.

Steve

Quite....

H,
Considering the post is 4 years old,...... :o :o :o

Tom... :slight_smile: