0% found this document useful (0 votes)
110 views5 pages

Códigos Prácticas ARDUINO

This document describes 8 Arduino practices including: 1) Blinking an LED 2) Creating a traffic light 3) Turning on an LED with a button 4) Controlling LED brightness with a potentiometer 5) Controlling a light with an LDR sensor 6) Controlling a servo motor 7) Controlling a motor 8) Creating an audible traffic light for the blind
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
110 views5 pages

Códigos Prácticas ARDUINO

This document describes 8 Arduino practices including: 1) Blinking an LED 2) Creating a traffic light 3) Turning on an LED with a button 4) Controlling LED brightness with a potentiometer 5) Controlling a light with an LDR sensor 6) Controlling a servo motor 7) Controlling a motor 8) Creating an audible traffic light for the blind
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

Código ARDUINO

 Práctica 1: BLINK- ENCENDER UN LED

int led = 13;


void setup() {
pinMode(led, OUTPUT); //Se configura el pin 13 como salida
}
void loop() {
digitalWrite(led, HIGH); // Se enciende el led
delay(1000); // Se espera unos segundos
digitalWrite(led, LOW); // Se apaga el led
delay(1000); // Se espera unos segundos
}
 Práctica 2: SEMÁFORO.

int ledR = 12;


int ledA = 9;
int ledV = 6;
void setup() {
pinMode(ledR, OUTPUT);
pinMode(ledA, OUTPUT);
pinMode(ledV, OUTPUT);
}
void loop() {
digitalWrite(ledR, HIGH); // Semáforo en rojo
digitalWrite(ledA, LOW);
digitalWrite(ledV, LOW);
delay(1000);
digitalWrite(ledR, LOW); // semáforo en verde
digitalWrite(ledA, LOW);
digitalWrite(ledV, HIGH);
delay(1000);
digitalWrite(ledR, LOW);
digitalWrite(ledA, HIGH);
digitalWrite(ledV, LOW); // semáforo en amarillo
delay(1000);
digitalWrite(ledR, LOW); // tiempo de espera todo apagado
digitalWrite(ledA, LOW);
digitalWrite(ledV, LOW);
delay(1000);
}
 Práctica 3: ENCENDER LED CON PULSADOR

const int buttonPin = 2; // the number of the pushbutton pin


const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}

 Práctica 4: CONTROL DE LA INTENSIDAD LED CON


POTENCIÓMETRO.

int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 9; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from
the sensor
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(sensorValue);
}
 Práctica 5: CONTROL DE LUZ CON LDR

int sensorPin = A0;


int ledPin = 7;
int sensorValue = 0;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
sensorValue = analogRead(sensorPin);
if (sensorValue >200){
digitalWrite(ledPin, LOW);}
else{
digitalWrite(ledPin, HIGH);}
}

 Práctica 6: CONTROL DE UN SERVOMOTOR.

#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo
object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180
degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable
‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0
degrees
{
myservo.write(pos); // tell servo to go to position in variable
‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
}
 Práctica 7: CONTROL DE UN MOTOR.

int motorPin = 13;


void setup() {
pinMode(motorPin, OUTPUT); //Se configura el pin 13 como
salida
}
void loop() {
digitalWrite(motorPin, HIGH); // Se enciende el led
delay(1000); // Se espera unos segundos
digitalWrite(motorPin, LOW); // Se apaga el led
delay(1000); // Se espera unos segundos
}

 Práctica 8: SEMÁFORO PARA INVIDENTES.

int ledR = 10;


int ledA = 9;
int ledV = 8;
int zumbador = 6;
void setup() {
pinMode(ledR, OUTPUT);
pinMode(ledA, OUTPUT);
pinMode(ledV, OUTPUT);
pinMode(zumbador, OUTPUT);
}
void loop() {
digitalWrite(ledR, HIGH); // Semafoto en rojo
digitalWrite(zumbador, HIGH); // Aviso a invidentes
digitalWrite(ledA, LOW);
digitalWrite(ledV, LOW);
delay(4000);
digitalWrite(ledR, LOW); // Semáforo verde
digitalWrite(zumbador, LOW); // Aviso a invidentes
digitalWrite(ledA, LOW);
digitalWrite(ledV, HIGH);
delay(4000);
digitalWrite(ledR, LOW); // Semáforo ámbar
digitalWrite(zumbador, LOW);
digitalWrite(ledA, HIGH);
digitalWrite(ledV, LOW);
delay(800);
}

You might also like