IFD:Interaktive Elektronik 2012/code

From Medien Wiki

resistive Sensor

Resistive Sensor Steckplatine.png
Potentiometer A0 Serial Steckplatine.png

Recipe for resistive sensor:

  • Pick a resistive sensor
  • Measure its lowest and highest resistance using a multimeter.
  • Write the name of the sensor and the maximum and minimum resistance on the black board.
  • pick a resistor which has the same value as the sensor on its highest value
  • Use the below code and create the circuit for a resistive sensor
  • open the serial monitor and have a look at the values.
  • try larger and smaller resistors and see the difference.
  • use an other sensor (one that is already listed on the black board)

Recipe for Potentiometer:

  • connect the Potentiometer as displayed on the right.
  • use the same program as before for the analog sensor
  • see what values you get - compare with values from the resistive sensor.


int mySensorValue;

void setup () {
 Serial.begin(9600);
}

void loop () {
  mySensorValue = analogRead(A0);
  Serial.print("The Sensor Value is: ");
  Serial.println(mySensorValue);
}


switch or Button

Button 1k Pullup Steckplatine.png
int mySensorValue;

void setup () {
 Serial.begin(9600);
 pinMode(13,OUTPUT);
 pinMode(4,INPUT);
}

void loop () {
  mySensorValue = digitalRead(4);
  if (mySensorValue == LOW) {
    Serial.println("The Button is pressed. ");
    digitalWrite(13,HIGH);
  }
  else {
    Serial.println("The Button is not pressed");
    digitalWrite(13,LOW);
  } 
}