Back to Parent

int inputPin = D4;              // choose the input pin (for PIR sensor)
int ledPin = D1;                // LED Pin
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status
int switchPin = D2;             // switch wired to D2

int calibrateTime = 10000;      // calibrate


void setup()
{
  pinMode( ledPin, OUTPUT );
  pinMode( switchPin , INPUT_PULLUP ); // sets pin as input
  pinMode(inputPin, INPUT_PULLDOWN );     // declare sensor as input
  pinMode( ledPin , OUTPUT ); // sets pin as output

  Serial.begin( 9600 ); // start the serial monitor
}

void loop()
{
  int switchvalue = digitalRead(switchPin);
  // if the sensor is calÄbrated
  if ( calibrated() )
  {
  // get the data from the sensor
    readTheSensor();

  }
  if( calibrated() && switchvalue==HIGH  ){
    // report it out, if the state has changed
    reportTheData();

  }else {
    digitalWrite ( ledPin, LOW);
  }

  Serial.print( "Switch Value is : " );
  Serial.println( switchvalue );
  Serial.print( "PIR value is : " );
  Serial.println( val );
  Serial.print( "PIR State is : " );
  Serial.println( pirState );


  delay( 100 );
}


void readTheSensor() {
  val = digitalRead(inputPin);
}

bool calibrated() {
  return (millis() > calibrateTime);
}


  setLED( pirState );

}

void setLED( int state )
{
  digitalWrite( ledPin, state );
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0