Chapterبەش 4 · Lectureوانە 4.1

Lab: Blink an LED and Build a Traffic Lightتاقیگە: LEDـێک بترووکێنە و گڵۆپێکی هاتوچۆ دروست بکە

Your first hands-on Arduino lab. Learn why every circuit needs a way back to GND, which leg of an LED is which, how to choose its resistor with Ohm's law for the UNO R3, UNO R4 and MKR WAN 1310, and what pinMode() and digitalWrite() do. Then blink an LED, see why delay() blocks, and build a traffic light — after spotting what is wrong with its first version.

یەکەم تاقیگەی دەستیی . فێر ببە بۆچی هەموو ڕێگایەکی گەڕانەوەی بۆ GND پێویستە، کام قاچی چییە، چۆن بە بۆ ⁦UNO R3⁩، ⁦UNO R4⁩ و ⁦MKR WAN 1310⁩ هەڵدەبژێریت و ⁦pinMode()⁩ و ⁦digitalWrite()⁩ چی دەکەن. پاشان بترووکێنە، بزانە بۆچی ⁦delay()⁩ ڕێگرە و گڵۆپێکی هاتوچۆ دروست بکە — دوای دۆزینەوەی هەڵەی یەکەم وەشانەکەی.

19 min read19 خولەک خوێندنەوە · 17 stepsهەنگاو

What you will learnچی فێر دەبیت

  • Explain GND and the complete circuit, and wire an LED with its resistor on a breadboard.
  • Tell the anode from the cathode and choose an LED's resistor with Ohm's law for 5 V and 3.3 V boards.
  • Use pinMode() and digitalWrite() with named pin constants.
  • Blink an LED, read a timing diagram and explain why delay() blocks.
  • Build a traffic light in the correct green → yellow → red order.
  • GND و تەواو ڕوون بکەرەوە و لەگەڵ لەسەر ببەستە.
  • لە جیا بکەرەوە و بە بۆ بۆردەکانی ⁦5 V⁩ و ⁦3.3 V⁩ هەڵبژێرە.
  • ⁦pinMode()⁩ و ⁦digitalWrite()⁩ لەگەڵ پینی ناودار بە بەکار بهێنە.
  • بترووکێنە، بخوێنەرەوە و ڕوون بکەرەوە بۆچی ⁦delay()⁩ ڕێگرە.
  • گڵۆپێکی هاتوچۆ بە ڕیزبەندیی دروستی سەوز ← زەرد ← سوور دروست بکە.

What you will buildچی دروست دەکەیت

In this lab you make an LED blink, then build a traffic light from three LEDs. On the way you meet what every output circuit needs: a complete path back to GND, a resistor to protect the LED, and two Arduino functions, pinMode() and digitalWrite(). All circuits here are low voltage: the board takes 5 V from the USB cable.

لەم تاقیگەیەدا دەترووکێنیت، پاشان لە سێ گڵۆپێکی هاتوچۆ دروست دەکەیت. لە ڕێگادا ئەوە دەناسیت کە هەموو پێویستی پێیەتی: ڕێگایەکی تەواو بۆ گەڕانەوە بۆ GND، بۆ پاراستنی و دوو : pinMode() و digitalWrite(). هەموو لێرەدا نزمە: بۆردەکە ⁦5 V⁩ لە کێبڵی وەردەگرێت.

Left: a traffic light at a junction, its green lamp lit. An arrow labelled same idea points right to our model: an Arduino UNO wired to a breadboard with three LEDs, red, yellow and green, each with a resistor; wires from pins 2, 3 and 4 and one GND wire. The green LED is lit. Caption: our model, three LEDs on pins 2, 3 and 4, low voltage from USB (5 V).لای چەپ: گڵۆپێکی هاتوچۆ لە چواڕێیانێک، گڵۆپە سەوزەکەی داگیرساوە. تیرێک بە ناوی هەمان بیرۆکە ئاماژە دەکات بۆ مۆدێلەکەمان: Arduino UNO بەستراو بە بریدبۆردێک کە سێ LEDـی سوور، زەرد و سەوزی لەسەرە، هەریەکە بە بەرگرێک؛ وایەر لە پینەکانی 2، 3 و 4ـەوە و یەک وایەری GND. LEDـە سەوزەکە داگیرساوە. ژێرنووس: مۆدێلەکەمان، سێ LED لەسەر پینەکانی 2، 3 و 4، ڤۆڵتیەی نزم لە USBـەوە (5 V).
The goal of this lab: a working traffic light made of three LEDs.ئامانجی ئەم تاقیگەیە: گڵۆپێکی هاتوچۆی کاراکراو لە سێ .CêIT

What you needچیت پێویستە

  • an Arduino UNO R3 or UNO R4 and a USB cable that carries data (an MKR WAN 1310 also works: see the resistor screen);
  • a half-size breadboard and five or six jumper wires;
  • three 5 mm LEDs: red, yellow and green;
  • three resistors: 330 Ω for an UNO R3, 470 Ω for an UNO R4, 220 Ω for an MKR WAN 1310.
  • ⁦Arduino UNO R3⁩ یان ⁦UNO R4⁩ و کێبڵێکی کە دەگوازێتەوە (⁦MKR WAN 1310⁩ـیش کار دەکات: سەیری پەڕەی بکە)؛
  • نیو قەبارە و پێنج یان شەش وایەری پەڕینەوە؛
  • سێ 5 ملم: سوور، زەرد و سەوز؛
  • سێ : ⁦330 Ω⁩ بۆ ⁦UNO R3⁩، ⁦470 Ω⁩ بۆ ⁦UNO R4⁩، ⁦220 Ω⁩ بۆ ⁦MKR WAN 1310⁩.

No board yet? Build the same circuit in Wokwi or Tinkercad Circuits (No board? Simulate it). How the holes of a breadboard are connected is explained in The breadboard.

هێشتا بۆردت نییە؟ هەمان لە Wokwi یان Tinkercad Circuits دروست بکە (بۆردت نییە؟ هاوشێوەی بکە). ئەوەی کونەکانی چۆن بەیەکەوە بەستراون لە بریدبۆرد ڕوون کراوەتەوە.

GND and the complete circuitGND و سووڕی کارەبایی تەواو

Current flows only around a complete loop (A complete circuit). For an LED on an Arduino the loop is: output pin → resistor → LED → GND → back into the board. GND (ground) is the 0 V point of the circuit: every voltage is measured from it, and it is the road the current takes back. So every part — LED, sensor or module — needs at least two wires: one to a supply or a pin, one to GND. Without GND no current flows, and the part does nothing.

تەنیا بە دەوری سووڕێکی تەواودا دەڕوات (سووڕی کارەبایی تەواو). بۆ لەسەر سووڕەکە ئەمەیە: پینی ← ← ← پینی GND ← گەڕانەوە بۆ ناو بۆردەکە. GND () خاڵی ⁦0 V⁩ـی : هەموو لێیەوە دەپێورێت و ئەو ڕێگایەیە کە پێیدا دەگەڕێتەوە. بۆیە هەموو پارچەیەک — ، یان مۆدیول — لانیکەم دوو وایەری پێویستە: یەکێک بۆ سەرچاوەیەک یان پینێک، یەکێک بۆ GND. بێ GND هیچ ناڕوات و پارچەکە هیچ ناکات.

