Blink
You will start by getting your arduino to do something simple first
void setup() { // the setup function runs once when you press reset or power the board
pinMode(LED_BUILTIN, OUTPUT); // initializes digital pin LED_BUILTIN as an output.
}
void loop() { // loop functions run over and over again forever
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
pinMode(LED_BUILTIN, OUTPUT); // initializes digital pin LED_BUILTIN as an output.
}
void loop() { // loop functions run over and over again forever
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Once you get your onboard LED to work start playing around with the code to see what changing it does. Try something creative with it to get it to do something cool.
Reading Resistors
Before we can continue, we have to teach how to read resistors.
We will do this one together
Now teachers will hand out one to students at a time from a bag to see if they can figure it out.
Turning off-board LEDs on and off
You are now going to try and get LEDs to work using the bread board. You will also see how resistors change a circuit.
Wire up your breadboard as shown below.
Wire up your breadboard as shown below.

Swap out a few of the resistors shown and observe how it changes the system.
Once you have tested it a few times move the 5V wire to a pin and change your blink code to try and figure out how to get your new light to turn on and off. You will need to change the pin used in your code from onboard LED to which ever digital pin you have your wire in.
Once you get one to light up, test out trying to put some lights in parallel, in the same column, or series, in the same row. See what happens as you try both.
Once you get one to light up, test out trying to put some lights in parallel, in the same column, or series, in the same row. See what happens as you try both.
Turning onboard LED on and off with Button
We will now try to get that onboard LED to blink by using a button. Set up your circuit similar to below
Use the :
Use the :
- 10K ohm resistor
/* Turns on and off a light emitting diode(LED) connected to digital
pin 13, when pressing a pushbutton attached to pin 2.*/
// these constants set pin numbers: const is used before int to ensure the value does not change
const int buttonPin=2; //the number of the pushbutton pin
const int ledPin=LED_BUILTIN; //the number of the LED pin
int buttonState=0; // variable for reading the pushbutton status
void setup() {
pinMode (ledPin,OUTPUT);
pinMode (buttonPin,INPUT);
}
void loop() {
buttonState=digitalRead(buttonPin);
if(buttonState==HIGH){
digitalWrite(ledPin,HIGH);
}
else{
digitalWrite(ledPin,LOW);
}
}
pin 13, when pressing a pushbutton attached to pin 2.*/
// these constants set pin numbers: const is used before int to ensure the value does not change
const int buttonPin=2; //the number of the pushbutton pin
const int ledPin=LED_BUILTIN; //the number of the LED pin
int buttonState=0; // variable for reading the pushbutton status
void setup() {
pinMode (ledPin,OUTPUT);
pinMode (buttonPin,INPUT);
}
void loop() {
buttonState=digitalRead(buttonPin);
if(buttonState==HIGH){
digitalWrite(ledPin,HIGH);
}
else{
digitalWrite(ledPin,LOW);
}
}