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);
}
// 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.
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.