Programing leds with an arduino and making it move with a, d on the serial monitor

int led = 2; //variable del LED a encender
char ans; //Caracter ingresado por el usuaro

void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
Serial.begin(9600); //Iniciamos la comunicación serial

void loop() {
if (Serial.available() > 0) {
ans =;
if (ans == 'a'){
if (led > 2)
else if (ans == 'd') {
if (led < 6)
digitalWrite(led, HIGH);
digitalWrite(led - 1, LOW);
digitalWrite(led + 1, LOW);

Then enter to this link so you can see the circuit

I don't have (or want) a TinkerCAD account.

You don't have code tags.

Why does "ans" have global scope?
I'm not mad keen on writing to the serial port's pins

What is the question?

You dont need a tinkercad acount to see it

What question

the protject is ok it didt have errors.

you just need to open serial and press a + enter for moving to the right.
d + enter to the left

sp. "The code didn't have any compilation errors" (i.e. syntax errors)

Not the same thing as the code not having any semantic errors. Which it does.

if (led > 2)

Imagine here that "led" has the value 2, so "led" is not greater than 2, so gets decremented, and is now 1.

digitalWrite(led, HIGH);
digitalWrite(led - 1, LOW);
digitalWrite(led + 1, LOW);

Pin "led" (aka 1) is Serial Tx, and pin "led-1" (aka 0) is Serial Rx.

I still can't see the circuit. Or any code tags.

Thank you for your your

Thank you for your thank-you.

I still can't see a schematic.

I'm calling right now to tinkercad so i can see if you without an account can see the circuit

I am going to make the circuit in a diagram but i´m going to try make it on another app you can see the circuit on the tinkercad

No, I can't see the circuit on TinkerCAD without a link to it

That's a link to TinkerCAD, not a link to your schematic

i dont have an schematic

Ok, it isn't a link to "the circuit" either

im gona talk with tinkercad}

or im gonna create you an account

That's very presumptuous - you're assuming
A) you can
B) I want one.

yes i have noticed