Back to Parent

/*
 This sketch will demonstrate a basic Internet of Things function of the Photon.
It will report the sensor value from a pressure sensor
on Pin A5 to the Particle cloud server.

// Hardware Required:
// 1. Particle Photon
// 2. Pressure sensor
// 3. 1K ohm resistor between pins A5 and ground
// 4. USB to micro USB cable for powering the Photon

*/


//Define our pins.
int buttonPin = A5;
int fsrPin = A0;

//pressureChecktime defines how often does it take to check the pressure level.
int pressureChecktime = 1000000; //10000 milliseconds is  2.7hrs

//record the time we report the pressure status with this
int lastPressureReport;
char PressureValue[4];//this is a tring where we will actual pressure value read from the sensor.

//int buttonState = 0;

void setup() {

  //tell photon if our pins are inputs or outputs
  pinMode(fsrPin, OUTPUT);
  pinMode(buttonPin, INPUT);

  //read the range of sensor
  Serial.begin(9600);

  // Turn on power to the fsr sensor
  digitalWrite(fsrPin, HIGH);

  //initialize timer
  lastPressureReport = millis();
}

void loop() {

  //read the range to determin if announcement;
  int buttonPinVal = analogRead(buttonPin);
  Serial.println(buttonPinVal);
  delay(1000);

  //check if it is time to report
  if ((millis() - lastPressureReport) >= pressureChecktime) {
    lastPressureReport = millis();
    int pressureLevel = analogRead(buttonPin);

    //clarify the pressureLevel into one of three categories
    if (pressureLevel < 1000){
    Particle.publish("pressureLevel", "low", PRIVATE);
    //digitalWrite(ledPin, LOW);

    }
    if (pressureLevel >= 1000 && pressureLevel < 2000)
    Particle.publish("pressureLevel", "Medium", PRIVATE);
    if (pressureLevel >= 2000)
    {
        Particle.publish("pressureLevel", "High", PRIVATE);
        //digitalWrite(ledPin, HIGH);
    }
    //publish the event when the pressure is low
    sprintf(PressureValue, "%d", pressureLevel);
    Particle.publish("sensorValue", PressureValue, PRIVATE);
  }

 } // this is the end of the loop.
Click to Expand

Content Rating

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

0