BMP180 Temperature Switch

I am currently trying to use a BMP180 sensor on my Arduino Uno as an on and off switch for a dc motor with a small fan attachment. The idea is that if the temperature is above 75F the fan turns on and if it is below 75F the fan turns off. I have attached the code that I have for just the sensor and I am asking for help or a push in the right direction with the code for the fan part.

#include <Adafruit_BMP085.h>

/*************************************************** 
  This is an example for the BMP085 Barometric Pressure & Temp Sensor

  Designed specifically to work with the Adafruit BMP085 Breakout 
  ----> https://www.adafruit.com/products/391

  These pressure and temperature sensors use I2C to communicate, 2 pins
  are required to interface
  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/

// Connect VCC of the BMP085 sensor to 3.3V (NOT 5.0V!)
// Connect GND to Ground
// Connect SCL to i2c clock - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 5
// Connect SDA to i2c data - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 4
// EOC is not used, it signifies an end of conversion
// XCLR is a reset pin, also not used here

Adafruit_BMP085 bmp;
  
void setup() {
  Serial.begin(9600);
  if (!bmp.begin()) {
	Serial.println("Could not find a valid BMP085 sensor, check wiring!");
	while (1) {}
  }
}
  
void loop() {
    Serial.print("Temperature = ");
    Serial.print(bmp.readTemperature()* 1.8 + 32);
    Serial.println(" *F");
    
   

    Serial.println();
    delay(500);
}

How are you powering your fan? You can't drive it directly from the Uno.

The idea of the demo code you copied, is to print the reading of a BMP085.

AA Batteries

I guess what I am asking is how do I use this information as an on and off switch. I would like to print it also to know if it is working.

// you want a bit of hysteresis or you will be toggling on/off too much
const float ON_TEMP = 75.0;
const float OFF_TEMP = 72.0;

void loop() {
    Serial.print("Temperature = ");
    float temp = bmp.readTemperature()* 1.8 + 32;
    Serial.print(temp);
    Serial.println(" *F");
    
    if ( temp > ON_TEMP ) {
      // turn on fan
    }

    if ( temp < OFF_TEMP ) {
      // turn off fan
    }

     Serial.println();
    delay(500);
}

As for how you turn your fan on/off, you need to provide a schematic, not "it runs on batteries" for people to help. You would typically use a MOSFET or other transistor to get the job done.

After some more research and alot of trial and error I think I have found something that works. Please let me know if you have any suggestions.

const int hot = 75; //set hot parameter
const int cold = 70; //set cold parameter
void setup() {
  pinMode(3, OUTPUT); //motor
  Serial.begin(9600);
}
void loop() {
  int sensor = analogRead(A0);
  float voltage = (sensor / 1024.0) * 5.0;
  float tempC = (voltage - .5) * 100;
  float tempF = (tempC * 1.8) + 32;
  Serial.print("temp: ");
  Serial.print(tempF);
  if (tempF < cold) { //cold
    digitalWrite(3, LOW);
    Serial.println(" It's Cold.");
  }
  else if (tempF >= hot) { //hot
    digitalWrite(3, HIGH);
    Serial.println(" It's Hot.");
  }
    delay(10);
}

EDIT: The image is not the right one. I switched the HIGH and LOW after realizing it turned on when cold and off when hot. I have since switched this in the code above.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.