Learn to Code via Tutorials on Repl.it!

← Back to all posts
Arduino Basics: Blink
tussiez (1668)

Arduino Blink

This will make an LED on an Arduino Uno blink.

Setup

What you'll need:

  • Arduino IDE
  • Printer USB cable
  • Computer
  • Arduino Uno
  • Basic understanding of code syntax

Note

Running this code in Repl.it does not work. You must compile and execute this code in the Arduino IDE.

Code Basics

Starting from the top:
Arduino C++ is similar to normal C++. If you come from another language, indentations do not matter here, as brackets are used. This language is similar to JavaScript.

void defines a function. You can use this to.. define functions in your script.

void setup(){} is a function that runs first, and only once, in an Arduino program. Typically you use this for "run-once" code, e.g defining pins, getting X data, etc

void loop(){} is the function that runs immediately after setup, and runs in a continous loop until the Arduino is unplugged.

Now that we've gone over the "basics", let's move on to the Blink code.

Blink

Running the code below will result in your Arduino's LED blinking.

void setup(){
  pinMode(13, OUTPUT); 
  //or replace 13 w/LED_BUILTIN
}

void loop(){
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
  delay(1000);
}

pinMode(13, OUTPUT) tells the Arduino that pin 13 is an output.
This will also control the built-in LED, as the LED is tied to this pin. You can also use LED_BUILTIN.

digitalWrite(13, HIGH) changes the voltage of pin 13. HIGH sets this to 5V, and low sets this to 0.

delay(1000) makes the loop wait 1000 milliseconds (1 second).

Uploading Code

First, you'll need to download and install the Arduino IDE.

Now, connect your Arduino using a USB cable to your computer. It should now turn on. If it doesn't, try another USB port, or if the green ON light never turns on, your Arduino is probably dead.

Moving on:
Open the Arduino IDE and paste (or write!) the code shown earlier into a new file.

Press Verify, the checkmark, at the top, to make sure your code is syntactically correct. If not, nothing will happen when you upload your code.

At this point, you'll need to set the serial port for the IDE to send your (compiled) code over.

In the top left corner, click "Tools" to open a dropdown menu. In this dropdown, click "Port" and select the option labeled with "Arduino" on it. If nothing shows up, reconnect your Arduino and repeat this step.

Now that you've selected a port, you can upload your code!
Press the arrow button to upload your code to the Arduino. If all goes well and no errors show up, the LED on your board should be blinking.

Hope you enjoyed this tutorial!
Tell me if I made any typos/mistakes in this, as I haven't written Arduino C++ in a while :>

Comments
hotnewtop
CyberHacker101 (128)

WHOOO ARE YOOOOOOU UNKNOW PERSON???? @foodandmoarfood

CyberHacker101 (128)

lol, he comments on everything and I became a sus DONT SUE ME @tussiez

CyberHacker101 (128)

OH GOD STOP THE PINGS IM GONNA DIE @tussiez

CyberHacker101 (128)

"OH GOD STOP THE PINGS IM GONNA DIE" - Most used words online @tussiez

CyberHacker101 (128)

dude im now geting pinged from OTHER Webs @tussiez

CyberHacker101 (128)

REEEEEEEEE PING DO DEEP WAP POOOO @tussiez

CyberHacker101 (128)

PING THE WING OF THE PINGEY THING BOIII @tussiez

CyberHacker101 (128)

Dude Im getting pinged by the same person 45 times @foodandmoarfood

tussiez (1668)

@CyberHacker101
[insert your doorbell chime here]

CyberHacker101 (128)

dude my teacher ended the whole meeting instead of the breakout rooms me and 3 other kids are on the zoom now only. CLASS IS DISMISSED BOI @tussiez

CyberHacker101 (128)

L O L Im having a feeling that lol is the only word i use @tussiez

tussiez (1668)

@CyberHacker101
@angrydoge (haha ping) invented new word
S A J J = Sad

CyberHacker101 (128)

