Variable or field 'setup' declared void

#define IR 6;

void setup {} (
int pinMode(6, INPUT);

void loop {} (
int value = digitalRead(6)
if IR = HIGH;
Serial.print1n(object found)
if IR = LOW;
SerialprintIn(no object found)

please edit your post, select the code part and press the </> icon in the tool bar to mark it as code. It’s unreadable as it stands. (also make sure you indented the code in the IDE before copying, that’s done by pressing ctrlT on a PC or cmdT on a Mac)

go check the C++ syntax… that’s not how you write an if… try to stick to

if (condition) {
  // code if condition is true


if (condition) {
  // code if condition is true
} else {
  // code if condition is false

also IR is worth 6, a constant, why do you want to assign HIGH or LOW to 6. it does not make sense…
→ assignment is with =, compare with ==

(and you want to compare with value, don’t you ?)

this should be void loop () {. first come parenthesis, “()” to describe the argument, braces “{}” surround the body of the function

setup() has the same issue. You have your () & {} mixed up.

-jim lee

You wonder why someone would take the time to change the () and {} the IDE gets there for you when you open a sketch…

OP seems MIA so…

So you see there are errors in almost every line - you need to understand the C language
rules a little better perhaps? Or start from a working example.

Also I would expect the comparisons to involve value, not IR which is the constant 6.
Perhaps you meant to use IR in the digitalRead call as the name for pin 6?

it’s C++ that we use here :wink:

Learn C first, C++ is more complex and a newcomer probably won’t benefit
by being bomdarded with stuff related to classes and templates just yet :slight_smile:

you mean a newcomer should not understand basic syntax things like Serial.begin() (which is missing in OP’s code) or Serial.print() ?

That’s not illegal in C. struct access to a function pointer.

but is it what is at play here? is it what OP needs to understand?

I’m not saying OP needs to become a C++ pro with all the advanced features. but understanding the concepts of OOP, instantiation and calling method is really part of the basics in my opinion.

Learning is a process of small steps, trying to do all at once risks creating major learning blocks and this helps noone. Can you remember back to when you were learning? I can and I had many misconceptions partly through poor tuition (self taught!).

Well I did learn C first because C++ did not exist at the time…

There is nothing wrong learning C, my point is that being exposed to the basics of C++ is also what matters.

(C will also get you biased around type casting as it’s more liberal / not as rich as C++)

bro stop fighting pls fix my code,im just a beginner i cannot understand complicated things…

If you cannot understand the difference between () (parentheses/round brackets) and {} (braces/squiggly brackets) and follow simple instructions then programming is probably not for you.


Bro, give it a try. You can do this

thanks bro.
i will try my best.

Thanks for your encouragement bro, with your help i studied more and i have finished my code with no errors and here's my code:
//Defining pins.
#define IR 6;
#define led 13;

void setup()
//Defining pinModes.
pinMode(6, INPUT);
pinMode(13, OUTPUT);
//Setting the baud rate..

void loop()
int in = digitalRead(6);
//in variable is the input of digital pin number 6..
//Defining if statements..
if (in == HIGH)
digitalWrite(13, HIGH);
if (in == LOW)
digitalWrite(13, LOW);

i also updated my code with led and not used serial monitor..

#define IR 6;
#define led 13;

The only reason you didn't get errors, is that you never used IR or led.
Lose the semicolons.

Also, you tested the return value of digitaRead for HIGH - it isn't necessary to then test for LOW, a simple "else" would do.

In summary,

void loop ()
  digitalWrite (13, digitalRead (6));

No variables, no tests required.