I tried to add a LCD to my proyect but Tinkercad always shows the same error "invalid header file"
The code works perfectly before the LCD, so the problem must be one the related commands...it is my first time using LCDs
In tinkercad, must you first "install" the library before you #include the header file?
As far as I know tinkercad website already has those libraries installed.
int sensorfoto2 = A3;
Adafruit_LiquidCrystal lcd_1(0);
void setup ()
{
lcd_1.begin(32, 16, 2);
pinMode(tonePin, OUTPUT);
}
void loop ()
{
int lectura = analogRead(sensortem);
int temperatura = map(lectura, 0, 1023, -50, 450);
int lectura2 = analogRead(sensortem2);
int temperatura2 = map(lectura2, 0, 1023, -50, 450);
int luz = analogRead(sensorfoto);
int luz2 = analogRead(sensorfoto2);
if(temperatura>=70 || temperatura2>=70)
{
lcd_1.setCursor(0, 1);
lcd_1.print("FIRE");
alarm ();
}
else if(luz==1022 && luz2==1022)
{
alarm ();
}
else
{
digitalWrite(8, LOW);
}
}
void alarm ()
{
tone(tonePin, 146, 98.931984375);
delay(109.924427083);
delay(15.7034895833);
tone(tonePin, 146, 98.931984375);
delay(109.924427083);
delay(141.33140625);
tone(tonePin, 146, 98.931984375);
}
The only constructor that applies to a single parameter is an I2C connection. And an I2C address of 0 is the general call address.
And this seems to be specifying 32 columns, 16 lines, and an unsupported font mode.
This call passes a float
as the 3rd parameter when an unsigned long
is required.
And this call also passes a float
as the parameter when an unsigned long
is required.
Neither tonePin
, sensortem
, sensortem2
nor sensorfoto
are defined.
I could probably go on, but it is already apparent that your sketch will not compile, and even if it did compile, would not do whatever it is you are expecting it to do.
TinkerCAD's generic "invalid header file" message (which can be seen when an invalid call is made to a library, for example), would seem to be the least of your problems.
those variables are defined, I didn't copy the whole code by mistake, but I will try the first observations.
As I say the sketch compiled perfectly and I even try on my arduino then, I wanted to try adding and lcd, there is when it didn't compile.
It means that the code doesn't compile.
Please show your full code on the forum
Good luck with your project.
int tonePin = 8;
int sensortem2 = A2;
int sensorfoto = A1;
int sensortem = A0;
int sensorfoto2 = A3;
Adafruit_LiquidCrystal lcd_1(0);
void setup ()
{
lcd_1.begin(32, 16, 2);
pinMode(tonePin, OUTPUT);
}
void loop ()
{
int lectura = analogRead(sensortem);
int temperatura = map(lectura, 0, 1023, -50, 450);
int lectura2 = analogRead(sensortem2);
int temperatura2 = map(lectura2, 0, 1023, -50, 450);
int luz = analogRead(sensorfoto);
int luz2 = analogRead(sensorfoto2);
if(temperatura>=70 || temperatura2>=70)
{
lcd_1.setCursor(0, 1);
lcd_1.print("FIRE");
alarm ();
}
else if(luz==1022 && luz2==1022)
{
alarm ();
}
else
{
digitalWrite(8, LOW);
}
}
void alarm ()
{
tone(tonePin, 146, 98.931984375);
delay(109.924427083);
delay(15.7034895833);
tone(tonePin, 146, 98.931984375);
delay(109.924427083);
delay(141.33140625);
tone(tonePin, 146, 98.931984375);
}
The only change are the libraries and the rest of variables defined
So lets return to the code. Sorry, it is a mess.
Where you downloaded it? You didn't write this code yourself, did you?
Where did you get it, especially this line
and the lines with the delays?
First of all, I don't see any libraries inluded in your code. You must include a header to use a library, say a Adafruit_LiquidCrystal.h
Missing this...
#include <Adafruit_LiquidCrystal.h>
// Adafruit_LiquidCrystal lcd_1(0); // NOT THIS
Adafruit_LiquidCrystal lcd_1(12, 10, 5, 4, 3, 2);
// lcd_1.begin(32, 16, 2); // NOT THIS
lcd_1.begin(16, 2);
What is the meaning of these values? Where did you get the values?
This is probably too exact, and might not ever happen. Maybe...
else if (luz > 1018 && luz2 > 1019)
Where did you get this whole sketch?
Yeah... I don't know why the top/begin of the code desappear when I paste it here. But the libraries are just added from the Tinkercad's files so couldn't be the problem.
Yeah wrote it by myself, Sorry for the mess, I just started to learn 3 weeks ago more and less... I wrote everything except the parts related to lcd; libraries, set up commands and the commands in the conditional. I took them from the example Tinkercad give you of the lcd.
I didn't get why the delays are bad... Their rol is just make an space between commands, aren't they? That's what my teacher told me "delay(the time required on ms)".
The loop "alarm" is music (but it was too long that a just copied the beginning to show you), so it needs a short wait after every tone.
Where did you get the values?
Make your tone()
and delay()
look like the example, here:
https://docs.arduino.cc/language-reference/en/functions/advanced-io/tone/
It could be from the example HelloWorld_i2v from the Adafruit_LiquidCrystal library.
#include "Adafruit_LiquidCrystal.h"
// Connect via i2c, default address #0 (A0-A2 not jumpered)
Adafruit_LiquidCrystal lcd(0);

delay(109.924427083); delay(15.7034895833);
All those (and more) decimal places are nonsense.
delay() only accepts whole numbers, no decimal places.
There is delayMicroseconds() if you want a finer resolution, but it still only accepts integers.
Leo..
Ohh I didn't know that, I got the whole tone loop from a webtool that convert an Midi file into arduino tone.
@van_der_decken already told you in post#6: no floats.
Google can teach you about "variable types".
delay();
tone();
Leo..