Two panels. Left, the circuit: a board with pin 2 at HIGH (5 V) at the top and GND (0 V) at the bottom; from pin 2 a wire goes through a resistor and then an LED, which is lit, and back to GND, marked with a ground symbol. Arrows show the current going round the loop. Right, the same idea with water: a high tank labelled high tank = HIGH pin, a pipe with a narrow part labelled narrow pipe = resistor, a water wheel labelled wheel = LED, and a low tank labelled low tank = GND. A note: no low tank, no flow.دوو بەش. چەپ، سووڕەکە: بۆردێک کە پینی 2ـی لەسەر HIGH (5 V)ـە لە سەرەوە و GND (0 V) لە خوارەوە؛ لە پینی 2ـەوە وایەرێک بە بەرگرێک و پاشان بە LEDـێکی داگیرساودا دەڕوات و دەگەڕێتەوە بۆ GND کە بە هێمای زەوی نیشان کراوە. تیرەکان ڕۆیشتنی تەزوو بە دەوری سووڕەکەدا پیشان دەدەن. ڕاست، هەمان بیرۆکە بە ئاو: تانکییەکی بەرز بە ناوی تانکیی بەرز = پینی HIGH، بۆرییەک بە بەشێکی تەسکەوە بە ناوی بۆریی تەسک = بەرگر، چەرخێکی ئاو بە ناوی چەرخ = LED و تانکییەکی نزم بە ناوی تانکیی نزم = GND. تێبینییەک: تانکیی نزم نەبێت، ڕۆیشتن نییە.
The LED's loop on the board, and the same idea with water.سووڕی لەسەر بۆردەکە و هەمان بیرۆکە بە ئاو.CêIT
Two water tanksدوو تانکیی ئاو

The pin at HIGH is a tank high up; GND is a tank on the floor. Water runs down the pipe and turns a small wheel (the LED); a narrow part of the pipe (the resistor) keeps the flow small. Take away the lower tank and the water has nowhere to go: nothing moves. Voltage is like the pressure that pushes; current is the flow.

پینی HIGH تانکییەکە لە بەرزی؛ GND تانکییەکە لەسەر زەوی. ئاو بە بۆرییەکەدا دێتە خوارەوە و چەرخێکی بچووک () دەسووڕێنێت؛ بەشێکی تەسکی بۆرییەکە () ڕۆیشتنەکە کەم دەکاتەوە. تانکییە نزمەکە لاببە و ئاوەکە شوێنی ڕۆیشتنی نامێنێت: هیچ ناجووڵێت. وەک ئەو پەستانەیە کە پاڵ دەنێت؛ ڕۆیشتنەکەیە.

Where the analogy stops workingسنووری ئەم نموونەیە

Water falls because of gravity; electric charge is pushed by voltage. The picture only shows why the path must be closed (Electricity as water in pipes).

ئاو بەهۆی کێشکردنی زەوییەوە دەکەوێتە خوارەوە؛ بە پاڵ دەنرێت. وێنەکە تەنیا پیشان دەدات بۆچی دەبێت ڕێگاکە داخراو بێت (کارەبا وەک ئاو لە بۆریدا).

The LED: a light that works one wayLED: ڕووناکییەک کە بە یەک ئاراستە کار دەکات

An LED (light-emitting diode) gives off light when current flows through it. Like every diode it lets current through in one direction only, from the anode (+) to the cathode (−) (Diodes and LEDs). On a new LED the anode is the longer leg; the cathode is the shorter leg, next to a flat edge on the rim. Put in the wrong way round, it simply stays dark: turn it round.

(دایۆدی ڕووناکیدەر) کاتێک پێیدا دەڕوات ڕووناکی دەدات. وەک هەموو تەنیا بە یەک ئاراستە تێدەپەڕێنێت، لە ⁦(+)⁩ بۆ ⁦(−)⁩ (دایۆدەکان و LEDـەکان). لە نوێدا قاچە درێژەکەیە؛ قاچە کورتەکەیە، لە تەنیشت لێوارێکی تەخت لەسەر بازنەکەی. ئەگەر پێچەوانە دابنرێت تەنیا تاریک دەمێنێتەوە: بیسووڕێنەوە.

The LED does not decide anything: the microcontroller's pin sends a digital signal and the LED shows it. When the sketch makes the pin HIGH (5 V on an UNO, 3.3 V on an MKR WAN 1310), current flows and the LED lights; at LOW (0 V) no current flows and the LED is off.

هیچ بڕیارێک نادات: پینی دەنێرێت و پیشانی دەدات. کاتێک پینەکە دەکاتە ⁦HIGH (5 V⁩ لە UNO، ⁦3.3 V⁩ لە ⁦MKR WAN 1310⁩)، دەڕوات و دادەگیرسێت؛ لە LOWـدا ⁦(0 V)⁩ هیچ ناڕوات و کوژاوەیە.

Left: a large red LED seen from the side, lit, with two legs. The long left leg is labelled anode (+), long leg; the short right leg is labelled cathode (−), short leg; a pointer to the rim says flat edge on the rim = cathode side. Right: the circuit symbol, a triangle pointing right with a bar, and two small arrows for light; anode (+) on the left, cathode (−) on the right. An arrow pointing right says current flows this way: the LED lights. A dashed arrow pointing left says turned round: no current, it stays dark.لای چەپ: LEDـێکی سووری گەورە لە لاوە، داگیرساو، بە دوو قاچەوە. قاچە درێژەکەی چەپ ناوی ئانۆد (+)، قاچی درێژە؛ قاچە کورتەکەی ڕاست ناوی کاتۆد (−)، قاچی کورتە؛ ئاماژەیەک بۆ بازنەکە دەڵێت لێواری تەخت لەسەر بازنەکە = لای کاتۆد. لای ڕاست: هێمای سووڕەکە، سێگۆشەیەک کە بەرەو ڕاست ئاماژە دەکات لەگەڵ هێڵێک و دوو تیری بچووک بۆ ڕووناکی؛ ئانۆد (+) لە چەپ و کاتۆد (−) لە ڕاست. تیرێک بەرەو ڕاست دەڵێت تەزوو بەم ئاراستەیە دەڕوات: LEDـەکە دادەگیرسێت. تیرێکی پچڕپچڕ بەرەو چەپ دەڵێت ئەگەر پێچەوانە بێت: تەزوو نییە و تاریک دەمێنێت.
Long leg = anode (+), short leg and flat edge = cathode (−).قاچی درێژ = ⁦(+)⁩، قاچی کورت و لێواری تەخت = ⁦(−)⁩.CêIT

Choosing the LED's resistor with Ohm's lawهەڵبژاردنی بەرگری LED بە یاسای ئۆم

