# 'Serial' does not name a type. Help fast for School Project

**URL:** <https://forum.arduino.cc/t/serial-does-not-name-a-type-help-fast-for-school-project/1087799>\
**Category:** Programming\
**Created:** [February 8, 2023, 5:21pm UTC](https://forum.arduino.cc/t/serial-does-not-name-a-type-help-fast-for-school-project/1087799 "2023-02-08T17:21:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![decifier](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/decifier/32/919036_2.png) [@decifier](https://forum.arduino.cc/u/decifier)\
**Post date:** [February 8, 2023, 5:21pm UTC](https://forum.arduino.cc/t/serial-does-not-name-a-type-help-fast-for-school-project/1087799/1 "2023-02-08T17:21:48Z")

</div>

Here is my code:  
#include \<Servo.h\>

Servo myservo;

#define enA 10//Enable1 L298 Pin enA  
#define in1 9 //Motor1 L298 Pin in1  
#define in2 8 //Motor1 L298 Pin in1  
#define in3 7 //Motor2 L298 Pin in1  
#define in4 6 //Motor2 L298 Pin in1  
#define enB 5 //Enable2 L298 Pin enB

#define R\_S A0 //ir sensor Right  
#define L\_S A1 //ir sensor Left

int pos = 0;

void setup() {  
pinMode(A0, INPUT\_PULLUP); // Soil Moisture Sensor 1 PIN A0  
pinMode(A1, INPUT\_PULLUP); // Soil Moisture Sensor 1 PIN A1  
pinMode(8,OUTPUT); // Relay Module PIN D8  
Serial.begin(9600); // Sensor Buart Rate  
myservo.attach(9); // Servo PIN D9  
digitalWrite(8, HIGH);

pinMode(R\_S, INPUT); // declare if sensor as input  
pinMode(L\_S, INPUT); // declare ir sensor as input

pinMode(enA, OUTPUT); // declare as output for L298 Pin enA  
pinMode(in1, OUTPUT); // declare as output for L298 Pin in1  
pinMode(in2, OUTPUT); // declare as output for L298 Pin in2  
pinMode(in3, OUTPUT); // declare as output for L298 Pin in3  
pinMode(in4, OUTPUT); // declare as output for L298 Pin in4  
pinMode(enB, OUTPUT); // declare as output for L298 Pin enB

analogWrite(enA, 150); // Write The Duty Cycle 0 to 255 Enable Pin A for Motor1 Speed  
analogWrite(enB, 150); // Write The Duty Cycle 0 to 255 Enable Pin B for Motor2 Speed  
delay(1000);

}

void loop() {

if((digitalRead(R\_S) == 0)&&(digitalRead(L\_S) == 0)){forword();} //if Right Sensor and Left Sensor are at White color then it will call forword function

if((digitalRead(R\_S) == 1)&&(digitalRead(L\_S) == 0)){turnRight();} //if Right Sensor is Black and Left Sensor is White then it will call turn Right function

if((digitalRead(R\_S) == 0)&&(digitalRead(L\_S) == 1)){turnLeft();} //if Right Sensor is White and Left Sensor is Black then it will call turn Left function

if((digitalRead(R\_S) == 1)&&(digitalRead(L\_S) == 1)){Stop();} //if Right Sensor and Left Sensor are at Black color then it will call Stop function  
}

void forword(){ //forword  
digitalWrite(in1, HIGH); //Right Motor forword Pin  
digitalWrite(in2, LOW); //Right Motor backword Pin  
digitalWrite(in3, LOW); //Left Motor backword Pin  
digitalWrite(in4, HIGH); //Left Motor forword Pin  
}

void turnRight(){ //turnRight  
digitalWrite(in1, LOW); //Right Motor forword Pin  
digitalWrite(in2, HIGH); //Right Motor backword Pin  
digitalWrite(in3, LOW); //Left Motor backword Pin  
digitalWrite(in4, HIGH); //Left Motor forword Pin  
}

void turnLeft(){ //turnLeft  
digitalWrite(in1, HIGH); //Right Motor forword Pin  
digitalWrite(in2, LOW); //Right Motor backword Pin  
digitalWrite(in3, HIGH); //Left Motor backword Pin  
digitalWrite(in4, LOW); //Left Motor forword Pin  
}

void Stop(){ //stop  
digitalWrite(in1, LOW); //Right Motor forword Pin  
digitalWrite(in2, LOW); //Right Motor backword Pin  
digitalWrite(in3, LOW); //Left Motor backword Pin  
digitalWrite(in4, LOW); //Left Motor forword Pin  
}

int m= analogRead(A0); // Soil Moisture Sensor 1 PIN A0  
int n= analogRead(A1); // Soil Moisture Sensor 1 PIN A1  
Serial.println(m);  
delay(10);  
Serial.println(n);  
delay(200);  
if (m\>=980)  
{  
myservo.write(90); // tell servo to go to position in variable 'pos'

digitalWrite(8, LOW); // Relay ON  
delay(1000);  
}  
else if(m\<=970)  
{  
digitalWrite(8, HIGH); // Relay ON  
}  
if (n\>=980)  
{  
myservo.write(0); // tell servo to go to position in variable 'pos'

digitalWrite(8, LOW); // Relay ON  
delay(1000);

}  
else if(n\<=970)  
{  
digitalWrite(8, HIGH); // Relay OFF  
}

else  
{  
digitalWrite(8, HIGH); // Relay OFF  
}

}

here is my error message:  
Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: "Arduino Uno"

sketch\_feb08a:82:1: error: 'Serial' does not name a type

Serial.println(m);

^ ~~~~~

sketch\_feb08a:83:6: error: expected constructor, destructor, or type conversion before '(' token

delay(10);

```
  ^

```

sketch\_feb08a:84:1: error: 'Serial' does not name a type

Serial.println(n);

^ ~~~~~

sketch\_feb08a:85:6: error: expected constructor, destructor, or type conversion before '(' token

delay(200);

```
  ^

```

sketch\_feb08a:86:1: error: expected unqualified-id before 'if'

if (m\>=980)

^~

sketch\_feb08a:93:1: error: expected unqualified-id before 'else'

else if(m\<=970)

^~~~

sketch\_feb08a:97:1: error: expected unqualified-id before 'if'

if (n\>=980)

^~

sketch\_feb08a:105:1: error: expected unqualified-id before 'else'

else if(n\<=970)

^~~~

sketch\_feb08a:110:1: error: expected unqualified-id before 'else'

else

^~~~

sketch\_feb08a:115:1: error: expected declaration before '}' token

}

