Learn to Code via Tutorials on Repl.it!

← Back to all posts
Arduino Basics: Blink
tussiez

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.

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 :>

Voters
Joelprogsie
Eubraboprogram
Unclyscam123
rammonsnova
JanWahib
xmasboy
Bumblebee99
kuldeepSinghSin
YuriPinheiro22
Cricket14
Comments
hotnewtop
foodandmoarfood

Good tutorial!

tussiez
CyberHacker101

WHOOO ARE YOOOOOOU UNKNOW PERSON???? @foodandmoarfood

CyberHacker101

youve got good repl its dude @foodandmoarfood

tussiez

@CyberHacker101 Mai Friend lol

CyberHacker101

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

tussiez

@CyberHacker101 :flushed:

CyberHacker101

OH GOD STOP THE PINGS IM GONNA DIE @tussiez

CyberHacker101

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

tussiez
CyberHacker101

dude im now geting pinged from OTHER Webs @tussiez

tussiez
CyberHacker101

REEEEEEEEE PING DO DEEP WAP POOOO @tussiez

tussiez

@CyberHacker101 ping pong

CyberHacker101

PING THE WING OF THE PINGEY THING BOIII @tussiez

CyberHacker101

im going insane @tussiez

tussiez
CyberHacker101

lol :!?) @tussiez

foodandmoarfood

p i n g

tussiez

@foodandmoarfood !!!!!!!!11

CyberHacker101

PING INFERNO MA DUDE @foodandmoarfood

foodandmoarfood
tussiez
CyberHacker101

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

tussiez

@CyberHacker101 Ping ping

CyberHacker101

PING PING DUCKY BOI @tussiez

tussiez

@CyberHacker101 PING PONG table tennis

CyberHacker101

TING TONG doorbell @tussiez

tussiez

@CyberHacker101
[insert your doorbell chime here]

CyberHacker101
CyberHacker101

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

tussiez
CyberHacker101

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

tussiez

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

CyberHacker101

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

tussiez

@CyberHacker101 When you commit big sajj

CyberHacker101

Screaming fatt indian noise @tussiez

tussiez
CyberHacker101

yo dude you busy? @tussiez

tussiez

@CyberHacker101 kinda lol HW

CyberHacker101

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

tussiez
foodandmoarfood

17 notifs
High pitched screaming

tussiez
xmasboy

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

tussiez

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

xmasboy

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

tussiez

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

xmasboy

I have to check @tussiez

tussiez

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

EvanMaksud

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

tussiez
CyberHacker101

@tussiez yo dude can ya help me?

CyberHacker101

idk if your even online dude @tussiez

tussiez

Hello @CyberHacker101
Busy today :/

CyberHacker101

ok, no problemo @tussiez

CyberHacker101

ima call it a day @tussiez

tussiez

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

CyberHacker101

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

tussiez

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

CyberHacker101

lol oof @tussiez

programmeruser

You have 666 cycles now

tussiez
tussiez

@programmeruser Phew, I have 667 now

zplusfour

wait Arduino on repl.it?

tussiez
zplusfour

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

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

tussiez

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

zplusfour

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

programmeruser
zplusfour

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

tussiez

@zplusfour Wdym by "learn" RPi?

zplusfour

@tussiez learn how to use it silly

tussiez

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

zplusfour

@tussiez exactly!!

programmeruser

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

tussiez

@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

@tussiez what's wrong with the ESP32?

tussiez

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

tussiez

@programmeruser Either way I would want to get one

programmeruser

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

tussiez

@programmeruser Eh I'll buy one of them eventually

zplusfour
tussiez

@zplusfour httttttps

zplusfour

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

Whippingdot

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

tussiez

@Whippingdot Oo &
;(

elipie

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

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

elipie

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

tussiez

@elipie Yeah :>

elipie
tussiez
programmeruser
tussiez
RainBowLion1

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

tussiez

@Rainbowryan Yee
Lights for a game?

RainBowLion1

@tussiez Yes my "Game"

tussiez

@Rainbowryan Arduino game?

RainBowLion1

@tussiez "Game" ok fine its a light

tussiez
RainBowLion1

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

tussiez
CyberHacker101

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

tussiez