CODING: LED

To light up an LED we would normally connect one leg (anode) to the +ve side of a battery and the other end to the -ve end of the battery.

With the Arduino we connect the anode side of the LED to a pin (we have chosen pin 2), this will act like the +ve terminal of your battery and the other end of the LED to a ground pin also on the Arduino. We will then write code to tell the Arduino to send electricity (5V) to pin 2. The electricity will then flow from pin 2, through the LED (and the resistor attached to the LED) and back to ground, closing the circuit and making the LED glow. 

When you wired TURL-X you connected the LED to pin 2 and ground.  

From PIN (red) to GROUND (black), closes the circuit

This code will flash the LED for 1 second.

Let’s break it down.

There are 2 main areas:
The first is the setup. When the Arduino turns on it will do this first. It’s like your morning routine, you wake up, get dressed, brush your teeth etc. It only does it once.
The second is the loop. Whatever you have here the Arduino will do over and over again, that’s why its called a loop.
Think of pin 2 like a light switch on your wall.
pinMode(2, OUTPUT) is you saying ‘this switch is allowed to control a light’.
digitalWrite(2, HIGH) is you flipping the switch up → light turns on!
digitalWrite(2, LOW) is flipping it down light off.

Imagine how long it would take you to drink 1 liter of soda if you could only sip 1 milliliter at a time. Forever! So instead of counting in big chunky ‘seconds’ (which would be too slow for precise blinking LEDs or quick reactions), the Arduino splits every second into 1000 tiny pieces called milliseconds — just like 1 liter = 1000 milliliters (ml). 

  • 1000 ms = 1 second 
  • So when you write delay(1000); → the Arduino waits exactly 1 second (1000 little ms ticks)
  • delay(500); → waits half a second (500 ml out of a liter)
  • delay(10); → waits only 1/100th of a second — super quick blink!

That’s why we almost always use milliseconds in code — it lets you control timing way more precisely, like choosing exactly how fast your LED flashes or how long a buzzer beeps.

Now it is your turn!

Open your Arduino IDE, go to File (top left corner) and choose New Sketch.

Delete everything on the screen, the setup and loop sections (as shown below). 

Copy the code below by clicking on the button “Copy Code to Clipboard”. Right click the mouse button on the IDE open page and paste the code.
Make sure you have set up your Arduino properly as shown in Setting Up 

 

Click the Upload button as shown here (top left corner, arrow pointing to the right).
If you set up everything correctly your TURL-X should have a blinking nose.

Congratulations!

Now experiment with the code. Change the delay time and make it blink faster or slower.

NEXT UP..