Hello, please take a look at the sketch below. We sued the first one to test connections and see if it drives our fan. And it worked fine.
int fanPin = 9; // Fan pin
void setup() {
// nothing happens in setup
}
void loop() {
int fadeValue =0 ;
analogWrite(fanPin, fadeValue);
// wait for 3000 milliseconds to see the fade effect
delay(30000);
fadeValue =255 ;
analogWrite(fanPin, fadeValue);
// wait for 3000 milliseconds to see the fade effect
delay(30000);
The first file we used just to test if everything is working , and fan went on and off. It has separate voltage supply. The larger document is the program that needs fixing. It compiles no problem, both temperature sensors work. It displays temperature: 1st line is peltier, 2nd line is heatsink. Then clears and displays "Fan OFF", then goes back to displaying temperature. Fan doesn't go on no matter how much temperature difference we set. We think that it is something with not reading temperature in the format suitable to use in our IF statement.
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
#include <math.h>
#define ONE_WIRE_BUS 2 // Data wire is plugged into pin 3 on the Arduino
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
// LCD Define
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); //Pins used on the LCD for our Arduino Uno
// Temperature Sensor Addresses
DeviceAddress PeltierTemp = { 0x28, 0x08, 0xC9, 0x5B, 0x04, 0x00, 0x00, 0xBC };
DeviceAddress HeatSinkTemp = { 0x28, 0x4C, 0x0D, 0x5B, 0x04, 0x00, 0x00, 0x28 };
const int fanPin = 9; // Fan connected to digital pin 9
int TemperatureDifference;
void setup(void)
{
// initialize serial communications at 9600 bps (serial port)
Serial.begin(9600);
delay(1000);
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(PeltierTemp, 10);
sensors.setResolution(HeatSinkTemp, 10);
}
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
lcd.print("Error");
} else {
lcd.print("F)");
lcd.print(DallasTemperature::toFahrenheit(tempC));
}
}
void loop()
{
lcd.clear();
sensors.requestTemperatures();
lcd.begin(16, 2); //Number of columns/rows in LCD screen
lcd.print("Peltier("); //Prints Device Temperature on LCD
printTemperature(PeltierTemp);
lcd.setCursor(0, 1); //New line of the LCD display
lcd.print("HeatSink(");
printTemperature(HeatSinkTemp);
delay (5000);
lcd.clear();
TemperatureDifference = PeltierTemp - HeatSinkTemp;
int fanSpeed;
if (TemperatureDifference <= 5) {
fanSpeed=255;
analogWrite(fanPin, fanSpeed);
lcd.begin(16, 2);
lcd.print("Fan Off");
delay (500);
}
else {
fanSpeed=255;
analogWrite(fanPin, fanSpeed);
lcd.clear();
lcd.begin(16, 2);
lcd.print("Fan Speed 100%");
delay (500);
}
delay(5000);
}
Thank you so much for the help!