top of page

Code for Base Arduino

#define ALTITUDE 412.0 //User altitude
#define T5 A6

    int temp = 200;

Adafruit_ADS1015 ads1115(0x48);

    int heater = 9;      // Heater connected to digital pin 9
    int val = 0;         // variable to store the read value
    int adc4 = 0;
    float adc4v,adc5v;


void setup()
{
  Serial.begin(9600);
  Serial.println("REBOOT");


 
  pinMode(T5, OUTPUT);
 
  analogWrite(9,200);
 
  if (pressure.begin())
    Serial.println("BMP180 init success");
  else
  {
    // Oops, something went wrong, this is usually a connection problem,
    // see the comments at the top of this sketch for the proper connections.
    Serial.println("BMP180 init fail\n\n");
    while(1); // Pause forever.
  }
  ads1115.begin();
}
void loop()
{
 
  char status;
  double T,P,p0,a;
  // Loop here getting pressure readings every 10 seconds.
  // If you want sea-level-compensated pressure, as used in weather reports,
  // you will need to know the altitude at which your measurements are taken.
  // We're using a constant called ALTITUDE in this sketch:
  Serial.println("-----------------------------------");
  Serial.print("provided altitude: ");
  Serial.print(ALTITUDE*3.28084,0);
  Serial.println(" feet");
  // If you want to measure altitude, and not pressure, you will instead need
  // to provide a known baseline pressure. This is shown at the end of the sketch.
  // You must first get a temperature measurement to perform a pressure reading.
  // Start a temperature measurement:
  // If request is successful, the number of ms to wait is returned.
  // If request is unsuccessful, 0 is returned.
  status = pressure.startTemperature();
  if (status != 0)
  {
    // Wait for the measurement to complete:
    delay(status);
    // Retrieve the completed temperature measurement:
    // Note that the measurement is stored in the variable T.
    // Function returns 1 if successful, 0 if failure.
    status = pressure.getTemperature(T);
    if (status != 0)
    {
      // Print out the measurement:
      Serial.print("temperature: ");
      Serial.print(T,2);
      Serial.print(" deg C, ");
      Serial.print((9.0/5.0)*T+32.0,2);
      Serial.println(" deg F");
      // Start a pressure measurement:
      // The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait).
      // If request is successful, the number of ms to wait is returned.
      // If request is unsuccessful, 0 is returned.
      status = pressure.startPressure(3);
      if (status != 0)
      {
        // Wait for the measurement to complete:
        delay(status);
        // Retrieve the completed pressure measurement:
        // Note that the measurement is stored in the variable P.
        // Note also that the function requires the previous temperature measurement (T).
        // (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.)
        // Function returns 1 if successful, 0 if failure.
        status = pressure.getPressure(P,T);
        if (status != 0)
        {
          // Print out the measurement:
          Serial.print("absolute pressure: ");
          Serial.print(P,2);
          Serial.print(" mb, ");
          Serial.print(P*0.0295333727,2);
          Serial.println(" inHg");
          // The pressure sensor returns abolute pressure, which varies with altitude.
          // To remove the effects of altitude, use the sealevel function and your current altitude.
          // This number is commonly used in weather reports.
          // Parameters: P = absolute pressure in mb, ALTITUDE = current altitude in m.
          // Result: p0 = sea-level compensated pressure in mb
          a = pressure.altitude(P,p0);
          Serial.print("computed altitude: ");
          Serial.print(a*3.28084,0);
          Serial.println(" feet");
          Serial.println("-----------------------------------");
          Serial.println(" ");
        }
        else Serial.println("error retrieving pressure measurement\n");
      }
      else Serial.println("error starting pressure measurement\n");
    }
    else Serial.println("error retrieving temperature measurement\n");
  }
  else Serial.println("error starting temperature measurement\n");
 
  delay(1000);  // Pause for 1 seconds

   int16_t adc0, adc1, adc2, adc3;
      static int Therm5;
      static int i;

      adc4 = analogRead(T5);
      adc4v = (float)(adc4*5)/1024;
      adc5v = (float)(adc4>>2);

        Therm5 = map(adc4 , 0 , 1024 , 0 , 255);

      if((i) == 2){
       if(Therm5 >= 215 && Therm5 <= 220){
              analogWrite(9,temp);
          }
        else if(Therm5 < 215){
              if(temp > 250){
                temp = 248;
              }
              else{
                temp = temp+2;
                analogWrite(9,temp);
              }
          }
        else{
              if(temp <= 5){
                temp = 10;
                }
              else{
                temp = temp-2;
                analogWrite(9,temp);
              }
          }
          i = -1;
      }

      i = i+1;
      
      adc0 = ads1115.readADC_SingleEnded(0);
      adc1 = ads1115.readADC_SingleEnded(1);
      adc2 = ads1115.readADC_SingleEnded(2);
      adc3 = ads1115.readADC_SingleEnded(3);
      Serial.print("AIN0: "); Serial.println(adc0*10);
      Serial.print("AIN1: "); Serial.println(adc1*10);
      Serial.print("AIN2: "); Serial.println(adc2*10);
      Serial.print("AIN3: "); Serial.println(adc3*10);
      Serial.println(" ");
      Serial.print("AIN4: "); Serial.print(adc4v); Serial.println("V");
      Serial.println(" ");
      Serial.print("AIN5: "); Serial.print(adc5v); //Serial.println("V");
      Serial.println(" ");
      Serial.println(temp);
      Serial.println(i);
      Serial.println(Therm5);
      
}

 

© 2023 by Name of Site. Proudly created with Wix.com

  • Facebook Social Icon
  • Twitter Social Icon
  • Instagram Social Icon
bottom of page