servo problem

I wrote this code of a moving robot but the servo keeps giving me error that ‘myservo’ was not declared in this scope

#include <Servo.h>
#include “SoftwareSerial.h”// import the serial library
Servo myservo; //Define the name of Servo object
int t=200;

const int IN1=3;
const int IN2=5;
const int IN3=6;
const int IN4=7;
int alarm=1;
int detectorPin = 10; // connect positive wire from circuit here
int detectorState = LOW; // we start, assuming no metal has been detected
int val; // variable for reading the pin status
int BluetoothData;
SoftwareSerial HC05(0,1); // RX, TX
int SPEED_Control=200;
void setup() {
// fIRST , define the Motor’s pin as an OUTPUT

pinMode( IN1 ,OUTPUT);// Right Motor 1st wire
pinMode( IN2 ,OUTPUT);// Right Motor 2nd wire
pinMode( IN3 ,OUTPUT);// left Motor 1st wire
pinMode( IN4 ,OUTPUT);// left Motor 2nd wire
myservo.attach(9); //connect servo to Pin D9
HC05.begin(9600);
pinMode(detectorPin, INPUT); // declare sensor as input
pinMode(alarm, OUTPUT); // declare alarm as output
digitalWrite(alarm, LOW);
digitalWrite(detectorPin, LOW);
}
void FORWARD(int Speed){
//When we want to let Motor To Rotate clock wise
// just void this part on the loop section .

analogWrite(IN1,0);
analogWrite(IN2,Speed);
analogWrite(IN3,Speed);
analogWrite(IN4,0);
myservo.write(0);
}
void BACKWARD(int Speed){
//When we want to let Motor To Rotate Counter clock wise
// just void this part on the loop section .
analogWrite(IN1,Speed);
analogWrite(IN2,0);
analogWrite(IN3,0);
analogWrite(IN4,Speed);
myservo.write(0);
}
void LEFT(int Speed){
//When we want to let Motor To Rotate Counter clock wise
// just void this part on the loop section .
myservo.write(45);
delay(1000);
analogWrite(IN1,0);
analogWrite(IN2,Speed);
analogWrite(IN3,0);
analogWrite(IN4,Speed);

}
void RIGHT(int Speed){
//When we want to let Motor To Rotate Counter clock wise
// just void this part on the loop section .
myservo.write(-45);
delay(1000);
analogWrite(IN1,Speed);
analogWrite(IN2,0);
analogWrite(IN3,Speed);
analogWrite(IN4,0);

}
void slowRIGHT(int Speed){
//When we want to let Motor To Rotate Counter clock wise
// just void this part on the loop section .
myservo.write(-45);
analogWrite(IN1,0);
analogWrite(IN2,Speed);
analogWrite(IN3,Speed);
analogWrite(IN4,0);

}
void slowLEFT(int Speed){
//When we want to let Motor To Rotate Counter clock wise
// just void this part on the loop section .
myservo.write(45);
analogWrite(IN1,0);
analogWrite(IN2,Speed);
analogWrite(IN3,Speed);
analogWrite(IN4,0);

}
void Stop(){
//When we want to let Motor To Rotate clock wise
// just void this part on the loop section .
analogWrite(IN1,0);
analogWrite(IN2,0);
analogWrite(IN3,0);
analogWrite(IN4,0);
myservo.write(0);

}

void loop() {
//Rise Up

if (HC05.available()){
BluetoothData=HC05.read();
Serial.println(BluetoothData);}

if(BluetoothData==‘F’){ // if number 1 pressed …
FORWARD(SPEED_Control);
}
if(BluetoothData==‘B’){ // if number 1 pressed …
BACKWARD(SPEED_Control);
}
if(BluetoothData==‘L’){ // if number 1 pressed …
RIGHT(SPEED_Control);

}
if(BluetoothData==‘R’){ // if number 1 pressed …
LEFT(SPEED_Control);
}
if(BluetoothData==‘S’){ // if number 1 pressed …
Stop();
}
if (BluetoothData==‘F’&&‘L’){
slowRIGHT(Speed_control);
}
if (BluetoothData==‘f’&&‘R’){
slowLEFT(Speed_control);}
{
val = digitalRead(detectorPin); // read input value and store it in val
if(digitalRead(detectorPin) == HIGH) {
Stop(); //stop robot
digitalWrite(alarm, HIGH); // sets alarm on
delay(5000); // waits for 5 second
digitalWrite(alarm, LOW); // sets alarm off
}
}
}

minesweeper.ino (3.63 KB)

#include "SoftwareSerial.h"// import the serial library\

Get rid of the stray \ at the end of the comment. It makes the compiler think that the next line (Servo myservo; //Define the name of Servo object) is part of that line so does not load the servo library.

int  SPEED_Control=200;
// then later
slowRIGHT(Speed_control);
slowLEFT(Speed_control);

Case matters.

Compiles with one warning after fixing the above, IDE ver 1.6.7, Uno.

Please post code in code tags like the "how to use the forum" stickies request. Proper indentation makes the code easier to follow. Use auto format to indent your code (ctrl-t or Tools, Auto Format).

 SoftwareSerial HC05(0,1); // RX, TX

Why are you using SoftwareSerial on the hardware serial pins? If you are not using Serial, use it to read from the HC05, NOT SoftwareSerial.

This is what the compiler sees#include "SoftwareSerial.h"// import the serial library Servo myservo; //Define the name of Servo

thanks every one :slight_smile:
and sorry for bad typing