0

I'm really new to coding and Arduino so I would be eternally grateful for the help.

I'm trying to make a really basic flame sensor that beeps, lights up an LED and displays the distance from the sensor to the flame when activated. I keep getting a "'Serial' does not name a type" error message for the line that reads - Serial.println(analogRead(A0));

I’ve tried to figure it out from the information on this forum of similar questions to try to correct the issue but it seems like every time I fix one thing another 2 errors come up. I’ve been stuck on this one for a little while so I’m hoping I might be able to receive some kind of assistance from the Arduino community.

Below is the entire code - any help is appreciated, thanks :)

int Led = 4;
int Buzz = 7;
int Sensor = 11;
int Fire = HIGH;
void setup()
{ Serial.begin(9600);
pinMode(Buzz,OUTPUT);
pinMode(Sensor,INPUT);
pinMode(Led,OUTPUT);
}
void loop()
{
Fire = digitalRead(Sensor);
if(Fire == HIGH);
Serial.print("analog Read = ");
Serial.print(analogRead);
}
Serial.println("HELP! A FIRE!");
digitalWrite(Buzz,HIGH);
digitalWrite(Led,HIGH);
delay(200);
digitalWrite(Led,LOW);
delay(200);
Serial.println(analogRead(A0));
}
else
{
Serial.println("No fire detected");
digitalWrite(Buzz,LOW);
digitalWrite(Led,LOW);
}
delay(500);
}
Majenko
106k5 gold badges81 silver badges139 bronze badges
asked Oct 26, 2019 at 23:34
2
  • 2
    You should learn to properly indent your code. You'd soon see the problem then. Commented Oct 26, 2019 at 23:35
  • You should also learn the difference between ( and {. And a tutorial like youtube.com/watch?v=QO_Jlz1qpDw or equal is recommended. Commented Oct 27, 2019 at 6:49

1 Answer 1

3

First things first; please INDENT YOUR CODE. The code you posted is a mess and I took at least double the time to fix that.

First, you have an extra closing curly bracket at line 17 and the if (Fire == High); should be changed to if (Fire == High){

Fixed code:

int Led = 4;
int Buzz = 7;
int Sensor = 11;
int Fire = HIGH;
void setup()
{
 Serial.begin(9600);
 pinMode(Buzz,OUTPUT);
 pinMode(Sensor,INPUT);
 pinMode(Led,OUTPUT);
}
void loop()
{
 Fire = digitalRead(Sensor);
 if(Fire == HIGH){
//Serial.print("analog Read = ");
//Serial.print(analogRead);
 Serial.println("HELP! A FIRE!");
 digitalWrite(Buzz,HIGH);
 digitalWrite(Led,HIGH);
 delay(200);
 digitalWrite(Led,LOW);
 delay(200);
 Serial.println(analogRead(A0));
 }
 else
 {
 Serial.println("No fire detected");
 digitalWrite(Buzz,LOW);
 digitalWrite(Led,LOW);
 }
 delay(500);
}
answered Oct 27, 2019 at 0:10
5
  • it looks like the answer helped stackoverflow.com/questions/58576149/… Commented Oct 27, 2019 at 9:11
  • @Jurag can you flag that as a dupe? Commented Oct 27, 2019 at 9:31
  • no, it is a different question and a different site. it is a follow-up question Commented Oct 27, 2019 at 9:35
  • Well he took my answer, added a else if, and say that it is his own code. I don't have enough rep over there to comment, can you help me call it out? Commented Oct 27, 2019 at 9:54
  • you have the thank you in the question :-). the user60250 account is unregistered, so temporary. Commented Oct 27, 2019 at 10:05

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.