Back to Parent

//PhotoCell inputs

int photoCellPin = A1; //input pin for photosensor
int photoCellReading = 0; //analog reading variable for photosensor

// Temperature Sensor inputs

int tempPin = A0; //input pin for tmp36
double temperature = 0.0; //variable for storing temperature value

//RGB inputs

int redPin = D4; //input pin for red color on RGB LED    
int greenPin = D6; //input pin for green color on RGB LED 
int bluePin = D5; //input pin for blue color on RGB LED  
int redValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int greenValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int blueValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255</td>

//Flex sensor inputs

int flexPin = A2; //input pin for photosensor
int flexReading = 0; //analog reading variable for photosensor
int speakerPin = D8; //input pin for piezo sensor

//Soilmoisture inputs
int moistPin = A4; //input pin for soil moisture sensor
int moistVal = 0; //analog reading variable for soil moisture sensor
int moistLed = D7; //input variable for green LED in soil moisture circuit

int last_published = -1;
void setup() {
 // Set up pins for RGB
  
  pinMode( redPin, OUTPUT); 
  pinMode( greenPin, OUTPUT);
  pinMode( bluePin, OUTPUT);
  analogWrite( redPin, redValue); // turn off the pin...
  analogWrite( greenPin, greenValue); // turn off the pin...
  analogWrite( bluePin, blueValue); // turn off the pin...
  
  //Set up pins for temperature sensor
  
  pinMode(tempPin, INPUT);
  
  //set up pin for flex sensor
  pinMode(speakerPin, OUTPUT);
  
  //set up pin for soil moisture sensor
  pinMode(moistLed, OUTPUT);

    // Register a Particle variable here
   Particle.variable("temperature", &temperature, DOUBLE); //collect temperature value 
  //Particle.variable("temperatureF", &temperatureF, DOUBLE);
   Particle.variable("light", &photoCellReading, INT); // collect light value
   Particle.variable("Stem_bend", &flexReading, INT); //collect stem bending value
   Particle.variable("soil_moisture", &moistVal, INT);//collect the soil moisture value
  
}

void loop() {
  int tempReading = analogRead(tempPin); //store analog value in tempReading based on input from tempPin
  double voltage = (tempReading * 3.3) / 4095.0; //calculate voltage
  temperature = (voltage - 0.5) * 100; // Calculate the temperature and update our static variable
  sendSMS();

  photoCellReading = analogRead(photoCellPin);    // Use analogRead to read the photo cell reading

  redValue = map(photoCellReading, 2200, 2900, 0, 255); // Map this value into the PWM range (0-255)
  blueValue = map(photoCellReading, 3000, 3500, 255, 0); // Map this value into the PWM range (0-255)
  
  if (photoCellReading > 2500 && photoCellReading < 3000 && temperature < 20.0) //Parallely check photosensor and temperature sensor and only if both are true proceed
  {
     analogWrite(redPin, redValue); // fade the LED to the desired brightness
  } 
  else if (photoCellReading > 3000 && temperature < 20.0) //Parallely check photosensor and temperature sensor and only if both are true proceed
  {
        analogWrite(bluePin, blueValue); // fade the LED to the desired brightness  
  }
  else 
  {
        analogWrite(redValue, 255); //turn all the colors off
        analogWrite(blueValue, 255); //turn all the colors off
        analogWrite(greenValue, 255); //turn all the colors off
  }
  moistVal = analogRead(moistPin); //store analog value in moistVal based on input from moistPin
  flexReading = analogRead(flexPin); //store analog value in flexReading based on input from flexPin
    if (flexReading < 100 ) //check if the flex sensor is bent
    {
        if (moistVal > 2000) //verify if there is enough moisture in soil
        {
            digitalWrite(moistLed, HIGH); //Turn the LED on
        }
        else 
        {
        tone(speakerPin, 494, 500); //play the piezp sensor
        }
    }    
}
void sendSMS(  ){

  // check if 1 minute has elapsed
	if( flexReading < 100 ){
		Particle.publish( "SendSMS", String( flexReading  ) );
		last_published = millis();
	delay(100000000);
	}
}
Click to Expand

Content Rating

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

0