Flashing Lights
Overview
In this tutorial you'll create a simple circuit that can turn a light on and off. Below you'll find a diagram and the code.
Set up
Schematic
When you setup the Arduino it's very important that all the wires go into the same spots as shown below. Also LEDs can only work on one direction. The long side should be connected to pin 7.
Things connect on the breadboard by sharing the same column. In the below schematic one side of the LED is connected to pin 7 and the other is connected to GND (ground by way of a resistor).
Code
In this project we're going to learn two new commands.
The pinMode command tells the Arduino if a in is input or output. To use it we tell it first a pin on the Arduino and second INPUT or OUTPUT. Here is an example...
// here we set pin 7 to OUTPUT
pinMode(7, OUTPUT);
// Here we set pin 4 to INPUT
pinMode(4, INPUT);
The digitalWrite command either sends or stops sending electricity to a pin. To use it we tell it first a pin on the Arduino and second HIGH or LOW where HIGH means ON and LOW means OFF. Always remember that we cannot write to a pin that isn't set to output.
// Here we turn pin 7 on.
digitalWrite(7, HIGH);
// Here we turn pin 4 off.
digitalWrite(4, LOW);
With these two commands use the code below to program your arduino! Simply copy this file into your Arduino editor and upload it!
COPY THIS CODE BELOW
Stretch Goals