Skip to content

Capacitor on breadboard

We were talking about threshold 3V value, used to make Arduino choose between a state - red LED On - or the other - Off.

Decision is set in following code snippet

if ((sensorpin/1024*5)<3) {
    digitalWrite(outputpin, LOW);
  else {
    digitalWrite(outputpin, HIGH);

"sensorpin/1024*5" returns matching Volts value read as already said: 5 is 5V power supply.

sensorpin has been declared float because it receives a number with decimal; if declared int then you'll get a reading error.
digitalWrite function sets 13th Arduino's digital pin to logical LOW=0 or HIGH=1, physical 0V or 5V.

Serial monitor

Pictures beside will explain what Arduino communicates to serial monitor every one second.

Remember that crossing 3V value (here the discharging phase), red LED on pin 13 from On gets Off.