floresta:
Let’s see a new photo. Pull out a little further so we can follow the wires and see the display.
Don
Thank you, I got it working by wiring it through the main smaller breadboard somehow!!
Im running through a few problems though:
- The LCD sometimes just stops displaying proper text and displays random gibberish and question marks etc…
plugging off the power or re-uploading the code seems to fix it, but it happens randomly. So it is not very reliable. I even tried another LCD.
this is my code:
#include <LiquidCrystal.h>
#define aref_voltage 3.3
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int tempPin = 1;
int tempReading;
int ledPin = 13;
int fan = 11;
int tempMin = 21;
int tempMax = 24;
int fanSpeed;
int fanLCD;
int photocellPin = 0;
int photocellReading;
void setup()
{
Serial.begin(9600);
analogReference(EXTERNAL);
pinMode(ledPin, OUTPUT);
pinMode(fan, OUTPUT);
pinMode(9, OUTPUT);
lcd.begin(16, 2);
lcd.clear();
}
void loop()
{
photocellReading = analogRead(photocellPin);
Serial.print("Analog reading = ");
Serial.println(photocellReading);
lcd.setCursor(0, 0);
//getting the voltage reading from the temperature sensor
tempReading = analogRead(tempPin);
// converting that reading to voltage, which is based off the reference voltage
float voltage = tempReading * aref_voltage;
voltage /= 1024.0;
// now print out the temperature
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
Serial.print(temperatureC); Serial.println(" degrees C"); //to degrees ((volatge - 500mV) times 100)
// now convert to Fahrenheight
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
Serial.print(temperatureF); Serial.println(" degrees F");
if((temperatureC < tempMin) && (photocellReading > 300)) {
fanSpeed = 0;
digitalWrite(fan, LOW);
digitalWrite(ledPin, LOW);
lcd.clear();
lcd.print("TEMP: ");
lcd.print(temperatureC); // display the temperature
lcd.write(0b11011111);
lcd.write("C ");
lcd.setCursor(0, 1); // move cursor to next line
lcd.print("FANS: OFF ");
}
if ((temperatureC >=tempMin) && (temperatureC <= tempMax) && (photocellReading > 300))
{
fanSpeed = map(temperatureC, tempMin, tempMax, 100, 255);
analogWrite(fan, fanSpeed);
digitalWrite(ledPin, HIGH);
fanLCD = map(temperatureC, tempMin, tempMax, 0, 100);
lcd.clear();
lcd.print("TEMP: ");
lcd.print(temperatureC); // display the temperature
lcd.write(0b11011111);
lcd.write("C ");
lcd.setCursor(0, 1); // move cursor to next line
lcd.print(“FANS: “);
lcd.print(fanLCD); // display the fan speed
lcd.print(”%”);
}
if((temperatureC > tempMax) && (photocellReading > 300))
{
digitalWrite(fan, HIGH);
analogWrite(9, 200);
delay(1500); // wait for a delayms 1000ms
analogWrite(9, 0); // 0 turns it off
delay(1500);
lcd.clear();
lcd.print("TEMP: ");
lcd.print(temperatureC); // display the temperature
lcd.write(0b11011111);
lcd.write("C ");
lcd.setCursor(0, 1); // move cursor to next line
lcd.print("FANS: MAX ");
}
if (photocellReading <= 300)
{
digitalWrite(fan, LOW);
digitalWrite(ledPin, LOW);
lcd.clear();
lcd.print("TEMP: ");
lcd.print(temperatureC); // display the temperature
lcd.write(0b11011111);
lcd.write("C ");
lcd.setCursor(0, 1); // move cursor to next line
lcd.print(“POWER SAVING”);
}
delay(1000);
}
Adding the delay at the end makes Problem 1 less frequent.
Problem 2, nothing to do with the LCD!
- Im using a cooler master 12V PC fan and powering it with 8x 1.5V AA batteries.
problem is, the code worked on it before with the KSD882 NPN Transistor, but stopped working now and I think I might have fried the transistor.
I tried other transistors but the same thing happens, the moment I power it, it just starts running full speed no matter what.
Im wiring according to this, http://aksoapy29.comoj.com/Pages/Tutorials/Arduino%20DC%20Motor%20Controller/diagram.png