Once an LED's "on" voltage is reached, its current rises very fast, so a resistor in series must set the current. The resistor takes the voltage that the LED does not: R=(Vpin−VLED)/IR = (V_{pin} - V_{LED}) / I (Ohm's law, Choosing an LED's resistor). A red, yellow or ordinary green LED needs about 2 V. Choose a current at or below the board's limit per pin (on the UNO R3 we use 10 mA, well below its 20 mA), then take the next standard resistor value up:

کاتێک داگیرسانی گەیشت، زۆر خێرا زیاد دەکات، بۆیە دەبێت بە زنجیرە دیاری بکات. ئەو وەردەگرێت کە نایگرێت: R=(Vpin−VLED)/IR = (V_{pin} - V_{LED}) / I (یاسای ئۆم، هەڵبژاردنی بەرگرەکەی LED). سوور، زەرد یان سەوزی ئاسایی نزیکەی ⁦2 V⁩ـی پێویستە. هەڵبژێرە کە لە سنووری هەر پینێکی بۆردەکە تێنەپەڕێت (لە ⁦UNO R3⁩ـدا ⁦10 mA⁩ بەکار دەهێنین، کە زۆر لە سنووری ⁦20 mA⁩ـەکەی کەمترە)، پاشان بەهای ستانداردی دواتری بەرەو سەرەوە وەربگرە:

UNO R3 (5 V, 20 mA per pin): R=5−20.010=300 Ω→330 Ω, I≈9.1 mAUNO R4 (5 V, 8 mA per pin): R≥5−20.008=375 Ω→470 Ω, I≈6.4 mAMKR WAN 1310 (3.3 V, 7 mA): R≥3.3−20.007≈186 Ω→220 Ω, I≈5.9 mA\begin{aligned} \text{UNO R3 (5 V, 20 mA per pin):}\ & R = \frac{5 - 2}{0.010} = 300\,\Omega \rightarrow 330\,\Omega,\ I \approx 9.1\text{ mA} \\ \text{UNO R4 (5 V, 8 mA per pin):}\ & R \ge \frac{5 - 2}{0.008} = 375\,\Omega \rightarrow 470\,\Omega,\ I \approx 6.4\text{ mA} \\ \text{MKR WAN 1310 (3.3 V, 7 mA):}\ & R \ge \frac{3.3 - 2}{0.007} \approx 186\,\Omega \rightarrow 220\,\Omega,\ I \approx 5.9\text{ mA} \end{aligned}

A 470 Ω resistor is safe on every 5 V board in this course. Blue, white and some bright green LEDs need about 3 V: on a 3.3 V board they barely light.

⁦470 Ω⁩ لەسەر هەموو بۆردێکی ⁦5 V⁩ـی ئەم کۆرسە سەلامەتە. شین، سپی و هەندێک سەوزی گەش نزیکەی ⁦3 V⁩ـیان پێویستە: لەسەر بۆردێکی ⁦3.3 V⁩ بە زەحمەت دادەگیرسێن.

Three cards, one per board, for a red LED of about 2 V. UNO R3: HIGH = 5 V, limit per pin 20 mA, R = (5 − 2) ÷ 0.010 = 300 Ω, next standard value up 330 Ω (orange, orange, brown bands), I = (5 − 2) ÷ 330 ≈ 9.1 mA. UNO R4: HIGH = 5 V, limit 8 mA, R ≥ (5 − 2) ÷ 0.008 = 375 Ω, so 470 Ω (yellow, violet, brown), I ≈ 6.4 mA. MKR WAN 1310: HIGH = 3.3 V, limit 7 mA, R ≥ (3.3 − 2) ÷ 0.007 ≈ 186 Ω, so 220 Ω (red, red, brown), I ≈ 5.9 mA.سێ کارت، بۆ هەر بۆردێک یەکێک، بۆ LEDـێکی سووری نزیکەی 2 V. UNO R3: HIGH = 5 V، سنووری هەر پین 20 mA، R = (5 − 2) ÷ 0.010 = 300 Ω، بەهای ستانداردی دواتر بەرەو سەرەوە 330 Ω (ڕەنگەکانی نارنجی، نارنجی، قاوەیی)، I = (5 − 2) ÷ 330 ≈ 9.1 mA. UNO R4: HIGH = 5 V، سنوور 8 mA، R ≥ (5 − 2) ÷ 0.008 = 375 Ω، بۆیە 470 Ω (زەرد، مۆر، قاوەیی)، I ≈ 6.4 mA. MKR WAN 1310: HIGH = 3.3 V، سنوور 7 mA، R ≥ (3.3 − 2) ÷ 0.007 ≈ 186 Ω، بۆیە 220 Ω (سوور، سوور، قاوەیی)، I ≈ 5.9 mA.
The same LED needs a different resistor on each board.هەمان لەسەر هەر بۆردێک جیاوازی پێویستە.CêIT

Wiring one LED on the breadboardبەستنی یەک LED لەسەر بریدبۆرد

The board has GND pins in both rows of headers, beside the supply pins 5V and 3.3V. An LED usually goes from an output pin, not from the 5V pin: on the 5V pin it would simply stay on, and the sketch could not switch it.

بۆردەکە لە هەردوو ڕیزی پینەکاندا پینی GNDـی هەیە، لە تەنیشت پینەکانی کارەبای ⁦5V⁩ و ⁦3.3V⁩. زۆرجار لە پینێکی دەبەسترێت، نەک لە پینی ⁦5V⁩: لەسەر پینی ⁦5V⁩ هەمیشە هەڵکراو دەمێنێتەوە و ناتوانێت بیگۆڕێت.

  1. Unplugدەربهێنە

    Unplug the USB cable while you wire.

    لە کاتی وایەرکێشاندا کێبڵی دەربهێنە.

  2. Signal wireوایەری سیگناڵ

    Connect pin 2 to a column of holes in the upper half of the breadboard.

    پینی 2 بە ستوونێک لە کونەکانی نیوەی سەرەوەی ببەستە.

  3. Resistorبەرگر

    Put the resistor from that column across the middle gap into the lower half.

    لەو ستوونەوە بە سەر کەلێنی ناوەڕاستدا بخەرە نیوەی خوارەوە.

  4. LEDLED

    Put the LED's long leg in the resistor's lower column and its short leg in the blue (−) rail.

    قاچە درێژەکەی لە ستوونە خوارەوەکەی و قاچە کورتەکەی لە هێڵی شین ⁦(−)⁩ دابنێ.

  5. GNDپینی GND

    Connect the blue rail to a GND pin of the board. Check everything, then plug in the USB cable.

    هێڵە شینەکە بە پینێکی GNDـی بۆردەکەوە ببەستە. هەموو شتێک بپشکنە، پاشان کێبڵی ببەستە.

