Z SensorWiki

< Previous | Home | Next >

Use the same sensor as in previous task. The only difference is that we use it in digital mode. Input comparator decides whether the measured value is below (0) or above (1) the fixed comparative level.

Try following programm:

#define LED_Yellow  13   // select the pin for the LED
#define SENSOR  3

long val = 0;           // variable to store the value coming from the sensor
void setup() 
  pinMode(LED_Yellow, OUTPUT);    // declare this pin as an OUTPUT
  pinMode(SENSOR, INPUT);         // declare this pin as an INPUT


  Serial.println("Test started   \n");
  digitalWrite(LED_Yellow, HIGH);  // make it visible

void loop() 
    val = digitalRead(SENSOR);     // read the value from the sensor
    Serial.print("Sensor = ");  
    Serial.println(val, BIN);  
}   /* End of Loop */

Presented solution is much quickier and easier, unfortunately we lost the possibility of the sensor callibration.

< Previous | Home | Next >