0% found this document useful (0 votes)
45 views11 pages

Práctica 1 Con Arduino

The document describes 6 Arduino practices: 1) Blinking an LED, 2) Traffic light simulation, 3) Button-controlled LED, 4) Potentiometer-controlled LED brightness, 5) Light-controlled LED using an LDR sensor, and 6) Controlling a servo motor. Each practice uses different Arduino codes to control outputs such as LEDs and servos based on input signals from buttons, sensors, or position variables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views11 pages

Práctica 1 Con Arduino

The document describes 6 Arduino practices: 1) Blinking an LED, 2) Traffic light simulation, 3) Button-controlled LED, 4) Potentiometer-controlled LED brightness, 5) Light-controlled LED using an LDR sensor, and 6) Controlling a servo motor. Each practice uses different Arduino codes to control outputs such as LEDs and servos based on input signals from buttons, sensors, or position variables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Prctica 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
}
Prctica 2: SEMFORO.
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); // Semforo en rojo
digitalWrite(ledA, LOW);
digitalWrite(ledV, LOW);
delay(1000);
digitalWrite(ledR, LOW); // semforo en verde
digitalWrite(ledA, LOW);
digitalWrite(ledV, HIGH);
delay(1000);
digitalWrite(ledR, LOW);
digitalWrite(ledA, HIGH);
digitalWrite(ledV, LOW); // semforo en amarillo
delay(1000);
digitalWrite(ledR, LOW); // tiempo de espera todo apagado
digitalWrite(ledA, LOW);
digitalWrite(ledV, LOW);
delay(1000);
}
Prctica 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);
}
}
Prctica 4: CONTROL DE LA INTENSIDAD LED CON POTENCIMETRO.
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);
}

Prctica 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);}

}
Prctica 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
}
}

You might also like