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);
}
  • 2
    You should learn to properly indent your code. You'd soon see the problem then. – Majenko Oct 26 '19 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. – MatsK Oct 27 '19 at 6:49
4

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);
}
  • it looks like the answer helped stackoverflow.com/questions/58576149/… – Juraj Oct 27 '19 at 9:11
  • @Jurag can you flag that as a dupe? – he77789 Oct 27 '19 at 9:31
  • no, it is a different question and a different site. it is a follow-up question – Juraj Oct 27 '19 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? – he77789 Oct 27 '19 at 9:54
  • you have the thank you in the question :-). the user60250 account is unregistered, so temporary. – Juraj Oct 27 '19 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.