Lab 6

Description

I have quite a lot of experiences that I forget to bring my Cal ID card when I go to the gym or South Hall. Especially, it really annoyed me this weekend because I came to the South Hall twice without my Cal ID card so that I wasn't able to enter the building. 

This Input-Output coincidence tool is designed to help me in such situations. When you press a certain point in the wallet, it makes sound if the card is inside the wallet. If not, it doesn't make any sound. Users can know if their necessary card (such as Cal 1 card) is inside using this tool.

The code is simple, but the difficult part was to find a threshold that can distinguish when the Cal ID card exists or not.

Code

 

int potPin = 0;   // select the input pin for the potentiometer
int speakerPin = 10;   // select the pin for the LED
int val = 0;      // variable to store the value coming from the sensor
int threshold = 1000;
 
void setup() {
  Serial.begin(9600);
}
 
void loop() {
  val = analogRead(potPin);    // read the value from the sensor, between 0 - 1024
  Serial.println(val);
  
  if(val > threshold){
    analogWrite(speakerPin, val/4); // analogWrite can be between 0-255    
  }
 
}

 

Photo

Attached

Photo of Lab6 Assignment
0
Your rating: None