[go: up one dir, main page]

0% found this document useful (0 votes)
31 views4 pages

Guia 13 Eld

The document shows code for an Arduino program that uses a potentiometer and servo motor. It reads the potentiometer value and maps it to an angle to control the servo position. For the second circuit, it adds an LED that turns on when the servo reaches a certain angle.

Uploaded by

Alberto Molina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views4 pages

Guia 13 Eld

The document shows code for an Arduino program that uses a potentiometer and servo motor. It reads the potentiometer value and maps it to an angle to control the servo position. For the second circuit, it adds an LED that turns on when the servo reaches a certain angle.

Uploaded by

Alberto Molina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

int Sensor_Temp = A0; // select the input pin for the potentiometer

int SegmentoA = 7; // select the pin for the LED


int SegmentoB = 8;
int SegmentoC = 9;
int SegmentoD = 10;
int SegmentoE = 11;
int SegmentoF = 12;
int SegmentoG = 13;
int Valor_sensor = 0; // variable to store the value coming from the sensor
float tempC; // Variable para almacenar el valor obtenido del sensor (0 a 1023)

void setup() {
// declare the ledPin as an OUTPUT:
pinMode(SegmentoA, OUTPUT);
pinMode(SegmentoB, OUTPUT);
pinMode(SegmentoC, OUTPUT);
pinMode(SegmentoD, OUTPUT);
pinMode(SegmentoE, OUTPUT);
pinMode(SegmentoF, OUTPUT);
pinMode(SegmentoG, OUTPUT);
Serial.begin(9600);
}

void loop() {
// lectura del valor desde el sensor:
Valor_sensor = analogRead(Sensor_Temp);
// Calculamos la temperatura con la fórmula
tempC = (5.0 * Valor_sensor * 100.0)/1024.0;
Serial.print(tempC);
Serial.print(" \n ");

if (tempC >= 30) {


digitalWrite(SegmentoA, LOW);
digitalWrite(SegmentoB, HIGH);
digitalWrite(SegmentoC, HIGH);
digitalWrite(SegmentoD, LOW);
digitalWrite(SegmentoE, HIGH);
digitalWrite(SegmentoF, HIGH);
digitalWrite(SegmentoG, HIGH);
}
else
{
digitalWrite(SegmentoA, LOW);
digitalWrite(SegmentoB, LOW);
digitalWrite(SegmentoC, LOW);
digitalWrite(SegmentoD, HIGH);
digitalWrite(SegmentoE, HIGH);
digitalWrite(SegmentoF, HIGH);
digitalWrite(SegmentoG, LOW);
}
delay(100);
}
RETO CIRCUITO 1
int Sensor_Temp = A0; // select the input pin for the potentiometer
int SegmentoA = 7; // select the pin for the LED
int SegmentoB = 8;
int SegmentoC = 9;
int SegmentoD = 10;
int SegmentoE = 11;
int SegmentoF = 12;
int SegmentoG = 13;
int Valor_sensor = 0; // variable to store the value coming from the sensor
float tempC; // Variable para almacenar el valor obtenido del sensor (0 a 1023)

void setup() {
// declare the ledPin as an OUTPUT:
pinMode(SegmentoA, OUTPUT);
pinMode(SegmentoB, OUTPUT);
pinMode(SegmentoC, OUTPUT);
pinMode(SegmentoD, OUTPUT);
pinMode(SegmentoE, OUTPUT);
pinMode(SegmentoF, OUTPUT);
pinMode(SegmentoG, OUTPUT);
Serial.begin(9600);
}

void loop() {
// lectura del valor desde el sensor:
Valor_sensor = analogRead(Sensor_Temp);
// Calculamos la temperatura con la fórmula
tempC = (5.0 * Valor_sensor * 100.0)/1024.0;
Serial.print(tempC);
Serial.print(" \n ");

if (tempC >= 35) {


digitalWrite(SegmentoA, HIGH);
digitalWrite(SegmentoB, HIGH);
digitalWrite(SegmentoC, HIGH);
digitalWrite(SegmentoD, LOW);
digitalWrite(SegmentoE, HIGH);
digitalWrite(SegmentoF, HIGH);
digitalWrite(SegmentoG, HIGH);
}
else
{
digitalWrite(SegmentoA, LOW);
digitalWrite(SegmentoB, LOW);
digitalWrite(SegmentoC, HIGH);
digitalWrite(SegmentoD, HIGH);
digitalWrite(SegmentoE, HIGH);
digitalWrite(SegmentoF, HIGH);
digitalWrite(SegmentoG, HIGH);
}
delay(100);
}
CIRCUITO 2

#include<Servo.h> // Librería para uso de potenciómetro y señales analógicas

Servo myServo; // crea un objeto servo para controlar un servo


int const PotPin=A0; // pin analógico utilizado para conectar el potenciómetro

// variable para leer el valor del pin analógico


int PotVal;
int angulo;

void setup(){
myServo.attach(11); // conecta el servo en el pin 11 al objeto servo
Serial.begin(9600);
}

void loop(){
PotVal=analogRead(PotPin);// lee el valor del potenciómetro (valor entre 0 y 1023)
Serial.print("Valor potenciometro:");
Serial.print(PotVal);
Serial.print(" \t "); //espacio entre texto
angulo=map(PotVal,0,1023,0,180); // escala para usarlo con el servo (valor entre 0 y 180)
Serial.print ("Angulo= ");
Serial.println (angulo);
myServo.write(angulo);// establece la posición del servo de acuerdo con el valor escalado
delay (15); // retraso de 15 milisegundos
}
RETO CIRCUITO 2

#include<Servo.h> // Librería para uso de potenciómetro y señales analógicas

Servo myServo; // crea un objeto servo para controlar un servo


int const PotPin=A0; // pin analógico utilizado para conectar el potenciómetro

// variable para leer el valor del pin analógico


int PotVal;
int angulo;
int LED = 2;

void setup(){
myServo.attach(11); // conecta el servo en el pin 11 al objeto servo
Serial.begin(9600);
pinMode(LED, OUTPUT);
}

void loop(){
PotVal=analogRead(PotPin);// lee el valor del potenciómetro (valor entre 0 y 1023)
Serial.print("Valor potenciometro:");
Serial.print(PotVal);
Serial.print(" \t "); //espacio entre texto
angulo=map(PotVal,0,1023,0,90); // escala para usarlo con el servo (valor entre 0 y 180)
Serial.print ("Angulo= ");
Serial.println (angulo);
myServo.write(angulo);// establece la posición del servo de acuerdo con el valor escalado
delay (15); // retraso de 15 milisegundos

if (angulo >= 75){


digitalWrite(LED, HIGH);
}
else{
digitalWrite(LED, LOW);
}
}

You might also like