Hi everyone! I'm from Brazil, so sorry if the english is not that good. I've studied elotronics some time ago, but I've never got into programing and haven´t used that knowledge in quite some time, so sorry if there's something basic I'm missing.
I'm trying to use tinkercad to simulate a circuit that lets you choose for how long a motor will be functioning and than start the motor. I'm using diferent AIs to help me build it, but I'm stuck and not evolving from the AIs. I even tried to take all the other components off the circuit and use a "hello World" code to test it, but it doesn't work. The arduino uno turns on and the LCD backlight as well, but no text is displayed. It´s not about the contrast, because even if I messe with the potenciometer nothing diferent happens.
I'm going to put the conections in here, as well as the code that the AIs wrote. Any insight is more than helpfull
The motor has the negative connection to the GND of the Arduino, while the positive is connected to the C output of the TIP 120. There is a diode connected in parallel to the motor's power supply.
The TIP 120 transistor connects its E terminal to the negative rail of the breadboard, while the B terminal is connected to pin 5 of the Arduino, with a resistor to protect the component.
The trigger switch has terminal 2b connected to the positive rail on the breadboard, while terminal 1a is connected to ground with a resistor. Terminal 1b is connected to pin 4 of the Arduino, while terminal 2a is not connected.
The LCD display follows the connections below:
- RS connected to pin 13
- E connected to pin 12
- D4 connected to pin 11
- D5 connected to pin 10
- D6 connected to pin 9
- D7 connected to pin 8
- GND connected to the negative rail of the breadboard
- VCC connected to the positive rail of the breadboard
- V0 connected to the potentiometer that controls the LCD brightness
- RW connected to the negative rail of the breadboard
- DB0 is not connected to anything
- DB1 is not connected to anything
- DB2 is not connected to anything
- DB3 is not connected to anything
- LED anode is connected to power with a resistor
- LED cathode is connected to GND
The keypad follows the connections below:
- Row 1 connected to pin A0
- Row 2 connected to pin A1
- Row 3 connected to pin A2
- Row 4 connected to pin A3
- Column 1 connected to pin A4
- Column 2 connected to pin A5
- Column 3 connected to pin 6
- Column 4 connected to pin 7
The code I'm trying right now is the following, wrote by Deepseek (I've tried ChatGPT, Gemini and Copilot, all with the same result). The only test code that seemed to work is one that makes the L LED of the arduino blink, all the others had the same result, LCD backlight goes on and displays nothing. The tinkercad doesn't indicate any problem with the code.
// Configurações do LCD (sem I2C)
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8); // Novos pinos: RS, E, D4, D5, D6, D7
// Configurações do teclado 4x4
const byte ROWS = 4; // 4 linhas
const byte COLS = 4; // 4 colunas
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {A0, A1, A2, A3}; // Conectar às linhas do teclado
byte colPins[COLS] = {A4, A5, 6, 7}; // Conectar às colunas do teclado
// Pino do motor (conectado ao transistor)
const int motorPin = 5; // Base do transistor (controla o motor)
// Pino do switch
const int switchPin = 4;
// Variáveis
unsigned long motorTime = 5000; // Tempo padrão de ativação do motor (5 segundos)
bool motorRunning = false;
unsigned long motorStartTime = 0;
void setup() {
// Inicializa o LCD
lcd.begin(16, 2);
lcd.print("Tempo Motor:");
lcd.setCursor(0, 1);
lcd.print(motorTime / 1000);
lcd.print(" seg");
// Configura o pino do motor
pinMode(motorPin, OUTPUT);
digitalWrite(motorPin, LOW); // Inicia com o motor desligado
// Configura o pino do switch
pinMode(switchPin, INPUT_PULLUP);
// Configura os pinos do teclado
for (byte r = 0; r < ROWS; r++) {
pinMode(rowPins[r], OUTPUT);
digitalWrite(rowPins[r], HIGH); // Desativa as linhas
}
for (byte c = 0; c < COLS; c++) {
pinMode(colPins[c], INPUT_PULLUP); // Configura as colunas como entrada com pull-up
}
}
void loop() {
// Verifica se o switch foi pressionado
if (digitalRead(switchPin) == LOW && !motorRunning) {
motorRunning = true;
motorStartTime = millis();
digitalWrite(motorPin, HIGH); // Liga o motor
lcd.setCursor(0, 1);
lcd.print("Motor ON ");
}
// Verifica se o tempo de ativação do motor acabou
if (motorRunning && (millis() - motorStartTime >= motorTime)) {
motorRunning = false;
digitalWrite(motorPin, LOW); // Desliga o motor
lcd.setCursor(0, 1);
lcd.print("Motor OFF");
}
// Verifica a entrada do teclado para alterar o tempo
char key = getKey();
if (key) {
if (key >= '0' && key <= '9') {
motorTime = (motorTime * 10) + ((key - '0') * 1000);
if (motorTime > 60000) motorTime = 1000; // Limite máximo de 60 segundos
lcd.setCursor(0, 1);
lcd.print(motorTime / 1000);
lcd.print(" seg");
} else if (key == 'C') {
motorTime = 1000; // Reseta para 1 segundo
lcd.setCursor(0, 1);
lcd.print(motorTime / 1000);
lcd.print(" seg");
}
}
}
// Função para ler o teclado matricial
char getKey() {
for (byte r = 0; r < ROWS; r++) {
digitalWrite(rowPins[r], LOW); // Ativa a linha
for (byte c = 0; c < COLS; c++) {
if (digitalRead(colPins[c]) == LOW) {
digitalWrite(rowPins[r], HIGH); // Desativa a linha
return keys[r][c]; // Retorna a tecla pressionada
}
}
digitalWrite(rowPins[r], HIGH); // Desativa a linha
}
return 0; // Nenhuma tecla pressionada
}