An Arduino UNO beside a breadboard. An orange wire runs from pin 2 to column 13 of the upper half. A resistor stands in column 13 across the middle gap, labelled resistor across the gap, 330 Ω for the UNO R3 or 470 Ω for the UNO R4. In the lower half the red LED's long leg (+) is in row j and its short leg (−) is in the blue rail at the bottom. A black wire, labelled GND: the way back, runs from the blue rail to a GND pin of the board.Arduino UNO لە تەنیشت بریدبۆردێک. وایەرێکی نارنجی لە پینی 2ـەوە دەچێتە ستوونی 13ـی نیوەی سەرەوە. بەرگرێک لە ستوونی 13 بە سەر کەلێنی ناوەڕاستدا ڕاوەستاوە، بە ناوی بەرگر بە سەر کەلێنەکەدا، 330 Ω بۆ UNO R3 یان 470 Ω بۆ UNO R4. لە نیوەی خوارەوەدا قاچە درێژەکەی (+) LEDـە سوورەکە لە ڕیزی jـدایە و قاچە کورتەکەی (−) لە هێڵی شینی خوارەوەدایە. وایەرێکی ڕەش بە ناوی GND: ڕێگای گەڕانەوە، لە هێڵە شینەکەوە دەچێتە پینێکی GNDـی بۆردەکە.
One LED on pin 2: wire, resistor, LED, GND rail, GND wire.یەک لەسەر پینی 2: وایەر، ، ، هێڵی GND، وایەری GND.CêIT

pinMode(): give each pin its job⁦pinMode()⁩: کاری هەر پینێک دیاری بکە

A digital pin can send or listen, and the sketch must say which: pinMode(pin, mode);, usually in setup(). The name says it: a pin is one of the metal legs where you connect wires, and its mode is the way it works, like the silent mode of a phone. For example pinMode(13, OUTPUT); tells the board that pin 13 will send signals, such as switching an LED on and off. A function like pinMode() is a small piece of code that does one job, like a tool in a toolbox.

دەتوانێت بنێرێت یان گوێ بگرێت و دەبێت بڵێت کامیان: pinMode(pin, mode);، زۆرجار لە setup()ـدا. ناوەکە خۆی دەیڵێت: pin یەکێکە لەو قاچە کانزاییانەی وایەریان پێوە دەبەستیت و mode شێوەی کارکردنییەتی، وەک دۆخی بێدەنگی مۆبایل. بۆ نموونە pinMode(13, OUTPUT); بە بۆردەکە دەڵێت کە پینی ⁦13⁩ دەنێرێت، وەک هەڵکردن و کوژاندنەوەی . وەک ⁦pinMode()⁩ پارچەیەکی بچووکی کۆدە کە یەک کار دەکات، وەک ئامرازێک لە سندووقی ئامرازدا.

ModeدۆخWhat the pin doesپینەکە چی دەکاتExampleنموونە
OUTPUTsends HIGH or LOWHIGH یان LOW دەنێرێتan LED, a buzzer, the input of a relay module، ، مۆدیولێکی
INPUTlistens: reads HIGH or LOWگوێ دەگرێت: HIGH یان LOW دەخوێنێتەوەthe digital output of a sensor
INPUT_PULLUPlistens, with a built-in pull-up resistor that holds it HIGH until a button pulls it LOWگوێ دەگرێت، بە ناوخۆییەوە کە بە HIGH ڕایدەگرێت تا دەیکاتە LOWa push button (Lab: Buttons) (تاقیگە: دوگمەکان)
Three cards. OUTPUT, pinMode(2, OUTPUT): an arrow goes from the pin to a lit LED; the pin sends 5 V or 0 V to an LED. INPUT, pinMode(7, INPUT): an arrow goes from a sensor to the pin; the pin listens, is it HIGH or LOW? INPUT_PULLUP, pinMode(8, INPUT_PULLUP): inside the chip a resistor connects the pin to 5 V, and outside a button connects it to GND; the pin listens and is held HIGH until the button pulls it LOW.سێ کارت. OUTPUT، pinMode(2, OUTPUT): تیرێک لە پینەکەوە دەچێتە LEDـێکی داگیرساو؛ پینەکە 5 V یان 0 V دەنێرێت بۆ LEDـێک. INPUT، pinMode(7, INPUT): تیرێک لە هەستەوەرێکەوە دێتە پینەکە؛ پینەکە گوێ دەگرێت، HIGHـە یان LOW؟ INPUT_PULLUP، pinMode(8, INPUT_PULLUP): لە ناو چیپەکەدا بەرگرێک پینەکە بە 5 Vـەوە دەبەستێت و لە دەرەوە دوگمەیەک بە GNDـەوە دەیبەستێت؛ پینەکە گوێ دەگرێت و بە HIGH ڕادەگیرێت تا دوگمەکە دەیکاتە LOW.
The three modes of a digital pin.سێ دۆخی .CêIT
The gates of a city portدەرگاکانی بەندەرێکی شار

Think of the pins as the gates of a port: some gates send goods out (OUTPUT), some take goods in (INPUT), and some wait with a doorbell that rings when someone presses it (INPUT_PULLUP).

پینەکان وەک دەرگاکانی بەندەرێک وێنا بکە: هەندێک دەرگا کاڵا دەنێرنە دەرەوە ⁦(OUTPUT)⁩، هەندێک کاڵا وەردەگرن ⁦(INPUT)⁩ و هەندێکیان بە زەنگێکەوە چاوەڕێ دەکەن کە کاتێک کەسێک دایدەگرێت لێ دەدات ⁦(INPUT_PULLUP)⁩.

Where the analogy stops workingسنووری ئەم نموونەیە

A port moves heavy loads; a pin gives only a few milliamps — enough for an LED, never enough for a motor.

بەندەر باری قورس دەگوازێتەوە؛ پین تەنیا چەند میلیئەمپێرێک دەدات — بەس بۆ ، هەرگیز بەس نییە بۆ .

digitalWrite(): HIGH or LOW⁦digitalWrite(): HIGH⁩ یان LOW

digitalWrite(pin, value) sets an output pin to HIGH (5 V on an UNO, 3.3 V on 3.3 V boards) or LOW (0 V). Digital means only two states, on (1) or off (0); write means sending a value to the pin. It works like a wall switch: switch up, HIGH, the light is on; switch down, LOW, the light is off. Voltage is the push, like water pressure: 5 V pushes, 0 V does not.

digitalWrite(pin, value) پینێکی دەکاتە HIGH (⁦5 V⁩ لە UNO، ⁦3.3 V⁩ لە بۆردەکانی ⁦3.3 V⁩) یان LOW ⁦(0 V)⁩. واتە تەنیا دوو دۆخ، هەڵکراو ⁦(1)⁩ یان کوژاو ⁦(0)⁩؛ write واتە ناردنی بەهایەک بۆ پینەکە. وەک دیوار کار دەکات: بۆ سەرەوە، HIGH، گڵۆپەکە هەڵکراوە؛ بۆ خوارەوە، LOW، گڵۆپەکە کوژاوەیە. پاڵنانەکەیە، وەک پەستانی ئاو: ⁦5 V⁩ پاڵ دەنێت، ⁦0 V⁩ پاڵ نانێت.

Switching the LED on pin 13هەڵکردن و کوژاندنەوەی LEDـی پینی ⁦13⁩snippet.inoARDUINORuns on a phone (or an emulator)لەسەر مۆبایل کار دەکات
digitalWrite(13, HIGH);   // the LED on pin 13 lights up
digitalWrite(13, LOW);    // and goes off

