HELP, it's for a school project

Hello, I'm new to this Arduino thing and I don't understand much about the basics of its programming, I recently tried to run this code that I took from a YouTube video, the guy only left a link to his page with the code and at no time did he talk about the code.

This is from the page with the code, if someone can help tell me what is wrong with the code I will be eternally grateful!!!

Post the code.
In code tags

Maybe you can indicate what the problem is that you have? Does it not compile? Can't you upload? If you can upload, what do you expect it to do and what does it do that you did not expect it to do?

get rid of the HTML code that made it's way in the source code

then it will compile fine on a UNO

please be eternally grateful now. I expect nothing less :slight_smile:

1 Like

Help😭

//Robot UNO
//Proyecto -> Barrera con contraseƱa

#include <Servo.h>
#include <Keypad.h>

char contrasena[]="1234"; //NUMERO DE LA CONTRASEƑA
char codigo[4];
int cont=0;
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
Servo servomotor;
int valor;

void setup(){
servomotor.attach(11,1000,2000);
Serial.begin(9600);
}

void loop(){
char customKey = customKeypad.getKey();
servomotor.write(0);
if (customKey != NO_KEY){
codigo[cont]=customKey;
Serial.print(codigo[cont]);
cont++;
if(cont==4){
if(codigo[0]==contrasena[0]&&codigo[1]==contrasena[1]&&codigo[2]==contrasena[2]&&codigo[3]==contrasena[3]){
digitalWrite(13,!digitalRead(13));
Serial.println(" ContraseƱa correcta");
servomotor.write(180);
delay(5000); //TIEMPO QUE SE MANTIENE SUBIDA LA BARRERA (en ms)
servomotor.write(0);
}
else if(codigo[0]!=contrasena[0]||codigo[1]!=contrasena[1]||codigo[2]!=contrasena[2]||codigo[3]!=contrasena[3]){
Serial.println(" ContraseƱa incorrecta");
}
cont=0;
}
}
}

try

//Robot UNO
//Proyecto -> Barrera con contraseƱa

#include <Servo.h>
#include <Keypad.h>

char contrasena[] = "1234"; //NUMERO DE LA CONTRASEƑA
char codigo[4];
int cont = 0;
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
Servo servomotor;
int valor;
void setup() {
  servomotor.attach(11, 1000, 2000);
  Serial.begin(9600);
}
void loop() {
  char customKey = customKeypad.getKey();
  servomotor.write(0);
  if (customKey != NO_KEY) {
    codigo[cont] = customKey;
    Serial.print(codigo[cont]);
    cont++;
    if (cont == 4) {
      if (codigo[0] == contrasena[0] && codigo[1] == contrasena[1] && codigo[2] == contrasena[2] && codigo[3] == contrasena[3]) {
        digitalWrite(13, !digitalRead(13));
        Serial.println("   ContraseƱa correcta");
        servomotor.write(180);
        delay(5000); //TIEMPO QUE SE MANTIENE SUBIDA LA BARRERA (en ms)
        servomotor.write(0);
      }
      else if (codigo[0] != contrasena[0] || codigo[1] != contrasena[1] || codigo[2] != contrasena[2] || codigo[3] != contrasena[3]) {
        Serial.println("   ContraseƱa incorrecta");
      }
      cont = 0;
    }
  }
}

not work's :frowning:

this does not mean anything. What did you try, do etc...

PLEASE USE CODE TAGS... (I'll trade the eternal gratefulness for the code tags)

āžœ please read How to get the best out of this forum and modify your post accordingly (including code tags).

1 Like

it compiles fine for Arduino UNO on my Mac. (the ; or the } that were in the red circle were not to be removed)

No more answer if you don't fix your posts and add code tags.

1 Like

Did it occur to you, maybe this is not a good place to find code?

1 Like

Remember also always, when it is for a school project, to mention how long the project has been going on or when was the assignment given. And when is the assignment due. Why? Because it usually gives a very good picture of how committed you are to learning something.

//Robot UNO
//Proyecto -> Barrera con contraseƱa

#include <Servo.h>
#include <Keypad.h>

char contrasena[]="1234"; //NUMERO DE LA CONTRASEƑA
char codigo[4];
int cont=0;
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
Servo servomotor;
int valor;
when i quit this valor ''br'', this problem appear: a function-definition is not allowed here before '{' token
void setup(){ and the error jumps here
servomotor.attach(11,1000,2000);
Serial.begin(9600);
}

void loop(){
char customKey = customKeypad.getKey();
servomotor.write(0);
if (customKey != NO_KEY){
codigo[cont]=customKey;
Serial.print(codigo[cont]);
cont++;
if(cont==4){
if(codigo[0]==contrasena[0]&&codigo[1]==contrasena[1]&&codigo[2]==contrasena[2]&&codigo[3]==contrasena[3]){
digitalWrite(13,!digitalRead(13));
Serial.println(" ContraseƱa correcta");
servomotor.write(180);
delay(5000); //TIEMPO QUE SE MANTIENE SUBIDA LA BARRERA (en ms)
servomotor.write(0);
}
else if(codigo[0]!=contrasena[0]||codigo[1]!=contrasena[1]||codigo[2]!=contrasena[2]||codigo[3]!=contrasena[3]){
Serial.println(" ContraseƱa incorrecta");
}
cont=0;
}
}
}

still no code tags. too bad. seems you can't follow the simple instructions from How to get the best out of this forum...

Probably programming is not for you as it requires discipline.

Good luck.

  1. Use the Auto Format function in the Arduino IDE editor: ctrl + T

  2. Copy-paste your code here after using ctrl + T.

  3. Use code tags around your code here. Highlight all your code but not your text you write here, and click on this button:
    image

If you don't follow these rules, everyone will think you're just an arrogant pupil trying to make other do his homework. I have a feeling J-M-L thinks so.

on my way there, waiting for a proof it was just a momentary lapse of reason

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.