# exit status 1 expected initializer before 'void'-Completed

**URL:** <https://forum.arduino.cc/t/exit-status-1-expected-initializer-before-void-completed/439089>\
**Category:** Programming\
**Created:** [February 19, 2017, 1:03pm UTC](https://forum.arduino.cc/t/exit-status-1-expected-initializer-before-void-completed/439089 "2017-02-19T13:03:08Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![wpage97](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wpage97/32/1142134_2.png) [@wpage97](https://forum.arduino.cc/u/wpage97)\
**Post date:** [February 19, 2017, 1:03pm UTC](https://forum.arduino.cc/t/exit-status-1-expected-initializer-before-void-completed/439089/1 "2017-02-19T13:03:08Z")

</div>

My code is coming up with a error saying 'expected initializer before 'void''  
I'm fairly new to C++ and was wondering if someone could help me out with this?  
Here is my Code

int temp //A0 producing 4 volts  
#define start\_button 2 // #define any text saying start\_button will be replaced with (port)2  
#define LED1 3 // #define any text saying LED1 will be replaced with (port)3  
#define heater\_element 4 // #define any text saying heater\_element will be replaced with (port)4  
#define LED2 5 // #define any text saying LED2 will be replaced with (port)5  
#define LED3 6 // #define any text saying LED3 will be replaced with (port)6  
#define piezo\_buzzer 7 // #define any text saying piezo\_buzzer will be replaced with (port)7

void setup()  
{  
pinMode(LED1,OUTPUT); //listing all pin outputs and speed of communication  
Serial.begin(9600);  
pinMode(heater\_element,OUTPUT);  
Serial.begin(9600);  
pinMode(LED2,OUTPUT);  
Serial.begin(9600);  
pinMode(LED3,OUTPUT);  
Serial.begin(9600);  
pinMode(piezo\_buzzer,OUTPUT);  
Serial.begin(9600);  
}  
void loop()  
{  
digitalRead(start\_button,HIGH) //starting machine  
{  
digitalWrite(LED1,HIGH); //turning on 'started' LED  
Serial.println("Started cooking process");  
}  
}

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [February 19, 2017, 1:09pm UTC](https://forum.arduino.cc/t/exit-status-1-expected-initializer-before-void-completed/439089/2 "2017-02-19T13:09:14Z")

</div>

Look at your very first line.

Please remember to use code tags when posting code.

---

<div class="post-metadata">

**Author:** ![JavierN](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@JavierN](https://forum.arduino.cc/u/JavierN)\
**Post date:** [February 19, 2017, 1:10pm UTC](https://forum.arduino.cc/t/exit-status-1-expected-initializer-before-void-completed/439089/3 "2017-02-19T13:10:14Z")

</div>

Hi! I'm fairly new myself so there might be a good reason, but why are you using Serial.begin so many times?

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [February 19, 2017, 1:13pm UTC](https://forum.arduino.cc/t/exit-status-1-expected-initializer-before-void-completed/439089/4 "2017-02-19T13:13:00Z")

</div>

Then there is this line. Look in the reference at [digitalRead](https://www.arduino.cc/en/Reference/DigitalRead). And missing a semi-colon.

```cpp
digitalRead(start_button,HIGH)

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [February 19, 2017, 1:13pm UTC](https://forum.arduino.cc/t/exit-status-1-expected-initializer-before-void-completed/439089/5 "2017-02-19T13:13:39Z")

</div>

(deleted)

---

<div class="post-metadata">

**Author:** ![Gabriel\_swe](https://avatars.discourse-cdn.com/v4/letter/g/7c8e57/32.png) [@Gabriel\_swe](https://forum.arduino.cc/u/Gabriel_swe)\
**Post date:** [February 19, 2017, 1:22pm UTC](https://forum.arduino.cc/t/exit-status-1-expected-initializer-before-void-completed/439089/6 "2017-02-19T13:22:36Z")

</div>

> groundfungus:  
> Then there is this line. Look in the reference at [digitalRead](https://www.arduino.cc/en/Reference/DigitalRead). And missing a semi-colon.
> 
> ```arduino
> digitalRead(start_button,HIGH)
> 
> ```

Naah, looking at the next few lines I dont think a semi-colon is missing.  
More likely a missing if and equal signs.

```arduino
if (digitalRead(start_button)==HIGH)

```

---

<div class="post-metadata">

**Author:** ![wpage97](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wpage97/32/1142134_2.png) [@wpage97](https://forum.arduino.cc/u/wpage97)\
**Post date:** [February 19, 2017, 2:04pm UTC](https://forum.arduino.cc/t/exit-status-1-expected-initializer-before-void-completed/439089/7 "2017-02-19T14:04:06Z")

</div>

That was helpful thank you but the error is still appearing, it says I need an initalizer before 'void' but I'm unsure as to what is meant

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [February 19, 2017, 2:04pm UTC](https://forum.arduino.cc/t/exit-status-1-expected-initializer-before-void-completed/439089/8 "2017-02-19T14:04:59Z")

</div>

Post your code.  
Use code tags.

---

<div class="post-metadata">

**Author:** ![wpage97](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wpage97/32/1142134_2.png) [@wpage97](https://forum.arduino.cc/u/wpage97)\
**Post date:** [February 19, 2017, 2:11pm UTC](https://forum.arduino.cc/t/exit-status-1-expected-initializer-before-void-completed/439089/9 "2017-02-19T14:11:14Z")

</div>

```cpp
int temp //A0 producing 4 volts
#define start_button 2 // #define any text saying start_button will be replaced with (port)2
#define LED1 3 // #define any text saying LED1 will be replaced with (port)3
#define heater_element 4 // #define any text saying heater_element will be replaced with (port)4
#define LED2 5 // #define any text saying LED2 will be replaced with (port)5
#define LED3 6 // #define any text saying LED3 will be replaced with (port)6
#define piezo_buzzer 7 // #define any text saying piezo_buzzer will be replaced with (port)7

void setup()
{
  // initialize serial communication:
  Serial.begin(9600);
  // initialize pins:
  pinMode(LED1,OUTPUT);                       
  pinMode(heater_element,OUTPUT);
  pinMode(LED2,OUTPUT);
  pinMode(LED3,OUTPUT);
  pinMode(piezo_buzzer,OUTPUT);
}

void loop()
{
   if digitalRead(start_button==HIGH)                     //starting machine
 {
   digitalWrite (LED1,HIGH);                     //turning on 'started' LED
    Serial.println("Started cooking process");
  }
}

```

---

<div class="post-metadata">

**Author:** ![JavierN](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@JavierN](https://forum.arduino.cc/u/JavierN)\
**Post date:** [February 19, 2017, 2:12pm UTC](https://forum.arduino.cc/t/exit-status-1-expected-initializer-before-void-completed/439089/10 "2017-02-19T14:12:10Z")

</div>

You need a semicolon in the first line.

int temp;

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [February 19, 2017, 2:12pm UTC](https://forum.arduino.cc/t/exit-status-1-expected-initializer-before-void-completed/439089/11 "2017-02-19T14:12:31Z")

</div>

Look again at your very first line.  
I think I've already mentioned this.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [February 19, 2017, 2:13pm UTC](https://forum.arduino.cc/t/exit-status-1-expected-initializer-before-void-completed/439089/12 "2017-02-19T14:13:37Z")

</div>

`if digitalRead(start_button==HIGH)  `then take a look here.

---

<div class="post-metadata">

**Author:** ![wpage97](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wpage97/32/1142134_2.png) [@wpage97](https://forum.arduino.cc/u/wpage97)\
**Post date:** [February 19, 2017, 2:27pm UTC](https://forum.arduino.cc/t/exit-status-1-expected-initializer-before-void-completed/439089/13 "2017-02-19T14:27:54Z")

</div>

Here is the error code:

```cpp
Arduino: 1.6.7 (Windows 10), Board: "Arduino/Genuino Uno"

Log_book_activity:20: error: expected initializer before 'void'

 void loop()

 ^

\\nasstudusers\4$\N0616240\My Documents\Arduino\Log_book_activity\Log_book_activity.ino: In function 'void loop()':

Log_book_activity:22: error: expected '(' before 'digitalRead'

    if digitalRead(start_button==HIGH)                        //starting machine

      ^

exit status 1
expected initializer before 'void'

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

```

and here is the corrections on the code(apologises for not seeing your original message):

```cpp
int temp; //A0 producing 4V
#define start_button 2 // #define any text saying start_button will be replaced with (port)2
#define LED1 3 // #define any text saying LED1 will be replaced with (port)3
#define heater_element 4 // #define any text saying heater_element will be replaced with (port)4
#define LED2 5 // #define any text saying LED2 will be replaced with (port)5
#define LED3 6 // #define any text saying LED3 will be replaced with (port)6
#define piezo_buzzer 7 // #define any text saying piezo_buzzer will be replaced with (port)7

void setup()
{
  // initialize serial communication:
  Serial.begin(9600);
  // initialize pins:
  pinMode(LED1,OUTPUT);                       
  pinMode(heater_element,OUTPUT);
  pinMode(LED2,OUTPUT);
  pinMode(LED3,OUTPUT);
  pinMode(piezo_buzzer,OUTPUT);
}
void loop()
{
  if digitalRead(start_button==HIGH)                      //starting machine
 {
  digitalWrite (LED1,HIGH);                    //turning on 'started' LED
    Serial.println("Started cooking process");
  }
}

```

 ![Capture.PNG](https://europe1.discourse-cdn.com/arduino/original/4X/3/4/2/342cb5ee0ff8288feb1225c036b0c738f1ef1758.png)

---

<div class="post-metadata">

**Author:** ![JavierN](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@JavierN](https://forum.arduino.cc/u/JavierN)\
**Post date:** [February 19, 2017, 2:31pm UTC](https://forum.arduino.cc/t/exit-status-1-expected-initializer-before-void-completed/439089/14 "2017-02-19T14:31:26Z")

</div>

the if statement should look like this:

```cpp
if (digitalRead(start_button)==HIGH)

```

---

<div class="post-metadata">

**Author:** ![wpage97](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wpage97/32/1142134_2.png) [@wpage97](https://forum.arduino.cc/u/wpage97)\
**Post date:** [February 19, 2017, 2:39pm UTC](https://forum.arduino.cc/t/exit-status-1-expected-initializer-before-void-completed/439089/15 "2017-02-19T14:39:36Z")

</div>

I've corrected that but the original error still is coming up

---

<div class="post-metadata">

**Author:** ![JavierN](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@JavierN](https://forum.arduino.cc/u/JavierN)\
**Post date:** [February 19, 2017, 2:43pm UTC](https://forum.arduino.cc/t/exit-status-1-expected-initializer-before-void-completed/439089/16 "2017-02-19T14:43:46Z")

</div>

I've copied your code and fixed the if statement and it compiles fine.  
Do you want to post it once more and I'll try to compile it again?

---

<div class="post-metadata">

**Author:** ![wpage97](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wpage97/32/1142134_2.png) [@wpage97](https://forum.arduino.cc/u/wpage97)\
**Post date:** [February 19, 2017, 4:45pm UTC](https://forum.arduino.cc/t/exit-status-1-expected-initializer-before-void-completed/439089/17 "2017-02-19T16:45:25Z")

</div>

I've sorted that issue out now but am now having another problem! I've created a nested loop and I want it to break that loop once 10 minutes has elapsed! Here is my code:

```cpp
int temp; //A0 producing 4V
#define start_button 2 // #define any text saying start_button will be replaced with (port)2
#define LED1 3 // #define any text saying LED1 will be replaced with (port)3
#define heater_element 4 // #define any text saying heater_element will be replaced with (port)4
#define LED2 5 // #define any text saying LED2 will be replaced with (port)5
#define LED3 6 // #define any text saying LED3 will be replaced with (port)6
#define piezo_buzzer 7 // #define any text saying piezo_buzzer will be replaced with (port)7

void setup()
{
  // initialize serial communication:
  Serial.begin(9600);
  // initialize pins:
  pinMode(LED1,OUTPUT);                       
  pinMode(heater_element,OUTPUT);
  pinMode(LED2,OUTPUT);
  pinMode(LED3,OUTPUT);
  pinMode(piezo_buzzer,OUTPUT);
}

void loop()
{
  if (digitalRead(start_button)==HIGH)                      //starting machine
 {
  digitalWrite (LED1,HIGH);                    //turning on 'started' LED
  Serial.println("Started cooking process");
  delay(5000);                                  //delay for 5 seconds 
  }
  if (analogRead(temp)<=4.5)
  {
  digitalWrite (heater_element,HIGH);          //turing on heater
  digitalWrite (LED2,HIGH);                    //turning on 'Boiling' LED
  Serial.println("Started to boil");
  delay(5000);                               
  }
  while (analogRead(temp)>4.5)
  {
  digitalWrite (heater_element,LOW);                    //turning off heating element
  Serial.println("Water Boiled");                                                     
  }
  do 
  {
    if (analogRead(temp)>4.5)
    {
      break;
    }
    else
    {
    digitalWrite (heater_element,HIGH);
    delay(10000); 
    digitalWrite (heater_element,LOW);
    delay(50000);
    }
  }
  while(delay(600000));

}

```

---

<div class="post-metadata">

**Author:** ![JavierN](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@JavierN](https://forum.arduino.cc/u/JavierN)\
**Post date:** [February 19, 2017, 5:06pm UTC](https://forum.arduino.cc/t/exit-status-1-expected-initializer-before-void-completed/439089/18 "2017-02-19T17:06:08Z")

</div>

I'm glad you got that working!  
I'm happy to help but you probably need to start a new thread with the new issue and mark this one as complete.  
That way everyone can pitch in! I'll keep an eye out for it.

---

<div class="post-metadata">

**Author:** ![wpage97](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wpage97/32/1142134_2.png) [@wpage97](https://forum.arduino.cc/u/wpage97)\
**Post date:** [February 19, 2017, 5:11pm UTC](https://forum.arduino.cc/t/exit-status-1-expected-initializer-before-void-completed/439089/19 "2017-02-19T17:11:14Z")

</div>

Will do thank you!

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 10:21pm UTC](https://forum.arduino.cc/t/exit-status-1-expected-initializer-before-void-completed/439089/20 "2021-05-05T22:21:09Z")

</div>

Closed on May 5, 2021, 10:21pm UTC