^

exit status 1

'Serial' does not name a type

This report would have more information with  
"Show verbose output during compilation"  
option enabled in File -\> Preferences.

Please help fast im on a deadline for a project

---

<div class="post-metadata">

**Author:** ![gfvalvo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gfvalvo/32/1013044_2.png) [@gfvalvo](https://forum.arduino.cc/u/gfvalvo)\
**Post date:** [February 8, 2023, 5:26pm UTC](https://forum.arduino.cc/t/serial-does-not-name-a-type-help-fast-for-school-project/1087799/2 "2023-02-08T17:26:27Z")

</div>

> [@decifier](#):
>
> im on a deadline for a project

Perhaps **you** are. But, none of the folks on the forum who might help you for **FREE** are. So perhaps you should consider rephrasing your request.

![image](https://europe1.discourse-cdn.com/arduino/original/4X/b/3/5/b357bf59ee547c1834fb3211af177096a1ccdf5d.jpeg)

---

<div class="post-metadata">

**Author:** ![Idahowalker](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/idahowalker/32/238858_2.png) [@Idahowalker](https://forum.arduino.cc/u/Idahowalker)\
**Post date:** [February 8, 2023, 5:27pm UTC](https://forum.arduino.cc/t/serial-does-not-name-a-type-help-fast-for-school-project/1087799/3 "2023-02-08T17:27:24Z")

</div>

Help us help you.

> [@](#):
>
> Please follow the advice given in this link [How to get the best out of this forum](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966) when posting code, in particular the section entitled 'Posting code and common code problems'.
> 
> Things that suck:  
>    
> a). Images of code suck.  
> b). Images of error messages suck.  
> c). Code snippets suck.
> 
> Use code tags (the \</\> icon above the compose window) to make it easier to read and copy code for examination
> 
> Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
> 
> Include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.
> 
> Post a schematic.
> 
> Post an image of your project.
> 
> Which Micro Controller are you using?
> 
> Is this simulator code?
> 
> Please describe the problem better then you just did.

---

<div class="post-metadata">

**Author:** ![Idahowalker](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/idahowalker/32/238858_2.png) [@Idahowalker](https://forum.arduino.cc/u/Idahowalker)\
**Post date:** [February 8, 2023, 5:29pm UTC](https://forum.arduino.cc/t/serial-does-not-name-a-type-help-fast-for-school-project/1087799/4 "2023-02-08T17:29:14Z")

</div>

You have code outside of a function.

Every { needs have } and hopefully in the correct place.

> [@decifier](#):
>
> int n= analogRead(A1); // Soil Moisture Sensor 1 PIN A1  
> Serial.println(m);  
> delay(10);  
> Serial.println(n);  
> delay(200);  
> if (m\>=980)  
> {  
> myservo.write(90); // tell servo to go to position in variable 'pos'
> 
> digitalWrite(8, LOW); // Relay ON  
> delay(1000);  
> }  
> else if(m\<=970)  
> {  
> digitalWrite(8, HIGH);

Which function is that code in?

---

<div class="post-metadata">

**Author:** ![buckfast\_beekeeper](https://avatars.discourse-cdn.com/v4/letter/b/74df32/32.png) [@buckfast\_beekeeper](https://forum.arduino.cc/u/buckfast_beekeeper)\
**Post date:** [February 8, 2023, 5:33pm UTC](https://forum.arduino.cc/t/serial-does-not-name-a-type-help-fast-for-school-project/1087799/5 "2023-02-08T17:33:06Z")

</div>

> [@decifier](#):
>
> void forword(){ //forword  
> digitalWrite(in1, HIGH); //Right Motor forword Pin  
> digitalWrite(in2, LOW); //Right Motor backword Pin  
> digitalWrite(in3, LOW); //Left Motor backword Pin  
> digitalWrite(in4, HIGH); //Left Motor forword Pin  
> }
> 
> void turnRight(){ //turnRight  
> digitalWrite(in1, LOW); //Right Motor forword Pin  
> digitalWrite(in2, HIGH); //Right Motor backword Pin  
> digitalWrite(in3, LOW); //Left Motor backword Pin  
> digitalWrite(in4, HIGH); //Left Motor forword Pin  
> }
> 
> void turnLeft(){ //turnLeft  
> digitalWrite(in1, HIGH); //Right Motor forword Pin  
> digitalWrite(in2, LOW); //Right Motor backword Pin  
> digitalWrite(in3, HIGH); //Left Motor backword Pin  
> digitalWrite(in4, LOW); //Left Motor forword Pin  
> }
> 
> void Stop(){ //stop  
> digitalWrite(in1, LOW); //Right Motor forword Pin  
> digitalWrite(in2, LOW); //Right Motor backword Pin  
> digitalWrite(in3, LOW); //Left Motor backword Pin  
> digitalWrite(in4, LOW); //Left Motor forword Pin  
> }

What they do in you're main loop? Functions and procedures must outside the setup and loop scope.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [August 7, 2023, 5:33pm UTC](https://forum.arduino.cc/t/serial-does-not-name-a-type-help-fast-for-school-project/1087799/6 "2023-08-07T17:33:14Z")

</div>

Closed on August 7, 2023, 5:33pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
