RUNlight

Made by jlwithro

A safety light concept for running at night.

Created: September 16th, 2015

0
0
/* Knock Sensor
   http://www.arduino.cc/en/Tutorial/Knock
   
   created 25 Mar 2007
   by David Cuartielles <http://www.0j0.org>
   modified 30 Aug 2011
   by Tom Igoe
   This example code is in the public domain.

 */
 
// these constants won't change:
const int ledPin = 11;      // led connected to digital pin 13
const int knockSensor = A0; // the piezo is connected to analog pin 0
const int threshold = 50;  // threshold value to decide when the detected sound is a knock or not

// these variables will change:
int sensorReading = 0;      // variable to store the value read from the sensor pin
int timer = 0;

void setup() {
 pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
 Serial.begin(9600);       // use the serial port
}

void loop() {
  // read the sensor and store it in the variable sensorReading:
  sensorReading = analogRead(knockSensor);    
  Serial.println(analogRead(sensorReading));
  
  // if the sensor reading is greater than the threshold:
  if (sensorReading <= threshold) {
    //timer initiate
    timer = 800; //800
    // update the LED pin itself:        
    analogWrite(ledPin, 100);
    // send the string "Knock!" back to the computer, followed by newline
  }
  
  if (timer < 1){
   // update the LED pin itself:        
    analogWrite(ledPin, 0); 
    }

  timer = timer-1;
  if (timer <= 0)
  {timer = 0;
  }
  delay(10);
}
Click to Expand
x
Share this Project

Found In
Courses

48-739 Making Things Interactive

· 0 members

Making Things Interactive (MTI) is a studio course based on physical prototyping and computing. You will develop novel sensing, interaction and display techniques through projects and short assignm...more


About

A safety light concept for running at night.