Arduino Basics: Blink
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 :>
Do u know anything about arduino/bluetooth connections pls? I need help 4 skool
@xmasboy Do you have a Bluetooth module? First of all, 5v - 5v, ground - ground :D
I have everything I need and I have basic experience with arduino. I need help with the coding [email protected]
@xmasboy Yeah, what model of the Bluetooth module do you have? The code is different
I have to check @tussiez
@xmasboy K, let me know so I can find you a good tutorial
What do you want to do with the module?
hey i have been doing arduino for while now. We may work together with arduino :D i also use tinkercad
@tussiez yo dude can ya help me?
idk if your even online dude @tussiez
Hello @CyberHacker101
Busy today :/
ok, no problemo @tussiez
ima call it a day @tussiez
@CyberHacker101 Also, how did my tutorial get so many upvotes?!
welp you got lots of ppl who like ur posts @tussiez
@CyberHacker101 Yey, but I think other tutorials like mine should get more upvotes, this is medium-effort
lol oof @tussiez
You have 666 cycles now
@programmeruser Phew, I have 667 now
wait Arduino on repl.it?
@tussiez CAN YOU USE ARDUINO ON REPL.IT???
ALSO SMH EVERYTIME I COMMENT ON YOUR POSTS YOU REPLY WITH "?"
@zplusfour
1 nope
2 Yeah IDK replacing WDYM or huh with ? became a habit somehow
@tussiez
1. ok sir
2. I think wdym is fine :)
@programmeruser yey!!
But nah i'll learn raspberry pi
@zplusfour Wdym by "learn" RPi?
@tussiez learn how to use it silly
@zplusfour I see what you mean - learning single-board computing, otherwise it's just a computer.
@tussiez exactly!!
If you don't want to buy a Arduino: htttps://tinkercad.com
I don't have one but I do have a ESP32.
@programmeruser I wanna get an ESP32 sometime, last time I checked they were insanely cheap (~$4 w/free shipping) on Ebay
EDIT: ESP32 ESP8266
@tussiez what's wrong with the ESP32?
@programmeruser Nothing, the ESP8266 I saw is 4$ not the ESP32
@programmeruser Either way I would want to get one
@tussiez it's only $10, but I would understand if that was too much
@programmeruser Eh I'll buy one of them eventually
@zplusfour httttttps
@tussiez "heeps".replaceAll("e", "t")
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
@Whippingdot Oo &
;(
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.
@elipie Wouldn't be a bit.. complex?
Tinkercad has an Arduino simulator, check there :D
@tussiez still, it would be a nice challenge. it is def possible though
@elipie Yeah :>
This is pog becuase i want blinking lights for my "Game" also do you guys like my bio?
@Rainbowryan Yee
Lights for a game?
@tussiez Yes my "Game"
@Rainbowryan Arduino game?
@tussiez "Game" ok fine its a light
@tussiez This isent a joke
"Video games are sirius subjects and should be treated with respect"-TechnoBlade king of minecraft
@Rainbowryan
Resepcc
awesome tutorial dude anyways wat in the world have been doing with my multiplayer test lol
Good tutorial!
@foodandmoarfood Thanks!
WHOOO ARE YOOOOOOU UNKNOW PERSON???? @foodandmoarfood
youve got good repl its dude @foodandmoarfood
@CyberHacker101 Mai Friend lol
lol, he comments on everything and I became a sus DONT SUE ME @tussiez
@CyberHacker101 :flushed:
OH GOD STOP THE PINGS IM GONNA DIE @tussiez
"OH GOD STOP THE PINGS IM GONNA DIE" - Most used words online @tussiez
@CyberHacker101 LOl
dude im now geting pinged from OTHER Webs @tussiez
@CyberHacker101 !
REEEEEEEEE PING DO DEEP WAP POOOO @tussiez
@CyberHacker101 ping pong
PING THE WING OF THE PINGEY THING BOIII @tussiez
im going insane @tussiez
@CyberHacker101 !!
lol :!?) @tussiez
p i n g
@foodandmoarfood !!!!!!!!11
PING INFERNO MA DUDE @foodandmoarfood
@CyberHacker101
MORE PING
@foodandmoarfood
A a a
Dude Im getting pinged by the same person 45 times @foodandmoarfood
@CyberHacker101 Ping ping
PING PING DUCKY BOI @tussiez
@CyberHacker101
PING PONGtable tennisTING TONGdoorbell @tussiez@CyberHacker101
[insert your doorbell chime here]
lol @tussiez
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 B O I
L O L
Im having a feeling that lol is the only word i use@tussiez@CyberHacker101
@angrydoge (haha ping) invented new word
S
A
J
J
= SadSANJJ GO BE SOOO NAAAAAA WEGER OGEA
is this what i do every day@tussiez@CyberHacker101 When you commit big sajj
Screaming fatt indian noise@tussiez@CyberHacker101
a a A
yo dude you busy? @tussiez
@CyberHacker101 kinda lol HW
LOL wait i mean LMAO that works doesn't it @tussiez
@CyberHacker101 lol
17 notifs
High pitched screaming
@foodandmoarfood A A A