Call pinMode(pin, OUTPUT) first. For steps between fully on and fully off, Arduino uses analogWrite() with PWM — that comes in Lab: Dimming with PWM and Beeping with tone().

سەرەتا pinMode(pin, OUTPUT) بەکار بهێنە. بۆ پلەکانی نێوان تەواو هەڵکراو و تەواو کوژاو، analogWrite() لەگەڵ بەکار دەهێنێت — ئەمە لە تاقیگە: کزکردن بە PWM و زەنگ بە ⁦tone()⁩دا دێت.

Two rows. Top: digitalWrite(2, HIGH); leads to a wall switch pushed up, then HIGH, 5 V on an UNO or 3.3 V on an MKR WAN 1310, and a lit red LED. Bottom: digitalWrite(2, LOW); leads to the switch pushed down, then LOW, 0 V, and the LED off.دوو ڕیز. سەرەوە: digitalWrite(2, HIGH); دەگاتە سویچێکی دیوار کە بۆ سەرەوە پاڵنراوە، پاشان HIGH، 5 V لە UNO یان 3.3 V لە MKR WAN 1310 و LEDـێکی سووری داگیرساو. خوارەوە: digitalWrite(2, LOW); دەگاتە سویچەکە کە بۆ خوارەوە پاڵنراوە، پاشان LOW، 0 V و LEDـەکە کوژاوە.
digitalWrite() flips the pin like a wall switch.⁦digitalWrite()⁩ پینەکە وەک دیوار دەگۆڕێت.CêIT

Lab 1: blink an LEDتاقیگەی 1: هەڵکردن و کوژاندنەوەی LEDـێک

While delay() waits, the board does nothing elseکاتێک ⁦delay()⁩ چاوەڕێ دەکات، بۆردەکە هیچی تر ناکات

delay(1000) stops the sketch for 1000 ms. During that second the board cannot read a button, check a sensor or answer the Serial Monitor; only background work goes on, such as storing incoming serial bytes and keeping PWM outputs running. For a blinking LED that is fine; for a device that must also react, it is not. The fix is to look at the clock with millis() instead of waiting: you will meet it in millis(): check the clock instead of waiting, and buttons need it too (Lab: Buttons).

delay(1000) بۆ ⁦1000 ms⁩ ڕادەگرێت. لەو چرکەیەدا بۆردەکە ناتوانێت بخوێنێتەوە، بپشکنێت یان وەڵامی بداتەوە؛ تەنیا کاری پشتەوە بەردەوامە، وەک هەڵگرتنی ئەو بە زنجیرە دێن و بەردەوامبوونی PWM. بۆ کە دەترووکێت ئەمە باشە؛ بۆ ئامێرێک کە دەبێت وەڵامیش بداتەوە، باش نییە. چارەسەر ئەوەیە لەبری چاوەڕێکردن بە millis() سەیری کاتژمێرەکە بکەیت: لە ⁦millis()⁩: لەبری چاوەڕێکردن سەیری کاتژمێر بکەدا دەیناسیت و پێویستیان پێیەتی (تاقیگە: دوگمەکان).

A timeline from 0 to 2 seconds. A thin bar at 0 s is digitalWrite(redPin, HIGH), then a long orange bar delay(1000): waiting until 1 s; a thin bar digitalWrite(redPin, LOW), then another delay(1000): waiting until 2 s. Below, a blue box button pressed sits at about 0.4 to 0.6 s with a dashed line up to the first waiting bar: the sketch is inside delay(), the press is missed. A green box: better for busy sketches, millis(): look at the clock, do the other jobs, change the LED when its time has come.هێڵێکی کات لە 0 تا 2 چرکە. شریتێکی باریک لە 0 چرکە digitalWrite(redPin, HIGH)ـە، پاشان شریتێکی درێژی نارنجی delay(1000): چاوەڕێ تا 1 چرکە؛ شریتێکی باریک digitalWrite(redPin, LOW)، پاشان delay(1000)ـێکی تر: چاوەڕێ تا 2 چرکە. لە خوارەوە، خانەیەکی شین بە ناوی دوگمە داگیرا لە نزیکەی 0.4 تا 0.6 چرکەدایە و هێڵێکی پچڕپچڕ تا یەکەم شریتی چاوەڕێ دەچێت: سکێچەکە لە ناو delay()ـدایە، داگرتنەکە لەدەست دەچێت. خانەیەکی سەوز: باشتر بۆ سکێچەکانی قەرەباڵغ، millis(): سەیری کاتژمێرەکە بکە، کارەکانی تر بکە، LEDـەکە بگۆڕە کاتێک کاتی هات.
During delay() the sketch is deaf to everything else.لە کاتی ⁦delay()⁩ـدا گوێی لە هیچی تر نییە.CêIT

Task 1: a short flash every secondئەرکی 1: ترووسکەیەکی کورت هەر چرکەیەک

ExerciseڕاهێنانTask 1ئەرکی 1

Change Lab 1 so the LED is on for 250 ms and off for 750 ms. How often does it flash?

تاقیگەی 1 بگۆڕە بۆ ئەوەی ⁦250 ms⁩ هەڵکراو و ⁦750 ms⁩ کوژاو بێت. چەند جار دەترووکێت؟

Hintئاماژە

Only the two delay() values change.

تەنیا دوو بەهای ⁦delay()⁩ دەگۆڕێن.

Show answerوەڵامەکە پیشان بدە
Task 1: 250 ms on, 750 ms offئەرکی ⁦1: 250 ms⁩ هەڵکراو، ⁦750 ms⁩ کوژاوtask1.inoARDUINORuns on a phone (or an emulator)لەسەر مۆبایل کار دەکات
// Task 1: a short flash once a second
const int redPin = 2;

void setup() {
  pinMode(redPin, OUTPUT);
}

void loop() {
  digitalWrite(redPin, HIGH);
  delay(250);                  // on for a quarter of a second
  digitalWrite(redPin, LOW);
  delay(750);                  // off for the rest of the second
}

One cycle is still 250+750=1000 ms250 + 750 = 1000\,\text{ms}, so it flashes once a second, but the LED is on for only a quarter of the time.

یەک خول هێشتا 250+750=1000 ms250 + 750 = 1000\,\text{ms}ـە، بۆیە هەر چرکەیەک جارێک دەترووکێت، بەڵام تەنیا چارەکێکی کاتەکە هەڵکراوە.

Two timing diagrams from 0 to 3 seconds. Lab 1, 1000 / 1000 ms: HIGH for one second, LOW for one second. Task 1, 250 / 750 ms: a short HIGH pulse of a quarter second at 0, 1 and 2 s, LOW the rest of the time. Note: Task 1 is still one cycle per second, but the LED is on only a quarter of it.دوو هێڵکاریی کاتبەندی لە 0 تا 3 چرکە. تاقیگەی 1، 1000 / 1000 ms: یەک چرکە HIGH، یەک چرکە LOW. ئەرکی 1، 250 / 750 ms: تڕپەیەکی کورتی HIGH بۆ چارەکە چرکەیەک لە 0، 1 و 2 چرکەدا و ئەوی تر LOW. تێبینی: ئەرکی 1 هێشتا هەر چرکەیەک خولێکە، بەڵام LEDـەکە تەنیا چارەکێکی هەڵکراوە.
Same rhythm, shorter flash.هەمان ڕیتم، ترووسکەی کورتتر.CêIT

