Back to Parent

Code for the Locker
//Locker code
//Reads the hall effect sensor and actuates the solenoid to read the locker

//Set pins
int hallpin = A0;
int solenoidPin = D1;
int hallEffectValue = 0;

void setup()
{
  pinMode(hallpin, INPUT); //Reads the hall effect sensor
  pinMode(solenoidPin, OUTPUT); //Moves the solenoid
  Serial.begin( 9600 ); //Read serial for insta-feedback!
}

void loop()
{
  //read hall effect value
  hallEffectValue = analogRead(hallpin);
  if (hallEffectValue < 100){ //Performs this sequence if the magnet is near.
    digitalWrite(solenoidPin, HIGH); //Unlocks the locker
    Particle.publish("lockernum", "23"); //send information to ifttt/Kana's apple watch!!
    delay(500); //Wait a few seconds to open the door
  }
  else digitalWrite(solenoidPin, LOW); //close the lock after a few seconds
  Serial.print( "Sensor reading is: " ); //Writes the hall effect value to the serial monitor
  Serial.println( hallEffectValue );
  delay(500);
}
Click to Expand

Content Rating

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

0