Requesting for help in my program ,pleas help me out

you need to include the Servo library. add this at the top of your sketch:

#include <Servo.h>  // https://www.arduino.cc/reference/en/libraries/servo/

Wait a minute ,
Should i include all the library of the component i have use or only for servo.
Thanking @J-M-L
Lucky

also pos is not declared anywhere, modify all your for loops and add int in front of the first pos

for (int pos = 180; pos>=0; pos-=1) {
  ...
}

lucky_final_robot:21:1: error: ‘Servo’ does not name a type; did you mean ‘Serial’?
Servo.servo1;
^~~~~
Serial
C:\Users\user\Documents\Arduino\lucky_final_robot\lucky_final_robot.ino: In function ‘void setup()’:
lucky_final_robot:150:1: error: ‘servo1’ was not declared in this scope
servo1.attach(23);
^~~~~~
C:\Users\user\Documents\Arduino\lucky_final_robot\lucky_final_robot.ino:150:1: note: suggested alternative: ‘perror’
servo1.attach(23);
^~~~~~
perror
lucky_final_robot:151:1: error: ‘serial’ was not declared in this scope
serial.begin(9600);
^~~~~~
C:\Users\user\Documents\Arduino\lucky_final_robot\lucky_final_robot.ino:151:1: note: suggested alternative: ‘Serial’
serial.begin(9600);
^~~~~~
Serial
C:\Users\user\Documents\Arduino\lucky_final_robot\lucky_final_robot.ino: In function ‘void loop()’:
lucky_final_robot:162:1: error: ‘counterclocwise’ was not declared in this scope
counterclocwise();
^~~~~~~~~~~~~~~
C:\Users\user\Documents\Arduino\lucky_final_robot\lucky_final_robot.ino:162:1: note: suggested alternative: ‘counterclockwise’
counterclocwise();
^~~~~~~~~~~~~~~
counterclockwise
lucky_final_robot:179:1: error: ‘ultra’ was not declared in this scope
ultra();
^~~~~
C:\Users\user\Documents\Arduino\lucky_final_robot\lucky_final_robot.ino:179:1: note: suggested alternative: ‘ultoa’
ultra();
^~~~~
ultoa
lucky_final_robot:180:1: error: ‘servo1’ was not declared in this scope
servo1.write(0);
^~~~~~
C:\Users\user\Documents\Arduino\lucky_final_robot\lucky_final_robot.ino:180:1: note: suggested alternative: ‘perror’
servo1.write(0);
^~~~~~
perror
lucky_final_robot:183:1: error: ‘sevo1’ was not declared in this scope
sevo1.write(180);
^~~~~
lucky_final_robot:195:1: error: a function-definition is not allowed here before ‘{’ token
{
^
lucky_final_robot:205:5: error: ‘pos’ was not declared in this scope
for(pos=0;pos<=180;pos+=1)
^~~
C:\Users\user\Documents\Arduino\lucky_final_robot\lucky_final_robot.ino:205:5: note: suggested alternative: ‘pow’
for(pos=0;pos<=180;pos+=1)
^~~
pow
lucky_final_robot:207:1: error: ‘servo1’ was not declared in this scope
servo1.write(pos);
^~~~~~
C:\Users\user\Documents\Arduino\lucky_final_robot\lucky_final_robot.ino:207:1: note: suggested alternative: ‘perror’
servo1.write(pos);
^~~~~~
perror
lucky_final_robot:209:1: error: expected ‘;’ before ‘}’ token
}
^
lucky_final_robot:210:5: error: ‘pos’ was not declared in this scope
for(pos=180;pos>=0;pos-=1)
^~~
C:\Users\user\Documents\Arduino\lucky_final_robot\lucky_final_robot.ino:210:5: note: suggested alternative: ‘pow’
for(pos=180;pos>=0;pos-=1)
^~~
pow
lucky_final_robot:212:1: error: ‘servo1’ was not declared in this scope
servo1.write(pos);
^~~~~~
C:\Users\user\Documents\Arduino\lucky_final_robot\lucky_final_robot.ino:212:1: note: suggested alternative: ‘perror’
servo1.write(pos);
^~~~~~
perror
exit status 1
‘Servo’ does not name a type; did you mean ‘Serial’?
Can anyone help me out , please!
thanking any kind hearted person in advance