Lab 2: three LEDs in a rowتاقیگەی 2: سێ LED لە دوای یەک

Add two more LEDs: yellow on pin 3 and green on pin 4, each with its own resistor, all sharing the same GND rail. The sketch switches them on one after another.

دوو تر زیاد بکە: زەرد لەسەر پینی 3 و سەوز لەسەر پینی 4، هەریەکە بە خۆیەوە و هەموویان هەمان هێڵی GND بەکار دەهێنن. یەک لە دوای یەک هەڵیان دەکات.

Lab 2: red, yellow, greenتاقیگەی 2: سوور، زەرد، سەوزtraffic_wrong.inoARDUINORuns on a phone (or an emulator)لەسەر مۆبایل کار دەکات
// Lab 2: three LEDs, one after another
const int redPin = 2;
const int yellowPin = 3;
const int greenPin = 4;

void setup() {
  pinMode(redPin, OUTPUT);
  pinMode(yellowPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
}

void loop() {
  digitalWrite(redPin, HIGH);     // red for 3 s
  delay(3000);
  digitalWrite(redPin, LOW);

  digitalWrite(yellowPin, HIGH);  // yellow for 1 s
  delay(1000);
  digitalWrite(yellowPin, LOW);

  digitalWrite(greenPin, HIGH);   // green for 3 s
  delay(3000);
  digitalWrite(greenPin, LOW);
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2-4

Three named pins.

سێ پینی ناودار.

Lineدێڕی 13-23

Each LED: on, wait, off. Then loop() starts again with red.

هەر : هەڵکردن، چاوەڕێ، کوژاندنەوە. پاشان ⁦loop()⁩ دووپاتە بە سوور دەست پێ دەکاتەوە.

An Arduino UNO and a breadboard. Three wires, orange from pin 2, yellow from pin 3 and green from pin 4, go to columns 5, 13 and 21 of the upper half. In each column a resistor crosses the middle gap, and below it an LED, red, yellow and green, has its long leg (+) in row j and its short leg in the blue rail. One black wire joins the blue rail to a GND pin: all three LEDs share the GND rail.Arduino UNO و بریدبۆردێک. سێ وایەر، نارنجی لە پینی 2، زەرد لە پینی 3 و سەوز لە پینی 4، دەچنە ستوونەکانی 5، 13 و 21ـی نیوەی سەرەوە. لە هەر ستوونێکدا بەرگرێک بە سەر کەلێنی ناوەڕاستدا دەپەڕێتەوە و لە خوارییەوە LEDـێک، سوور، زەرد و سەوز، قاچە درێژەکەی (+) لە ڕیزی jـدایە و قاچە کورتەکەی لە هێڵی شیندا. یەک وایەری ڕەش هێڵە شینەکە بە پینێکی GNDـەوە دەبەستێت: هەر سێ LEDـەکە هێڵی GND بەکار دەهێنن.
Three LEDs, three resistors, one shared GND rail.سێ ، سێ ، یەک هێڵی GNDـی هاوبەش.CêIT

Lab 2: three LEDs in a rowتاقیگەی 2: سێ LED لە دوای یەک

Spot the problem: the order of the lightsهەڵەکە بدۆزەرەوە: ڕیزبەندیی ڕەنگەکان

ExerciseڕاهێنانWould you drive by this light?بەم گڵۆپەدا ئۆتۆمبێل لێ دەخوڕیت؟

The sketch works, but watch the order of the colours: red → yellow → green → red. What is wrong for a real junction, and which order should it be?

کار دەکات، بەڵام سەیری ڕیزبەندیی ڕەنگەکان بکە: سوور ← زەرد ← سەوز ← سوور. بۆ چواڕێیانێکی ڕاستەقینە چی هەڵەیە و ڕیزبەندییەکە دەبێت چۆن بێت؟

Hintئاماژە

What does a yellow light tell a driver?

گڵۆپی زەرد چی بە شۆفێر دەڵێت؟

Show answerوەڵامەکە پیشان بدە

At a junction, yellow means "red is coming: stop if you can do it safely". So yellow must come between green and red: green → yellow → red, then green again. Lab 2 shows yellow and then green, which would confuse drivers. Some countries, such as the United Kingdom, also show red and yellow together just before green.

لە چواڕێیانێکدا زەرد واتە «سوور دێت: ئەگەر بە سەلامەتی دەتوانیت بوەستە». بۆیە زەرد دەبێت لە نێوان سەوز و سووردا بێت: سەوز ← زەرد ← سوور، پاشان دووپاتە سەوز. تاقیگەی 2 زەرد و پاشان سەوز پیشان دەدات، کە شۆفێران سەرلێشێواو دەکات. هەندێک وڵات، وەک شانشینی یەکگرتوو، پێش سەوز بۆ کاتێکی کورت سوور و زەرد پێکەوە پیشان دەدەن.

Two rows of traffic lights. Lab 2: red for 3 s, then yellow for 1 s, then green for 3 s, then red; a cross between yellow and green, labelled: yellow, then green, drivers expect red. Task 2: green for 3 s, yellow for 1 s, red for 3 s, then green; a tick, labelled: yellow warns, red is coming.دوو ڕیز گڵۆپی هاتوچۆ. تاقیگەی 2: سوور بۆ 3 چرکە، پاشان زەرد بۆ 1 چرکە، پاشان سەوز بۆ 3 چرکە، پاشان سوور؛ خاچێک لە نێوان زەرد و سەوزدا بە تێبینیی زەرد، پاشان سەوز: شۆفێران چاوەڕێی سوور دەکەن. ئەرکی 2: سەوز بۆ 3 چرکە، زەرد بۆ 1 چرکە، سوور بۆ 3 چرکە، پاشان سەوز؛ نیشانەی ڕاست بە تێبینیی زەرد ئاگادار دەکاتەوە: سوور دێت.
Yellow must come between green and red.زەرد دەبێت لە نێوان سەوز و سووردا بێت.CêIT

Task 2: the right orderئەرکی 2: ڕیزبەندیی دروست

Task 2 changes only the order of the three blocks in loop(): green, then yellow, then red.

ئەرکی 2 تەنیا ڕیزبەندیی سێ بلۆکەکەی ناو loop() دەگۆڕێت: سەوز، پاشان زەرد، پاشان سوور.

Task 2: green, yellow, redئەرکی 2: سەوز، زەرد، سوورtraffic_right.inoARDUINORuns on a phone (or an emulator)لەسەر مۆبایل کار دەکات
// Task 2: a traffic light in the right order
const int redPin = 2;
const int yellowPin = 3;
const int greenPin = 4;

void setup() {
  pinMode(redPin, OUTPUT);
  pinMode(yellowPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
}

void loop() {
  digitalWrite(greenPin, HIGH);   // green: go (3 s)
  delay(3000);
  digitalWrite(greenPin, LOW);

  digitalWrite(yellowPin, HIGH);  // yellow: red is coming (1 s)
  delay(1000);
  digitalWrite(yellowPin, LOW);

  digitalWrite(redPin, HIGH);     // red: stop (3 s)
  delay(3000);
  digitalWrite(redPin, LOW);
}
An animation with the real timing of Task 2, in three frames that repeat. 1: green for 3 seconds, go; the lines that switch the green LED are highlighted and the timeline shows 0 s to 3 s. 2: yellow for 1 second, red is coming; 3 s to 4 s. 3: red for 3 seconds, stop; 4 s to 7 s; then loop() starts again with green. One cycle is 7 seconds.
An animation with the real timing of Task 2, in three frames that repeat. 1: green for 3 seconds, go; the lines that switch the green LED are highlighted and the timeline shows 0 s to 3 s. 2: yellow for 1 second, red is coming; 3 s to 4 s. 3: red for 3 seconds, stop; 4 s to 7 s; then loop() starts again with green. One cycle is 7 seconds.
Task 2 running: green 3 s, yellow 1 s, red 3 s, again and again.ئەرکی 2 لە کاردا: سەوز 3 چرکە، زەرد 1 چرکە، سوور 3 چرکە، دووپاتە و دووپاتە.CêIT

Common mistakesهەڵە باوەکان

MistakeهەڵەBetterباشتر
The LED is in backwards and stays dark. پێچەوانە دانراوە و تاریک دەمێنێتەوە.Long leg (anode) towards the pin, short leg (cathode) to GND.قاچی درێژ () بەرەو پین، قاچی کورت () بۆ GND.
No resistor: the LED and the pin are overloaded.بێ : و پینەکە زیاد لە توانا بار دەکرێن.Always put a resistor in series: 330 Ω (UNO R3), 470 Ω (UNO R4), 220 Ω (MKR WAN 1310).هەمیشە بە زنجیرە دابنێ: ⁦330 Ω (UNO R3)⁩، ⁦470 Ω (UNO R4)⁩، ⁦220 Ω (MKR WAN 1310)⁩.
A 220 Ω resistor on an UNO R4 (about 13.6 mA). ⁦220 Ω⁩ لەسەر ⁦UNO R4⁩ (نزیکەی ⁦13.6 mA⁩).Stay below 8 mA per pin: use 470 Ω.لە خوار ⁦8 mA⁩ بۆ هەر پینێک بمێنەرەوە: ⁦470 Ω⁩ بەکار بهێنە.
pinMode() is missing: the LED glows dimly.⁦pinMode()⁩ نییە: کز دادەگیرسێت.Write pinMode(pin, OUTPUT) in setup().⁦pinMode(pin, OUTPUT)⁩ لە ⁦setup()⁩ـدا بنووسە.
Both legs of a part in the same 5-hole column.هەردوو قاچی پارچەیەک لە هەمان ستوونی 5 کونیدا.A column is one connection: put the legs in different columns (The breadboard).ستوونێک یەک پەیوەندییە: قاچەکان لە ستوونی جیاوازدا دابنێ (بریدبۆرد).
The GND wire is forgotten.وایەری GND لەبیر کراوە.Every circuit needs the way back: a wire from the blue rail to GND.هەموو ڕێگای گەڕانەوەی پێویستە: وایەرێک لە هێڵی شینەوە بۆ GND.
The LED is wired to the 5V pin and never goes off. بە پینی ⁦5V⁩ـەوە بەستراوە و هەرگیز ناکوژێتەوە.Wire it from a digital pin such as pin 2, so the sketch can switch it.لە وەک پینی 2ـەوە بیبەستە، بۆ ئەوەی بتوانێت بیگۆڕێت.
The traffic light goes red → yellow → green.گڵۆپی هاتوچۆکە سوور ← زەرد ← سەوز دەگۆڕێت.Green → yellow → red: yellow warns that red is coming.سەوز ← زەرد ← سوور: زەرد ئاگادار دەکاتەوە کە سوور دێت.

Exercisesڕاهێنانەکان

ExerciseڕاهێنانSOS in Morse codeSOS بە کۆدی مۆرس

Make the LED on pin 2 signal SOS: three short flashes (dots), three long ones (dashes) and three short ones, run together, then a pause. One Morse unit is 200 ms: a dot lasts 1 unit, a dash 3 units, the gap between flashes 1 unit and the pause between words 7 units. (SOS is sent as one signal, without the gaps between letters.) Where dots, dashes and SOS come from: Dots and dashes.

سەر پینی 2 وا لێ بکە SOS بنێرێت: سێ ترووسکەی کورت (خاڵ)، سێ درێژ (هێڵ) و سێ کورت، بە دوای یەکدا، پاشان وەستانێک. یەک یەکەی ⁦200 ms⁩ـە: خاڵ 1 یەکە دەخایەنێت، هێڵ 3 یەکە، بۆشایی نێوان ترووسکەکان 1 یەکە و وەستانی نێوان وشەکان 7 یەکە. (SOS وەک یەک دەنێردرێت، بێ بۆشایی نێوان پیتەکان.) خاڵ، هێڵ و SOS لە کوێوە هاتوون: خاڵ و هێڵ.

Hintئاماژە

Write a small function that flashes for a given time, and call it in three for loops.

بچووک بنووسە کە بۆ کاتێکی دیاریکراو دەترووکێت و لە سێ بانگی بکە.

Show answerوەڵامەکە پیشان بدە
SOS on pin 2SOS لەسەر پینی 2sos.inoARDUINORuns on a phone (or an emulator)لەسەر مۆبایل کار دەکات
// SOS in Morse code on pin 2: . . . - - - . . . sent as one signal
const int ledPin = 2;
const int unit = 200;               // one Morse unit, in ms

void flash(int length) {            // LED on for 'length' ms, then a 1-unit gap
  digitalWrite(ledPin, HIGH);
  delay(length);
  digitalWrite(ledPin, LOW);
  delay(unit);
}

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop() {
  for (int i = 0; i < 3; i++) {     // three dots
    flash(unit);
  }
  for (int i = 0; i < 3; i++) {     // three dashes
    flash(3 * unit);
  }
  for (int i = 0; i < 3; i++) {     // three dots
    flash(unit);
  }
  delay(6 * unit);                  // pause between words: 7 units in all
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 5-10

flash(): LED on for the given time, then a one-unit gap.

⁦flash()⁩: بۆ کاتی دیاریکراو هەڵدەبێت، پاشان بۆشاییەکی یەک یەکەیی.

Lineدێڕی 17-19

Three dots, using a for loop.

سێ خاڵ، بە .

ExerciseڕاهێنانA blue LEDLEDـێکی شین

A blue LED needs about 3.0 V. Which resistor would you use on a 5 V UNO R3 for about 10 mA, and what current flows then? Would the same LED work well on an MKR WAN 1310 (3.3 V)?

شین نزیکەی ⁦3.0 V⁩ـی پێویستە. لەسەر ⁦UNO R3⁩ـی ⁦5 V⁩ بۆ نزیکەی ⁦10 mA⁩ کام بەکار دەهێنیت و ئینجا چ دەڕوات؟ ئایا هەمان لەسەر ⁦MKR WAN 1310 (3.3 V)⁩ باش کار دەکات؟

Show answerوەڵامەکە پیشان بدە
R=5−30.010=200 Ω→220 Ω,I=2 V220 Ω≈9.1 mAR = \frac{5 - 3}{0.010} = 200\,\Omega \rightarrow 220\,\Omega, \quad I = \frac{2\text{ V}}{220\,\Omega} \approx 9.1\text{ mA}

On the MKR WAN 1310 only 3.3−3.0=0.3 V3.3 - 3.0 = 0.3\,\text{V} is left for the resistor: with 220 Ω that is about 1.4 mA, so the LED is very dim. Use a red or yellow LED there.

لەسەر ⁦MKR WAN 1310⁩ تەنیا 3.3−3.0=0.3 V3.3 - 3.0 = 0.3\,\text{V} بۆ دەمێنێتەوە: بە ⁦220 Ω⁩ ئەمە نزیکەی ⁦1.4 mA⁩ـە، بۆیە زۆر کزە. لەوێ سوور یان زەرد بەکار بهێنە.

ExerciseڕاهێنانA pedestrian crossingپەڕینەوەی پیادە

Add a green "walk" LED for people on pin 5. It must be on only while the cars have red, and it should go off one second before the cars get green again.

سەوزی «پیاسە» بۆ خەڵک لەسەر پینی 5 زیاد بکە. دەبێت تەنیا ئەو کاتە هەڵکراو بێت کە ئۆتۆمبێلەکان سووریان هەیە و یەک چرکە پێش ئەوەی ئۆتۆمبێلەکان دووپاتە سەوز وەربگرن بکوژێتەوە.

Hintئاماژە

Split the red delay(3000) into two parts.

⁦delay(3000)⁩ـی سوورەکە بکە بە دوو بەش.

Show answerوەڵامەکە پیشان بدە
A traffic light with a walk lightگڵۆپی هاتوچۆ لەگەڵ گڵۆپی پیاسەcrossing.inoARDUINORuns on a phone (or an emulator)لەسەر مۆبایل کار دەکات
// A traffic light with a pedestrian "walk" light
const int redPin = 2;
const int yellowPin = 3;
const int greenPin = 4;
const int walkPin = 5;              // green "walk" light for people

void setup() {
  pinMode(redPin, OUTPUT);
  pinMode(yellowPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(walkPin, OUTPUT);
}

void loop() {
  digitalWrite(greenPin, HIGH);     // cars go, people wait
  delay(3000);
  digitalWrite(greenPin, LOW);

  digitalWrite(yellowPin, HIGH);    // red is coming
  delay(1000);
  digitalWrite(yellowPin, LOW);

  digitalWrite(redPin, HIGH);       // cars stop ...
  digitalWrite(walkPin, HIGH);      // ... people walk
  delay(2000);
  digitalWrite(walkPin, LOW);       // walk ends 1 s before the cars move
  delay(1000);
  digitalWrite(redPin, LOW);
}

Summaryپوختە

  • Current needs a complete loop: output pin → resistor → LED → GND. GND is the 0 V reference and the way back.
  • An LED works one way: long leg = anode (+), short leg and flat edge = cathode (−).
  • Choose the resistor with R=(Vpin−VLED)/IR = (V_{pin} - V_{LED}) / I within the pin's limit: 330 Ω (UNO R3), 470 Ω (UNO R4), 220 Ω (MKR WAN 1310).
  • pinMode(pin, OUTPUT) in setup(); then digitalWrite(pin, HIGH or LOW) switches the pin like a wall switch.
  • Name pins once with const int; delay() blocks the whole sketch, so busy sketches use millis().
  • A traffic light goes green → yellow → red; here 3 s, 1 s and 3 s, a 7-second cycle.
  • پێویستی بە سووڕێکی تەواوە: پینی ← ← ← پینی ⁦GND. GND⁩ خاڵی سەرچاوەی ⁦0 V⁩ـە و ڕێگای گەڕانەوەیە.
  • بە یەک ئاراستە کار دەکات: قاچی درێژ = ⁦(+)⁩، قاچی کورت و لێواری تەخت = ⁦(−)⁩.
  • بە R=(Vpin−VLED)/IR = (V_{pin} - V_{LED}) / I لە ناو سنووری پینەکەدا هەڵبژێرە: ⁦330 Ω (UNO R3)⁩، ⁦470 Ω (UNO R4)⁩، ⁦220 Ω (MKR WAN 1310)⁩.
  • ⁦pinMode(pin, OUTPUT)⁩ لە ⁦setup()⁩ـدا؛ پاشان ⁦digitalWrite(pin, HIGH⁩ یان LOW) پینەکە وەک دیوار دەگۆڕێت.
  • پینەکان یەک جار بە const int ناو ببە؛ ⁦delay()⁩ هەموو ڕادەگرێت، بۆیە قەرەباڵغ ⁦millis()⁩ بەکار دەهێنن.
  • گڵۆپی هاتوچۆ سەوز ← زەرد ← سوور دەگۆڕێت؛ لێرەدا 3 چرکە، 1 چرکە و 3 چرکە، خولێکی 7 چرکەیی.
Review questionsپرسیارەکانی پێداچوونەوە
Why does every LED need a resistor?بۆچی هەموو LEDـێک پێویستی بە بەرگر هەیە؟

Above its on-voltage an LED's current rises very fast; the resistor sets a safe current for the LED and the pin.

لە سەرووی داگیرسانەوە زۆر خێرا زیاد دەکات؛ سەلامەت بۆ و پینەکە دیاری دەکات.

What happens if you forget pinMode(pin, OUTPUT)?ئەگەر ⁦pinMode(pin, OUTPUT)⁩ لەبیر بکەیت چی ڕوو دەدات؟

digitalWrite(HIGH) only turns on the weak internal pull-up, so the LED glows dimly.

⁦digitalWrite(HIGH)⁩ تەنیا لاوازی ناوخۆیی هەڵدەکات، بۆیە کز دادەگیرسێت.

What is wrong with red → yellow → green?سوور ← زەرد ← سەوز چی هەڵەیە؟

Yellow warns that red is coming, so it must come between green and red.

زەرد ئاگادار دەکاتەوە کە سوور دێت، بۆیە دەبێت لە نێوان سەوز و سووردا بێت.

Lesson complete!وانەکە تەواو بوو!

Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.

Key termsزاراوە سەرەکییەکان

Next lessonوانەی داهاتوو

Lab: Talking to the Board with the Serial Monitorتاقیگە: قسەکردن لەگەڵ بۆرد بە Serial Monitor

References and further readingسەرچاوەکان و خوێندنەوەی زیاتر

This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.

Appearanceڕووکار

Modeدۆخ
Styleشێواز
Coloursڕەنگەکان

Saved on this device only.تەنیا لەسەر ئەم ئامێرە پاشەکەوت دەکرێت.