SANJJ GO BE SOOO NAAAAAA WEGER OGEA is this what i do every day @tussiez

CyberHacker101 (128)

Screaming fatt indian noise @tussiez

CyberHacker101 (128)

LOL wait i mean LMAO that works doesn't it @tussiez

foodandmoarfood (15)

17 notifs
High pitched screaming

xmasboy (4)

Do u know anything about arduino/bluetooth connections pls? I need help 4 skool

tussiez (1668)

@xmasboy Do you have a Bluetooth module? First of all, 5v - 5v, ground - ground :D

xmasboy (4)

I have everything I need and I have basic experience with arduino. I need help with the coding [email protected]

tussiez (1668)

@xmasboy Yeah, what model of the Bluetooth module do you have? The code is different

tussiez (1668)

@xmasboy K, let me know so I can find you a good tutorial
What do you want to do with the module?

EvanMaksud (2)

hey i have been doing arduino for while now. We may work together with arduino :D i also use tinkercad

CyberHacker101 (128)

idk if your even online dude @tussiez

tussiez (1668)

@CyberHacker101 Also, how did my tutorial get so many upvotes?!

CyberHacker101 (128)

welp you got lots of ppl who like ur posts @tussiez

tussiez (1668)

@CyberHacker101 Yey, but I think other tutorials like mine should get more upvotes, this is medium-effort

zplusfour (901)

wait Arduino on repl.it?

zplusfour (901)

@tussiez CAN YOU USE ARDUINO ON REPL.IT???

ALSO SMH EVERYTIME I COMMENT ON YOUR POSTS YOU REPLY WITH "?"

tussiez (1668)

@zplusfour
1 nope
2 Yeah IDK replacing WDYM or huh with ? became a habit somehow

zplusfour (901)

@tussiez
1. ok sir
2. I think wdym is fine :)

zplusfour (901)

@programmeruser yey!!
But nah i'll learn raspberry pi

zplusfour (901)

@tussiez learn how to use it silly

tussiez (1668)

@zplusfour I see what you mean - learning single-board computing, otherwise it's just a computer.

programmeruser (596)

If you don't want to buy a Arduino: htttps://tinkercad.com
I don't have one but I do have a ESP32.

tussiez (1668)

@programmeruser I wanna get an ESP32 sometime, last time I checked they were insanely cheap (~$4 w/free shipping) on Ebay

EDIT: ESP32 ESP8266

programmeruser (596)

@tussiez what's wrong with the ESP32?

tussiez (1668)

@programmeruser Nothing, the ESP8266 I saw is 4$ not the ESP32

tussiez (1668)

@programmeruser Either way I would want to get one

programmeruser (596)

@tussiez it's only $10, but I would understand if that was too much

tussiez (1668)

@programmeruser Eh I'll buy one of them eventually

zplusfour (901)

@tussiez "heeps".replaceAll("e", "t")

Whippingdot (657)

I made a good tutorial and no one even looked at it 😭😭 BTW i will send this to my friend he has some arduino thing or smthing

elipie (353)

wouldnt it be cool if there was an Arduino emulator on replit? (oh editing: i found a language suggestion for emulator... YESS PLEASE) or maybe a community member could make one... oh YOU CHALLENGE ME? I WILL GET STRAIGHT TO WORK.

tussiez (1668)

@elipie Wouldn't be a bit.. complex?
Tinkercad has an Arduino simulator, check there :D

elipie (353)

@tussiez still, it would be a nice challenge. it is def possible though

RainBowLion1 (6)

This is pog becuase i want blinking lights for my "Game" also do you guys like my bio?

RainBowLion1 (6)

@tussiez "Game" ok fine its a light

RainBowLion1 (6)

@tussiez This isent a joke
"Video games are sirius subjects and should be treated with respect"-TechnoBlade king of minecraft

CyberHacker101 (128)

awesome tutorial dude anyways wat in the world have been doing with my multiplayer test lol