Please post your full sketch.

If possible, you should always post code directly in the forum thread as text:

  1. Select Tools > Auto Format from the Arduino IDE’s menus. This will make it easier for you to spot bugs and make it easier for us to read.
  2. Select Edit > Copy for Forum from the Arduino IDE’s menus.
  3. In a forum reply here, click on the post composer field.
  4. Press “Ctrl+V”. This will paste the sketch to the post composer.
  5. Move the cursor outside of the code tags before you add any additional text to your reply.
  6. Repeat the above process if your sketch has multiple tabs.
  7. Click the Reply button to post your reply.

This will make it easy for anyone to look at it, which will increase the likelihood of you getting help.

When your code requires a library that’s not included with the Arduino IDE please post a link to where you downloaded that library from or if you installed it using Library Manager (Sketch > Include Library > Manage Libraries in the Arduino IDE) then say so and state the full name of the library.

I’ve merged your cross-posts @justinlucky.

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a suspension from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the “How to get the best out of this forum” guide you will find at the top of every forum category. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

But how do i delete it ,
help please
Sir!

No need to delete it. Just please don’t cross-post again and everything will be fine.

Sure sir
I will be on my best
Lucky

For posting error-messages use a code-section. It is really annoying to scrolldown so many times until the end of the error-messages is reached.

Simply click on the </>-Symbol

which will insert the needed formation
and the area where to post is already marked. Simply press Ctrl-V to insert the clipboard-content
image

best regards Stefan

1 Like

Arduino: 1.8.13 (Windows 7), Board: “Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)”

lucky_final_robot:22:6: error: expected unqualified-id before ‘.’ token

Servo.servo1;

  ^

C:\Users\user\Documents\Arduino\lucky_final_robot\lucky_final_robot.ino: In function ‘void setup()’:

lucky_final_robot:151:3: error: ‘servo1’ was not declared in this scope

servo1.attach(23);

^~~~~~

C:\Users\user\Documents\Arduino\lucky_final_robot\lucky_final_robot.ino:151:3: note: suggested alternative: ‘Servo’

servo1.attach(23);

^~~~~~

Servo

lucky_final_robot:152:3: error: ‘serial’ was not declared in this scope

serial.begin(9600);

^~~~~~

C:\Users\user\Documents\Arduino\lucky_final_robot\lucky_final_robot.ino:152:3: note: suggested alternative: ‘Serial’

serial.begin(9600);

^~~~~~

Serial

C:\Users\user\Documents\Arduino\lucky_final_robot\lucky_final_robot.ino: In function ‘void loop()’:

lucky_final_robot:163:7: error: ‘counterclocwise’ was not declared in this scope

   counterclocwise();

   ^~~~~~~~~~~~~~~

C:\Users\user\Documents\Arduino\lucky_final_robot\lucky_final_robot.ino:163:7: note: suggested alternative: ‘counterclockwise’

   counterclocwise();

   ^~~~~~~~~~~~~~~

   counterclockwise

lucky_final_robot:180:5: error: ‘ultra’ was not declared in this scope

 ultra();

 ^~~~~

C:\Users\user\Documents\Arduino\lucky_final_robot\lucky_final_robot.ino:180:5: note: suggested alternative: ‘ultoa’

 ultra();

 ^~~~~

 ultoa

lucky_final_robot:181:5: error: ‘servo1’ was not declared in this scope

 servo1.write(0);

 ^~~~~~

C:\Users\user\Documents\Arduino\lucky_final_robot\lucky_final_robot.ino:181:5: note: suggested alternative: ‘Servo’

 servo1.write(0);

 ^~~~~~

 Servo

lucky_final_robot:184:7: error: ‘sevo1’ was not declared in this scope

   sevo1.write(180);

   ^~~~~

