Lesson 7: Analog input
Esta página necesita un navegador reciente (con soporte para SharedArrayBuffer). Por favor, actualiza Chrome, Edge, Firefox o Safari a la última versión.
English
More than on and off
- The pins A0 to A5 can measure a voltage from 0 V to 5 V.
analogRead(A0)gives a number from 0 (0 V) to 1023 (5 V). 2.5 V gives about 512.- A potentiometer (a knob) or a light sensor gives a voltage. On this page, move the slider.
void setup() {
Serial.begin(9600);
}
void loop() {
int value = analogRead(A0);
Serial.println(value);
delay(500);
}
English
A night light
- A light sensor gives a small number in the dark and a big number in bright light.
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
if (analogRead(A0) < 300) { // dark
digitalWrite(13, HIGH);
} else {
digitalWrite(13, LOW);
}
}
Dificultad 2/5 · 140 monedas + un pequeño bono en el primer intento de hoy
Read A0 and print the voltage with 2 decimals, like Voltage: 2.50, every 500 ms. The voltage is value * 5.0 / 1023.0.
Haz clic en Ejecutar para ver la salida aquí.
Dificultad 3/5 · 200 monedas + un pequeño bono en el primer intento de hoy
A light sensor is on A0. Switch the LED on pin 13 ON when the reading is below 300 (dark) and OFF otherwise.
Haz clic en Ejecutar para ver la salida aquí.