[{"data":1,"prerenderedAt":266},["ShallowReactive",2],{"lesson-2-01-blinky":3},{"id":4,"title":5,"body":6,"chapterName":253,"chapterNumber":186,"description":254,"extension":255,"includesCode":201,"lessonNumber":180,"meta":256,"navigation":201,"path":257,"seo":258,"starterCode":259,"stem":260,"tags":261,"__hash__":265},"lessons/lessons/2-01-blinky.md","Blinky",{"type":7,"value":8,"toc":245},"minimark",[9,14,18,22,25,28,31,37,41,44,107,111,114,161,241],[10,11,13],"h2",{"id":12},"introduction","Introduction",[15,16,17],"p",{},"In this lesson, we'll cover the basics of circuits and electricity, and how to design your very first circuit using the\ncomponents in your kit. The goal of this project is to create a simple circuit with an LED that blinks on and off at a\nregular interval.",[10,19,21],{"id":20},"wiring-the-circuit","Wiring the Circuit",[15,23,24],{},"To build the Blinky circuit, you'll need to connect an LED and a resistor to one of the GPIO pins on your controller.\nRemember that the LED is directional, meaning it will only light up if you connect it the right way. There is a small\narrow next to the LED symbol on the components in your kit that indicates the direction of current flow. Make sure that\nthe arrow correctly points from higher voltage towards ground. The resistor should be connected in series with the LED\nto limit the current and prevent it from burning out. You can connect the resistor either before or after the LED in the\ncircuit.",[15,26,27],{},"If you'd like, you can test this circuit by using the 5V pin instead of a GPIO pin. If you connect the LED and resistor\nin series between the 5V pin and GND, the LED should light up as soon as you connect it. This can be a good way to\nverify that your circuit is wired correctly before you start writing code to control it.",[15,29,30],{},"We have included below the diagram from lesson 1-01 Circuits, which shows a basic circuit with an LED and resistor in\nseries. You can use this as a reference for how to wire your Blinky circuit. Remember here that our source of positive\nvoltage is going to be one of the GPIO pins instead of the 5V pin, but the rest of the circuit will look the same.",[32,33],"img",{"alt":34,"src":35,"width":36},"Example basic circuit with an LED and resistor in series","/images/lessons/01-basic-circuit.svg","80%",[10,38,40],{"id":39},"writing-the-code","Writing the Code",[15,42,43],{},"We've left comments for you in the starter code to guide you through writing the code to control your Blinky circuit. As\na refresher, here are some of the functions you may wish to use.",[45,46,47,70],"table",{},[48,49,50],"thead",{},[51,52,53,60,65],"tr",{},[54,55,56],"th",{},[57,58,59],"strong",{},"Function",[54,61,62],{},[57,63,64],{},"Description",[54,66,67],{},[57,68,69],{},"Usage",[71,72,73,85,96],"tbody",{},[51,74,75,79,82],{},[76,77,78],"td",{},"digitalWrite",[76,80,81],{},"Instructs a pin to output a digital signal until changed.",[76,83,84],{},"digitalWrite(#, HIGH/LOW);",[51,86,87,90,93],{},[76,88,89],{},"pinMode",[76,91,92],{},"Sets a pin to either be an ouptut or an input from here on out.",[76,94,95],{},"pinMode(#, OUTPUT/INPUT);",[51,97,98,101,104],{},[76,99,100],{},"delay",[76,102,103],{},"Waits without doing anything for a specified length of time, in milliseconds. (1000 milliseconds = 1 second)",[76,105,106],{},"delay(1000);",[10,108,110],{"id":109},"testing-your-circuit","Testing Your Circuit",[15,112,113],{},"Once you have your circuit wired and your code written, you can test it out by running your program. If everything is\nset up correctly, you should see your LED blink on and off at a regular interval. If it's not working, double-check your\nwiring and make sure your code is correct. If you need, you can read through the solution below.",[115,116,117,121,142,146],"hint-section",{},[10,118,120],{"id":119},"code-hints","Code Hints",[122,123,124,128,139],"ul",{},[125,126,127],"li",{},"In setup, your only goal should be to set your chosen pin's mode. Output mode lets you turn the pin on and off with\ncode, while input mode lets you wanted to read a value from that pin, such as from a sensor. Which do you think you\nneed for this project?",[125,129,130,131,135,136,138],{},"Remember that ",[132,133,134],"code",{},"delay()"," takes milliseconds, where 1 second is equal to 1000 milliseconds. If you want your LED to stay\non for 1 second and then off for 1 second, how many milliseconds should you pass to ",[132,137,134],{},"?",[125,140,141],{},"digitalWrite(pin, HIGH/LOW) is the command that turns your specified pin on or off. Which do you think you need to\nturn the LED on? Which do you need to turn it off?",[10,143,145],{"id":144},"circuit-hints","Circuit Hints",[122,147,148,155,158],{},[125,149,150,151,154],{},"Remember that a circuit needs to a few things: it must be a ",[57,152,153],{},"closed loop"," that flows from a power source, eventually\nto ground. To get the LED to light up, it will need to be a part of that circuit.",[125,156,157],{},"You will need your circuit to flow from the positive voltage, in this case, one of the numbered GPIO pins, through the\nLED and resistor, and back to ground (GND).",[125,159,160],{},"Make sure your LED is connected in the right direction. The arrow on the LED symbol on the components in your kit\nindicates the direction of current flow. The arrow should point from higher voltage towards ground.",[162,163,164,167,237],"solution-section",{},[15,165,166],{},"Below is the code for the project, and a full diagram of the wiring.",[168,169,174],"pre",{"className":170,"code":171,"language":172,"meta":173,"style":173},"language-cpp shiki shiki-themes github-light github-dark","void setup() {\n  pinMode(3, OUTPUT);\n}\n\nvoid loop() {\n  digitalWrite(3, HIGH);\n  delay(1000);\n  digitalWrite(3, LOW);\n  delay(1000);\n}\n","cpp","",[132,175,176,184,190,196,203,209,215,221,227,232],{"__ignoreMap":173},[177,178,181],"span",{"class":179,"line":180},"line",1,[177,182,183],{},"void setup() {\n",[177,185,187],{"class":179,"line":186},2,[177,188,189],{},"  pinMode(3, OUTPUT);\n",[177,191,193],{"class":179,"line":192},3,[177,194,195],{},"}\n",[177,197,199],{"class":179,"line":198},4,[177,200,202],{"emptyLinePlaceholder":201},true,"\n",[177,204,206],{"class":179,"line":205},5,[177,207,208],{},"void loop() {\n",[177,210,212],{"class":179,"line":211},6,[177,213,214],{},"  digitalWrite(3, HIGH);\n",[177,216,218],{"class":179,"line":217},7,[177,219,220],{},"  delay(1000);\n",[177,222,224],{"class":179,"line":223},8,[177,225,226],{},"  digitalWrite(3, LOW);\n",[177,228,230],{"class":179,"line":229},9,[177,231,220],{},[177,233,235],{"class":179,"line":234},10,[177,236,195],{},[32,238],{"alt":239,"src":240},"Solution wiring to blinky circuit","/images/lessons/02-01-blinky-solution.svg",[242,243,244],"style",{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":173,"searchDepth":186,"depth":186,"links":246},[247,248,249,250,251,252],{"id":12,"depth":186,"text":13},{"id":20,"depth":186,"text":21},{"id":39,"depth":186,"text":40},{"id":109,"depth":186,"text":110},{"id":119,"depth":186,"text":120},{"id":144,"depth":186,"text":145},"First Projects","Blink an LED on and off using your controller and code. This is the classic first project for learning how to control circuits with code.","md",{},"/lessons/2-01-blinky",{"title":5,"description":254},"2-01-blinky.cpp","lessons/2-01-blinky",[262,263,132,264],"beginner","circuits","led","O42G99ZGprKThNtetkO_6WVR0qxTXmHsJYnnoEdn5IY",1775950750610]