I made a project using the Arduino NANO, which worked perfectly in TINKERCAD, but when we upload it to the arduino, it gives an error.
Project:
#include <Adafruit_LiquidCrystal.h>
#include <math.h>
Adafruit_LiquidCrystal lcd(0);
byte lampada[8]={B00000,B00100,B10101,B10001,B00000,B01110,B10001,B11111};
//Portas
#define botao_av 5
#define botao_en 4
#define botao_re 3
#define ledver1 2
#define rele 8
#define ledazul 11
#define ledverde 10
#define ledvermelho 9
//----------------------------------------//
//Verificar botoes
bool L_botao_av = 1; //variável para fazer a leitura do botão (MAIS)
bool LA_botao_av = 1; //variável para verificar a leitura anterior do botão (MAIS)
bool L_botao_en = 1; //variável para fazer a leitura do botão (ENTER/VOLTAR)
bool LA_botao_en = 1; //variável para verificar a leitura anterior do botão (ENTER/VOLTAR)
bool L_botao_re = 1; //variável para fazer a leitura do botão (MENOS)
bool LA_botao_re = 1; //variável para verificar a leitura anterior do botão (MENOS)
//----------------------------------------//
int tela = 1; //variável para controlar a mudança de tela no menu
//----------------------------------------//
// Variaveis globais
float leitura = 0;
float lux;
float lux_A;
float v = 0;
float corrente;
float vLDR = 0;
float media;
float LDR;
float valorLDR = 0; //Leitura inicial do LDR
int N = 1; // Contador
void setup() {
digitalWrite(ledver1, HIGH);
lcd.begin(16,2);
lcd.createChar(1,lampada);
lcd.clear(); //limpa todos os caracteres do lcd
lcd.setCursor(0,0); //posiciona o cursor no display (caracter, linha)
lcd.write(1);
lcd.print(" Sensor Luz "); //imprime o texto entre aspas
lcd.write(1);
lcd.setCursor(0,1); //posiciona o cursor no display (caracter, linha)
lcd.print(" Aguarde... "); //imprime o texto entre aspas
delay (100);
lcd.clear();
// Indicando as portas de entrada e de saida de dados
Serial.begin(9600);
pinMode(ledazul , OUTPUT);
pinMode(ledverde , OUTPUT);
pinMode(ledvermelho , OUTPUT);
pinMode(LDR , INPUT);
pinMode(rele, OUTPUT);
pinMode(botao_av, INPUT_PULLUP);
pinMode(botao_en, INPUT_PULLUP);
pinMode(botao_re, INPUT_PULLUP);
}
void loop() {
N++;
LDR = analogRead(A0); // le o pino de entrada
v = (LDR*5)/1023; // converte o valor lido para tensao
corrente = v/1000; // Calcula a corrente do sistema
vLDR = ((5-v)/corrente); // calcula a resistencia do LDR
lux_A= 255.84*pow(vLDR, -10/9); // eq. da luminosidade
lux = lux_A *100;
media = ((media * N + lux)/(N+1));
Serial.println(lux);
leituraLeds();
//------------Alternar entre telas pelo botão------------//
// === Ações no display LCD === //
if (tela==1){ //se a variável tela for igual a MAIS, faça...
lcd.setCursor(0,0); //posiciona o cursor no display (caracter, linha)
lcd.print("<< SELECIONE >>"); //imprime o texto entre aspas
lcd.setCursor(0,1); //posiciona o cursor no display (caracter, linha)
lcd.print(">Leitura atual "); //imprime o texto entre aspas
}
else if (tela==2){
lcd.setCursor(0,0);
lcd.print("<< SELECIONE >>");
lcd.setCursor(0,1);
lcd.print(">Max e Min ");
}
else if (tela==3){
lcd.setCursor(0,0);
lcd.print("<< SELECIONE >>");
lcd.setCursor(0,1);
lcd.print(">Media ");
}
else if (tela==10){
lcd.setCursor(0,0);
lcd.print(" :: LEITURA :: ");
leitor_A();
}
else if (tela==20){
lcd.setCursor(0,0);
lcd.print(" :: MAX E MIN ::");
Mx();
}
else if (tela==30){
lcd.setCursor(0,0);
lcd.print(" :: MEDIA :: ");
Media();
}
L_botao_av = digitalRead(botao_av);
if (!L_botao_av && LA_botao_av) {
if (tela==1)tela=2;
else if (tela==2)tela=3;
else if (tela==3)tela=1;
}
LA_botao_av = L_botao_av;
L_botao_re = digitalRead(botao_re);
if (!L_botao_re && LA_botao_re) {
if (tela==1)tela=3;
else if (tela==2)tela=1;
else if (tela==3)tela=2;
}
LA_botao_re = L_botao_re;
L_botao_en = digitalRead(botao_en);
if (!L_botao_en && LA_botao_en) {
if (tela==1)tela=10;
else if (tela==2)tela=20;
else if (tela==3)tela=30;
else if (tela==10)tela=1;
else if (tela==20)tela=2;
else if (tela==30)tela=3;
}
LA_botao_en = L_botao_en;
}
void lerDados(){
lux=lux;
}
void leituraLeds(){ // Função responsável por verificar o estados dos LED's e da carga
valorLDR = analogRead(A0);
if (valorLDR < 50){
apagaLeds();
digitalWrite(rele, HIGH);
digitalWrite(ledazul, HIGH);
}
// Luminosidade média
if(valorLDR >= 50 && valorLDR<140){
apagaLeds();
digitalWrite(rele, HIGH);
digitalWrite(ledverde, HIGH);
}
if(valorLDR>140.4){
apagaLeds();
digitalWrite(ledvermelho, HIGH);
}
}
void apagaLeds(){ // Para apagar o LED's e a Carga
digitalWrite(rele, LOW);
digitalWrite(ledazul, LOW);
digitalWrite(ledverde, LOW);
digitalWrite(ledvermelho, LOW);
}
//-----------------------------------------------------------//
void Mx(){
lerDados();
lcd.setCursor (0, 1);
lcd.print(" ");
static int maior = 0;
maior = max(maior, lux);
lcd.setCursor (0, 1);
lcd.print("Max:");
lcd.print(maior);
lcd.setCursor (7, 1);
lcd.print(" ");
static int menor = 1;
menor = min(menor, lux);
lcd.setCursor (9, 1);
lcd.print("Min:");
lcd.print(menor);
delay(3000);
}
void Media(){
lerDados();
Serial.print(" | ");
Serial.print(N);
lcd.setCursor (0, 1);
lcd.print(" ");
lcd.setCursor (0, 1);
lcd.print("Media:");
lcd.print(media);
lcd.print(" Lux");
delay(3000);
}
void leitor_A(){ // caso A
lerDados();
lcd.setCursor (0, 1);
lcd.print("Lum:");
lcd.print(lux);
lcd.print(" lux ");
Serial.print(" | ");
Serial.print("Valor LDR(volts): ");
Serial.println(v); //imprime a media com 5 casas decimais
} // Fim do algoritmo
The error that appears:
Sketch uses 9932 bytes (32%) of program storage space. Maximum is 30720 bytes.
Global variables use 725 bytes (35%) of dynamic memory, leaving 1323 bytes for local variables. Maximum is 2048 bytes.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x80
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x80
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x80
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x80
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x80
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x80
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x80
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x80
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x80
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x80
Failed uploading: uploading error: exit status 1
I need Help...