IES Gómez-Moreno Departamento de Tecnología
Controlling LEDs with Arduino(adapted from a document by Victor Gallego)
Practice 1: Blinking LED
We need:1 protoboard1 LED1 resistor of 220Ωwires
Circuit:
Program:
// Project 1 – Blinking LED int ledPin = 10;
void setup(){ pinMode(ledPin, OUTPUT);}
void loop() { digitalWrite(ledPin, HIGH); delay(1000); digitalWrite(ledPin, LOW); delay(1000);
IES Gómez-Moreno Departamento de Tecnología
}
Exercises:1.1. Put comments in every line in the program1.2. Change the time of blinking
Practice 2: Morse S.O.S.
We need:The same circuit as in practice 1.
Program:
int ledPin = 10;
void setup(){ pinMode(ledPin, OUTPUT);}
void loop(){ for (int x=0; x
IES Gómez-Moreno Departamento de Tecnología
delay(100); } delay(5000);}
Ejercicios:2.1 Put comments in every line in the program2.2 Search in the Internet the Morse code for your name. Change the program so it transmits your name.
Practice 3: Traffic lights
We need:1 protoboard1 yellow LED1 red LED1 green LED3 resistors of 220Ω
Circuit:
Programa:
IES Gómez-Moreno Departamento de Tecnología
// Practice 3 – Traffic lightsint ledDelay = 10000; int redPin = 10;int yellowPin = 9;int greenPin = 8;
void setup() { pinMode(redPin, OUTPUT); pinMode(yellowPin, OUTPUT); pinMode(greenPin, OUTPUT);}
void loop() { digitalWrite(redPin, HIGH); delay(ledDelay); digitalWrite(yellowPin, HIGH); delay(2000); digitalWrite(greenPin, HIGH); digitalWrite(redPin, LOW); digitalWrite(yellowPin, LOW); delay(ledDelay); digitalWrite(yellowPin, HIGH); digitalWrite(greenPin, LOW); delay(2000); digitalWrite(yellowPin, LOW); }
Practice 4: Interactive traffic lights
We need:1 protoboard1 yellow LED2 red LEDs2 green LEDs5 resistors of 220Ω1 PTM switch1 pull-down resistor
IES Gómez-Moreno Departamento de Tecnología
Circuito:
Programa:
// Proyecto 4 – SEMÁFORO INTERACTIVOint cocheRojo = 12; int cocheAmarillo = 11;int cocheVerde = 10;int peatonRojo = 9; int peatonVerde = 8;int pulsador = 2; int tiempoCruzar = 5000; unsigned long tiempoCambio;
void setup() { pinMode(cocheRojo, OUTPUT); pinMode(cocheAmarillo, OUTPUT); pinMode(cocheVerde, OUTPUT); pinMode(peatonRojo, OUTPUT); pinMode(peatonVerde, OUTPUT); pinMode(pulsador, INPUT);
digitalWrite(cocheVerde, HIGH); digitalWrite(peatonRojo, HIGH);}
IES Gómez-Moreno Departamento de Tecnología
void loop() { int estado = digitalRead(pulsador); if (estado == HIGH && (millis() - tiempoCambio) > 5000) { cambiarLuces(); }}
void cambiarLuces() { digitalWrite(cocheVerde, LOW); digitalWrite(cocheAmarillo, HIGH); delay(2000); digitalWrite(cocheAmarillo, LOW); digitalWrite(cocheRojo, HIGH); delay(1000); digitalWrite(peatonRojo, LOW); digitalWrite(peatonVerde, HIGH); delay(tiempoCruzar); for (int x=0; x
IES Gómez-Moreno Departamento de Tecnología
4.2 Put comments in every line in the program
Practice 5: Moving LEDs
We need:1 protoboard10 LEDs10 resistors of 220Ω
Circuit:
Programa:
int ledPin[ ] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; int ledDelay = 200;
void setup() { for (int x=0; x
IES Gómez-Moreno Departamento de Tecnología
void loop() {for (int x=0; x
IES Gómez-Moreno Departamento de Tecnología
Practice 6: Interactive moving LEDs
We need:The circuit in practice 5 and a variable resistor.
Circuito:
Programa:
byte ledPin[ ] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; int ledDelay; int potPin = 2;
void setup()
IES Gómez-Moreno Departamento de Tecnología
{ for (int x=0; x
IES Gómez-Moreno Departamento de Tecnología
Practice 7 – Increasing LEDWe need:1 LED verde1 resistencia de 220 Ω
Circuito:
Programa:// Proyecto 7 – Increasing LED
int ledPin = 11;
void setup() { pinMode(ledPin, OUTPUT);}
void loop() { for (int valorLED=0; valorLED