lucky_final_robot:196:3: error: a function-definition is not allowed here before ‘{’ token

{

^

lucky_final_robot:208:7: error: ‘servo1’ was not declared in this scope

   servo1.write(pos);

   ^~~~~~

C:\Users\user\Documents\Arduino\lucky_final_robot\lucky_final_robot.ino:208:7: note: suggested alternative: ‘Servo’

   servo1.write(pos);

   ^~~~~~

   Servo

lucky_final_robot:210:5: error: expected ‘;’ before ‘}’ token

 }

 ^

lucky_final_robot:213:7: error: ‘servo1’ was not declared in this scope

   servo1.write(pos);

   ^~~~~~

C:\Users\user\Documents\Arduino\lucky_final_robot\lucky_final_robot.ino:213:7: note: suggested alternative: ‘Servo’

   servo1.write(pos);

   ^~~~~~

   Servo

exit status 1

expected unqualified-id before ‘.’ token
i still have this error
Bro please
I am almost screw in learning this code
please help me out

Oh yeah sure
I will surely follow that suggestion
With gratitude
Lucky

it did not work well.

Are you using a locally installed Arduino-IDE or some kind of online-tool to write your programs?

I use Arduino IDE i download it through Google

The period is wrong, it must be only a space. Here you instantiate the Servo object ti use it later. Write:
Servo servo1;

don’t know what you mean “you downloaded it through google”

Do you click on an icon on your computer that looks similar like this
image

Does then popup a picture like this
image
and after some time do you see a window where the upper leftcorner looks like this?
image
best regards Stefan

Yes Brother


My program has some error
i just want it correct
That’s it Brother @StefanL38
Lucky

