Skip to content

Capacitor on breadboard

"No please, software's not for me"

Maybe you're right, but just a moment; it's time to explain why last pictures of previous page differ.

Simply in code programming Arduino micro-controller a threshold value is used to create two possible events: On and Off, like a light home switch. Value is 3V.

But where can we probe it?

Just remember the darker yellow wire: this goes from C positive side to an Arduino analog input, which collects the probed value from breadboard. Arduino transforms it to an equivalent number from 0 to 1023 (so range is 1024 possible values) that can be manipulated.

Transformation is needed because arduino is a computer, and like every one of them it computes digital unit.

Example of light switch can help: you move your hand in an analog way, and switch transforms this movement into one of its possible condition, on or off. Here there's same stuff, with main difference of a wider range giving you better precision rebuilding original value.

We're proud to show you the best and huge software ever written since man exists

// Riccardo Giuliani for hw2sw.com

// Words after double slash are simply comments, don't affect real code
// Two variables, first accept decimals, second no.
float sensorpin;
int outputpin = 13;

// Important function where setup starting conditions
void setup() {
  // Serial communication set with a 9600 baudrate
  Serial.begin(9600);
}

// Main program loop
void loop() {
  // 1 second delay
  delay(1000);
  Listening on Arduino's Analog 0 pin
  sensorpin = analogRead(A0);
  Print result directly in Arduino's serial monitor, and goes ahead
  Serial.println((sensorpin/1024*5));
  // new 1 second delay
  delay(1000);
  // Comparing test
  if ((sensorpin/1024*5)<3) {
    digitalWrite(outputpin, LOW);
    Serial.println("BASSO");
  }
  else {
    digitalWrite(outputpin, HIGH);
    Serial.println("ALTO");
  }
}