Code given error

void loop()
{
if(get_channel_voltage(INPUT_CHANNEL_1) > ALARM_LEVEL_1);
{
digitalWrite(OUTPUT_1, HIGH);
Serial.println("IN1 HIGH VOLTAGE");
}
else
{
digitalWrite(OUTPUT_1, LOW);
}
if(get_channel_voltage(INPUT_CHANNEL_2) > ALARM_LEVEL_2)
{
digitalWrite(OUTPUT_2, HIGH);
Serial.println("IN2 HIGH VOLTAGE");
}
else
{
digitalWrite(OUTPUT_2, LOW);
}
if(get_channel_voltage(INPUT_CHANNEL_1) < ALARM_LEVEL_3)
{
digitalWrite(OUTPUT_3, LOW);
Serial.println("IN3 LOW VOLTAGE");
}
else
{
digitalWrite(OUTPUT_3, HIGH);
}

}

code is error if block
exit status 1
expected initializer before 'if'

Post all of the code. Read the forum guidelines to see how to properly post code.

Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

This is one of the errors that I get when I paste your loop() into a sketch.

'INPUT_CHANNEL_1' was not declared in this scope

So as requested by @groundFungus, post your complete code and use code tags.

One other problem is if (get_channel_voltage(INPUT_CHANNEL_1) > ALARM_LEVEL_1);. The semi-colon at the end terminates the if and the next lines will be executed unconditionally; it also results in a message in the line of else without if.

Arduino:1.8.15 (Windows 10), Kart:"Arduino Uno"

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Mehmet\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10815 -build-path C:\Users\Mehmet\AppData\Local\Temp\arduino_build_284558 -warnings=none -build-cache C:\Users\Mehmet\AppData\Local\Temp\arduino_cache_178461 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\Mehmet\Desktop\Workspace\ISSD_Project\Coding\Voltage_Measurement_Relays_Control\Voltage_Measurement_Relays_Control.ino

C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Mehmet\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10815 -build-path C:\Users\Mehmet\AppData\Local\Temp\arduino_build_284558 -warnings=none -build-cache C:\Users\Mehmet\AppData\Local\Temp\arduino_cache_178461 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\Mehmet\Desktop\Workspace\ISSD_Project\Coding\Voltage_Measurement_Relays_Control\Voltage_Measurement_Relays_Control.ino

Using board 'uno' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr

Using core 'arduino' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr

Detecting libraries used...

"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\Mehmet\AppData\Local\Temp\arduino_build_284558\sketch\Voltage_Measurement_Relays_Control.ino.cpp" -o nul

Generating function prototypes...

"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\Mehmet\AppData\Local\Temp\arduino_build_284558\sketch\Voltage_Measurement_Relays_Control.ino.cpp" -o "C:\Users\Mehmet\AppData\Local\Temp\arduino_build_284558\preproc\ctags_target_for_gcc_minus_e.cpp"

"C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\Mehmet\AppData\Local\Temp\arduino_build_284558\preproc\ctags_target_for_gcc_minus_e.cpp"

Çalışma derleniyor...

"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\Mehmet\AppData\Local\Temp\arduino_build_284558\sketch\Voltage_Measurement_Relays_Control.ino.cpp" -o "C:\Users\Mehmet\AppData\Local\Temp\arduino_build_284558\sketch\Voltage_Measurement_Relays_Control.ino.cpp.o"

C:\Users\Mehmet\Desktop\Workspace\ISSD_Project\Coding\Voltage_Measurement_Relays_Control\Voltage_Measurement_Relays_Control.ino: In function 'void setup()':

Voltage_Measurement_Relays_Control:53:5: error: a function-definition is not allowed here before '{' token

 {

 ^

Voltage_Measurement_Relays_Control:59:5: error: 'else' without a previous 'if'

 else

 ^~~~

Voltage_Measurement_Relays_Control:63:47: error: expected primary-expression before '>' token

 if (get_channel_voltage(INPUT_CHANNEL_2)) > ALARM_LEVEL_2)

                                           ^

Voltage_Measurement_Relays_Control:72:47: error: expected primary-expression before '<' token

 if (get_channel_voltage(INPUT_CHANNEL_1)) < ALARM_LEVEL_3)

                                           ^

Voltage_Measurement_Relays_Control:82:3: error: expected '}' at end of input

}

^

exit status 1

a function-definition is not allowed here before '{' token

Please follow the advice given in the link below when posting code. Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

And error text.

Get rid of the semicolon after the first if-statement.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.