ABOUT PROGRAM

I HAVE A PROBLEM ABOUT ARDUINO CODE.I MADE HOME SECURITY SYSTEM WİTH ARDUINO BUT I COMPILE THE PROGRAM “a function-definition is not allowed here before ‘{’ token”.IF ANYONE HELP ME I LL BE PLEASED.THE PROGRAM IS IN ATTACHMENT

kod.ino.txt (1.38 KB)

Where does your setup() function end?

Put EVERY { on a line by itself. Put EVERY } on a line by itself.

It will be blindingly obvious what your problem is.

(deleted)

Yes that is my full sketch spycatcher2k. ı agree some functions missing.but which functions missing??ı couldnt find them.and setup() function end } ı put that at te end of pin mode line pauls

setup() function end } ı put that at te end of pin mode line

pinMode(11,OUTPUT); // buzzer in digital pin 11 }

Do you mean the } that is part of the comment ?

Your for loop doesn't look good to me.

Why didn't you post your code?

(deleted)

AWOL: Your for loop doesn't look good to me.

Why didn't you post your code?

MY CODE IS TOP OF THE PAGE UNDER MY FIRST QUESTION

Attaching the code is not the same as posting the code. Posting the code in code tags (like the forum stickies ask, if you had read them) allows anyone to see it without having to download the code into a text editor. Before you post the code please use autoformat (ctrl-t or Tools Auto Format) to indent the code to make it more readable. Autoformat will also often point out errors in mismatched brackets.

karaneee: MY CODE IS TOP OF THE PAGE UNDER MY FIRST QUESTION

Please stop SHOUTING

AWOL: Please stop SHOUTING

sorry

int IRpin = A0; // IR photodiode on analog pin A0

int IRemitter = 2; // IR emitter LED on digital pin 2 int ambientIR; // variable to store the IR coming from the ambient int obstacleIR; // variable to store the IR coming from the object int value[10]; // variable to store the IR values int distance; // variable that will tell if there is an obstacle or not

void setup(){

Serial.begin(9600); // initializing Serial monitor pinMode(IRemitter,OUTPUT); // IR emitter LED on digital pin 2 digitalWrite(IRemitter,LOW);// setup IR LED as off

pinMode(11,OUTPUT); // buzzer in digital pin 11 }

void loop(){

distance = readIR(5); // calling the function that will read the distance and passing the "accuracy" to it Serial.println(distance); // writing the read value on Serial monitor // buzzer(); // uncomment to activate the buzzer function }

int readIR(int times){

for(int x=0;x

//-- Function to sound a buzzer for audible measurements --//

void buzzer(){

if (distance>1){

if(distance>100){ // continuous sound if the obstacle is too close

digitalWrite(11,HIGH); }

else{ // bips faster when an obstacle approaches

digitalWrite(11,HIGH);

delay(150-distance); // adjust this value for your convenience

digitalWrite(11,LOW);

delay(150-distance); // adjust this value for your convenience } }

else{ // off if there is no obstacle

digitalWrite(11,LOW); }

}

for(int x=0;xsee reply #5

can you help me.I couldnt understand what you mean.if u can change the code and attach here i can try it.that is my first forum chatting.So i dont know the rules of the forum.

The site includes a reference page where you can see how a for loop should be constructed. The IDE is packed with worked programming examples.

pinMode(11,OUTPUT); // buzzer in digital pin 11 }

The } is still commented out so setup() does not end here.

for(int x=0;x

What do you want this for loop to do ? Whatever it is it is written wrongly at the moment.

For loops are one of the fundamental programming structures in C (and most programming languages) so you would be wise to read about them and understand how they work.

Dare I suggest that you read this before posting a programming question and follow the advice it contains about posting code here.

I suggest that you start with a book on C and learn the basics before continuing.

And please edit your reply #11. Currently it's impossible to determine if you made stupid mistakes or that something else went wrong.

type ``` [code] ``` before the code type ``` [/code] ``` after the code

To help a you a little on the way

void setup()
{

  Serial.begin(9600); // initializing Serial monitor pinMode(IRemitter,OUTPUT); // IR emitter LED on digital pin 2 digitalWrite(IRemitter,LOW);// setup IR LED as off

  pinMode(11, OUTPUT); // buzzer in digital pin 11 }
                                                   ^
                                                   ^
                                              this } needs to move to the next line to 'close' the setup()

Same for the } at the end of this line

distance = readIR(5); // calling the function that will read the distance and passing the "accuracy" to it Serial.println(distance); // writing the read value on Serial monitor // buzzer(); // uncomment to activate the buzzer function }