0% found this document useful (0 votes)
25 views

Lab01 Arduino

The document defines variables to store analog input values and voltage levels. It sets up digital pins as outputs to control LEDs. The main loop reads the analog input, converts it to voltage, prints it, and uses if/else statements to light different combinations of LEDs depending on the voltage range detected.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Lab01 Arduino

The document defines variables to store analog input values and voltage levels. It sets up digital pins as outputs to control LEDs. The main loop reads the analog input, converts it to voltage, prints it, and uses if/else statements to light different combinations of LEDs depending on the voltage range detected.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

int adc;

int v;
float voltaje;
void setup() {
Serial.print(9600);
pinMode(1,OUTPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
}
void loop() {
// lectura señal anlógica
adc = analogRead(A0);
delay(10);
// Conversión a voltaje
v=adc;
voltaje= v*=5;
voltaje= voltaje/=1023;
Serial.print(" voltaje=");
Serial.println(voltaje);
//Comparador para activar los leds
if (voltaje > 0 && voltaje <= 1)
{
digitalWrite(1,HIGH);
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
}

else if (voltaje > 1 && voltaje <= 2)


{
digitalWrite(1,HIGH);
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
}

else if (voltaje > 2 && voltaje <= 3)


{
digitalWrite(1,HIGH);
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
}
else if (voltaje > 3 && voltaje <= 4)
{
digitalWrite(1,HIGH);
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
}
else if (voltaje > 4 && voltaje <= 5)
{
digitalWrite(1,HIGH);
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
}

else
{
digitalWrite(1,LOW);
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
}
}

You might also like