Problems with making a function

I’ve read example code and tutorials online but still confused with the error message I’m getting calling my function. I’m writing code to turn a camera on and take a picture when an input pin goes high. I have a function called: void TURN_ON_CAMERA() that I want to call to power up the camera. When I try to compile I get the error “a function is not allowed here before ‘{’ token”.

If I add “;” to the end of the above statement to make it

“void TURN_ON_CAMERA();”

then my error message goes away, but all the example code I’ve seen doesn’t not have a “’;” at the end of the function statement and I don’t want to add it if it’s not supposed to be there.

My full code is:

#include <Arduino.h>

int PIR = 2; // The PIR is conencted to pin 2
int LED = 13; //The LED is connected to pin 13
int PIR_STATUS; //Pir status
int CAM_PWR = 5; // Cam power
int CAM_STAUS;
int SHUTTER = 6;
int NMBR_OF_PICS;//used in a for loop to take three pictures quick and then pause and take a third

void setup() {
pinMode(LED, OUTPUT);
pinMode(PIR, INPUT);
pinMode(CAM_PWR, OUTPUT);
Serial.begin (9600);
pinMode(SHUTTER, OUTPUT);
}

void loop()
{
delay(5000);
PIR_STATUS=digitalRead(PIR);

if (PIR_STATUS == HIGH)
{
Serial.println(“MOTION DETECTED”);

}

else {

digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)
delay(250); // wait for a second
digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
delay(250);
Serial.println(“NO MOTION”);
}

void TURN_ON_CAMERA()
{
digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
delay(1000);
digitalWrite(LED, HIGH);
delay (1000);
digitalWrite(LED, LOW);
delay(3000);
digitalWrite(CAM_PWR, HIGH);
Serial.println (“CAMER A IS ON”);
delay(1000);
digitalWrite(CAM_PWR, LOW);
Serial.println (“CAMERA IS OFF”);
delay(3000);
Serial.print(“CAMERA POWERED ON”);
}

Looks like you have too few braces. Use Ctrl + T to format your code. The mistake should be revealed.

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :)

You seem to be trying to create a function inside another function - that is not allowed.

When you put the semi-colon at the end of the function line it just becomes a call to the function - which is allowed inside another function. But then, of course, there will be no function called TURN_ON_CAMERA()

Please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum Your code is too long to study quickly without copying to a text editor.

…R

Thanks for the advice, I have tried to post my code correctly below. Still haven’t been able to figure out why I’m getting the error message from the first bracket in my
void TURN_ON_CAMERA() function that says:
“a function definition is not allowed here before ‘{’ token”. Any advice apprecaited

#include <Arduino.h>

int PIR = 2;      // The PIR is conencted to pin 2
int LED = 13;     //The LED is connected to pin 13
int PIR_STATUS;   //Pir status
int CAM_PWR = 5;  // Cam power
int CAM_STAUS;
int SHUTTER = 6;
int NMBR_OF_PICS;//used in a for loop to take three pictures quick and then pause and take a third

void setup() {
  pinMode(LED, OUTPUT);
  pinMode(PIR, INPUT);
  pinMode(CAM_PWR, OUTPUT);
  Serial.begin (9600);
  pinMode(SHUTTER, OUTPUT);
}

void loop()
{
  delay(5000);
  PIR_STATUS = digitalRead(PIR);

  if (PIR_STATUS == HIGH)
  {
    Serial.println("MOTION DETECTED");

  }

  else {

    digitalWrite(LED, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(250);              // wait for a second
    digitalWrite(LED, LOW);    // turn the LED off by making the voltage LOW
    delay(250);
    Serial.println("NO MOTION");
  }

  void TURN_ON_CAMERA()
  {
    digitalWrite(LED, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(1000);              // wait for a second
    digitalWrite(LED, LOW);    // turn the LED off by making the voltage LOW
    delay(1000);
    digitalWrite(LED, HIGH);
    delay (1000);
    digitalWrite(LED, LOW);
    delay(3000);
    digitalWrite(CAM_PWR, HIGH);
    Serial.println ("CAMER A IS ON");
    delay(1000);
    digitalWrite(CAM_PWR, LOW);
    Serial.println ("CAMERA IS OFF");
    delay(3000);
    Serial.print("CAMERA POWERED ON");
  }

You need a } on line 39 to mark the end of the loop() function.

Every { must have a corresponding }

...R

Another way to look at the problem. After formatting, why is this indented (nested)?

  void TURN_ON_CAMERA()
  {

Hi, Count the number of { and the number of } they should be the same........ :o

Tom.... :)