(uint8_t) error , how to solve this code , can any one help me i'm a beginner

#include<NewPing.h>
#define TRIGGER_PIN 6
#define ECHO_PIN 7
#define MAX_DISTANCE 100
int LED = 13;

void setup() {
NewPing sonar(TRIGGER_PIN , ECHO_PIN , MAX_DISTANCE);
Serial.begin(9600);
pinMode ; int (“LED , OUTPUT”); //defining led pin as output

}

void loop() {
if ((“RIGHT VALUE == 1” && “LEFT VALUE == 1”)); //for input values
(uint8_t) digitalWrite (LED) = “HIGH”; //for output of led pin
}

{

if ((“RIGHT VALUE == 0” && “LEFT VALUE == 0”)); //for input values
(uint8_t) digitalWrite (LED) = “HIGH”; //for output of led pin
}

the error shows,
C:\Users\Toshiba\Documents\Arduino\ULLTRASONIC_LED\ULLTRASONIC_LED.ino: At global scope:
ULLTRASONIC_LED:25:5: error: expected unqualified-id before ‘{’ token
{
^
exit status 1
too few arguments to function ‘void digitalWrite(uint8_t, uint8_t)’

digitalWrite() takes 2 parameters, the pin number and the value that the pin should be set to

See digitalWrite() - Arduino Reference

Welcome

There are many syntax errors in your code, it should be :

#include <NewPing.h>
#define TRIGGER_PIN 6
#define ECHO_PIN 7
#define MAX_DISTANCE 100
int LED = 13;

void setup()
{
  NewPing sonar( TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE );
  Serial.begin( 9600 );
  pinMode( LED, OUTPUT ); //defining led pin as output
}

void loop()
{
  if ( RIGHT_VALUE == 1 && LEFT_VALUE == 1 ) //for input values
  {
    digitalWrite( LED, HIGH ); //for output of led pin
  }

  if ( RIGHT_VALUE == 0 && LEFT_VALUE == 0 ) //for input values
  {
    digitalWrite( LED, HIGH ); //for output of led pin
  }
}

Study the changes. I’m only repairing syntax errors, so you will have to fix the other problems like RIGHT_VALUE and LEFT_VALUE not being declared, and the logic of your if statements :slight_smile:

Thanks for solving my problems and giving me suggestions.

#include <NewPing.h>
#define TRIGGER_PIN 6
#define ECHO_PIN 7
#define MAX_DISTANCE 100
int LED = 13;

void setup()
{
NewPing sonar( TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE );
Serial.begin( 9600 );
pinMode( LED, OUTPUT ); //defining led pin as output
}

void loop()
{
if ( “RIGHT_VALUE == 1 && LEFT_VALUE == 1” ) //for input values
{
digitalWrite( LED, HIGH ); //for output of led pin
}

if ( “RIGHT_VALUE == 0 && LEFT_VALUE == 0” ) //for input values
{
digitalWrite( LED, HIGH ); //for output of led pin
}
}

here’s my updated code by your suggestions

This is wrong

Why have you got quotes around the test values ?

Hi, @efefeg_3
Welcome to the forum.

Please read the post at the start of any forum , entitled “How to use this Forum”.
OR

Then look down to “code problems” about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks… Tom… :grinning: :+1: :coffee: :australia:

// UKHeli bob … thanks for your suggestions. i didn’t understand can you fix this.

#include<NewPing.h>
#define TRIGGER_PIN 6
#define ECHO_PIN 7
#define MAX_DISTANCE 100
int LED = 13;

void setup()
{
NewPing sonar( TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE );
Serial.begin( 9600 );
pinMode( LED, OUTPUT ); //defining led pin as output
}

void loop()
{
if ( “RIGHT_VALUE == 1 && LEFT_VALUE == 1” ) //for input values
{
digitalWrite( LED, HIGH ); //for output of led pin
}

if ( “RIGHT_VALUE == 0 && LEFT_VALUE == 0” ) //for input values
{
digitalWrite( LED, LOW ); //for output of led pin
}
}

yes UKheli bob you are correct. i did not get output for my project.

I was suggesting that you remove the quotes around the values in the the tests. but as RIGHT_VALUE and LEFT_VALUE are not declared in you code it will not compile anyway

Please Auto format your code in the IDE, use Copy for forum in the IDE and paste it here so that it is code tags to make it easier to read and copy for examination

Hi, @efefeg_3

#include<NewPing.h>
#define TRIGGER_PIN 6
#define ECHO_PIN 7
#define MAX_DISTANCE 100
int LED = 13;

void setup()
{
  NewPing sonar( TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE );
  Serial.begin( 9600 );
  pinMode( LED, OUTPUT ); //defining led pin as output
}

void loop()
{
  if ( RIGHT_VALUE == 1 && LEFT_VALUE == 1 ) //for input values
  {
    digitalWrite( LED, HIGH ); //for output of led pin
  }

  if ( RIGHT_VALUE == 0 && LEFT_VALUE == 0 ) //for input values
  {
    digitalWrite( LED, LOW ); //for output of led pin
  }
}

That should be a strart, now how are you going to get readings from the NewPing library?

Have you looked at the example code in the IDE for NewPing?

Tom… :grinning: :+1: :coffee: :australia: