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);
}
-
2You should learn to properly indent your code. You'd soon see the problem then.Majenko– Majenko2019年10月26日 23:35:07 +00:00Commented 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.MatsK– MatsK2019年10月27日 06:49:25 +00:00Commented Oct 27, 2019 at 6:49
1 Answer 1
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/…2019年10月27日 09:11:20 +00:00Commented Oct 27, 2019 at 9:11
-
@Jurag can you flag that as a dupe?he77789– he777892019年10月27日 09:31:33 +00:00Commented Oct 27, 2019 at 9:31
-
no, it is a different question and a different site. it is a follow-up question2019年10月27日 09:35:02 +00:00Commented 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?he77789– he777892019年10月27日 09:54:14 +00:00Commented Oct 27, 2019 at 9:54
-
you have the thank you in the question :-). the user60250 account is unregistered, so temporary.2019年10月27日 10:05:59 +00:00Commented Oct 27, 2019 at 10:05