if you still have errors (fix pos declaration as mentioned in post #4) then post the code and describe what you see

You should post code by using code-tags
There is an automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose “copy for forum”
  3. paste clipboard into write-window of a posting

best regards Stefan

type or paste code here[code]
#include <Servo.h>  // https://www.arduino.cc/reference/en/libraries/servo/
#define m1 8
#define m2 9
#define EN1 2
#define m3 10
#define m4 11
#define EN2 3
#define m5 12
#define m6 13
#define EN3 4
#define m7 14
#define m8 15
#define EN4 5
#define m9 16
#define m10 17
#define EN5 6
#define STQ 20
#define Q4 53
#define Q3 52
#define Q2 51
#define Q1 50
Servo servo1;
#define ECHO 21
#define TRIG 22
long duration;
long distance;
void forward()
{
  digitalWrite(m1, HIGH);
  digitalWrite(m2, LOW);
  analogWrite(EN1, 255);
  digitalWrite(m3, HIGH);
  digitalWrite(m4, LOW);
  analogWrite(EN2, 255);
  digitalWrite(m5, HIGH);
  digitalWrite(m6, LOW);
  analogWrite(EN3, 255);
  digitalWrite(m7, HIGH);
  digitalWrite(m8, LOW);
  analogWrite(EN4, 255);
}
void backward()
{
  digitalWrite(m1, LOW);
  digitalWrite(m2, HIGH);
  analogWrite(EN1, 255);
  digitalWrite(m3, LOW);
  digitalWrite(m4, HIGH);
  analogWrite(EN2, 255);
  digitalWrite(m5, LOW);
  digitalWrite(m6, HIGH);
  analogWrite(EN3, 255);
  digitalWrite(m7, LOW);
  digitalWrite(m8, HIGH);
  analogWrite(EN4, 255);
  delay(1000);
}
void right()
{
  digitalWrite(m1, HIGH);
  digitalWrite(m2, LOW);
  analogWrite(EN1, 255);
  digitalWrite(m3, LOW);
  digitalWrite(m4, HIGH);
  analogWrite(EN2, 175);
  digitalWrite(m5, HIGH);
  digitalWrite(m6, LOW);
  analogWrite(EN3, 255);
  digitalWrite(m7, LOW);
  digitalWrite(m8, HIGH);
  analogWrite(EN4, 175);
  delay(1000);
}
void left()
{
  digitalWrite(m1, LOW);
  digitalWrite(m2, HIGH);
  analogWrite(EN1, 175);
  digitalWrite(m3, HIGH);
  digitalWrite(m4, LOW);
  analogWrite(EN2, 255);
  digitalWrite(m5, LOW);
  digitalWrite(m6, HIGH);
  analogWrite(EN3, 175);
  digitalWrite(m7, HIGH);
  digitalWrite(m8, LOW);
  analogWrite(EN4, 255);
  delay(1000);
}
void stop()
{
  digitalWrite(m1, LOW);
  digitalWrite(m2, LOW);
  analogWrite(EN1, 100);
  digitalWrite(m3, LOW);
  digitalWrite(m4, LOW);
  analogWrite(EN2, 100);
  digitalWrite(m5, LOW);
  digitalWrite(m6, LOW);
  analogWrite(EN3, 100);
  digitalWrite(m7, LOW);
  digitalWrite(m8, LOW);
  analogWrite(EN4, 100);
  delay(1000);
}
void clockwise()
{
  digitalWrite(m9, HIGH);
  digitalWrite(m10, LOW);
  analogWrite(EN5, 175);
  delay(1000);
}
void counterclockwise()
{
  digitalWrite(m9, LOW);
  digitalWrite(m10, HIGH);
  analogWrite(EN5, 175);
  delay(1000);
}
void wait()
{
  digitalWrite(m9, LOW);
  digitalWrite(m10, LOW);
  analogWrite(EN5, 100);
  delay(1000);
}
void setup()
{
  pinMode(m1, OUTPUT);
  pinMode(m2, OUTPUT);
  pinMode(EN1, OUTPUT);
  pinMode(m3, OUTPUT);
  pinMode(m4, OUTPUT);
  pinMode(EN2, OUTPUT);
  pinMode(m5, OUTPUT);
  pinMode(m6, OUTPUT);
  pinMode(EN3, OUTPUT);
  pinMode(m7, OUTPUT);
  pinMode(m8, OUTPUT);
  pinMode(EN4, OUTPUT);
  pinMode(m9, OUTPUT);
  pinMode(m10, OUTPUT);
  pinMode(EN5, OUTPUT);
  pinMode(Q1, INPUT);
  pinMode(Q2, INPUT);
  pinMode(Q3, INPUT);
  pinMode(Q4, INPUT);
  pinMode(STQ, INPUT);
  pinMode(ECHO, INPUT);
  pinMode(TRIG, OUTPUT);
  servo1.attach(23);
  Serial.begin(9600);
}
void loop()
{
  {

    int temp1 = digitalRead(Q1);
    int temp2 = digitalRead(Q2);
    int temp3 = digitalRead(Q3);
    int temp4 = digitalRead(Q4);
    if (temp1 == 1 && temp2 == 0 && temp3 == 0 && temp4 == 0)
      counterclockwise();
    else if (temp1 == 0 && temp2 == 1 && temp3 == 0 && temp4 == 0)
      forward();
    else if (temp1 == 1 && temp2 == 1 && temp3 == 0 && temp4 == 0)
      clockwise();
    else if (temp1 == 0 && temp2 == 0 && temp3 == 1 && temp4 == 0)
      left();
    else if (temp1 == 1 && temp2 == 0 && temp3 == 1 && temp4 == 0)
      stop();
    else if (temp1 == 0 && temp2 == 1 && temp3 == 1 && temp4 == 0)
      right();
    else if (temp1 == 0 && temp2 == 0 && temp3 == 0 && temp4 == 1)
      backward();
    else if (temp1 == 0 && temp2 == 0 && temp3 == 0 && temp4 == 0)
      wait();
  }
  {
    ultra();
    servo1.write(0);
    if (distance <= 10)
    {
      sevo1.write(180);
    }
    {
      servo1.write(90):
      }
    }
  {
    backward();
    if (distance <= 10)
      delay(1000);
  }
  void ultra()
  {
    digitalWrite(TRIG, LOW);
    delay(2);
    digitalWrite(TRIG, HIGH);
    delay(10);
    digitalWrite(TRIG, LOW);
    duration = pulseIn(ECHO, HIGH);
    distance = duration * 0.034 / 2;
  }
  {
    for (int pos = 0; pos <= 180; pos += 1)
    {
      servo1.write(pos);
      delay(15)
    }
    for (int pos = 180; pos >= 0; pos -= 1)
    {
      servo1.write(pos);
      delay(15);
    }
  }
}
[/code]