Fan Controller And Liquid Crystal

Hello, I am Some what New to Coding and i am taking on a somewhat new project for me. I am Building a power supply and i am making a Arduino Fan controller for it. I would like For the 16x2 display To show something like this (Look at The Image Hard to explain)

But I Just don't know how to do the code, so can someone help me. The original code was found on this website http://www.electroschematics.com/9540/arduino-fan-speed-controlled-temperature/ But i modified everything for my needs current the LCD Please Help Here is my current code

[code]
// PWM and Speed Control for Power Supply Project

#include <LiquidCrystal.h>
LiquidCrystal lcd(7,6,5,4,3,2);
int tempPin1 = A1;   // the output pin of LM35
int tempPin2 = A2;   // the output pin of LM35
int tempPin3 = A3;   // the output pin of LM35
int tempPin4 = A4;   // the output pin of LM35
int tempPin5 = A5;   // the output pin of LM35
int fan1 = 11;       // the pin where fan is
int fan2 = 12;       // the pin where fan is
int fan3 = 13;       // the pin where fan is
int relay1 =14;      // The pin where the relay is 
int relay2 =15;      //The pin where the relay is 
int relay3 =16;      //The pin where the relay is
int relay4 =9;      //The pin where the relay is 
int led = 8;        // led pin
int temp1;
int temp2;
int temp3;
int temp4;
int temp5;
int tempMin = 30;   // the temperature to start the fan & First Relay stage
int tempMax = 70;   // the maximum temperature when fan is at 100
int temprelay = 50; // Tempture second relay stage starts.
int fanSpeed;
int fanLCD;
int readTemp1() {  // get the temperature and convert it to celsius
  temp1 = analogRead(tempPin1);
  return temp1 * 0.48828125; }
int readTemp2() {  // get the temperature and convert it to celsius
  temp2 = analogRead(tempPin2);
  return temp2 * 0.48828125; }
int readTemp3() {  // get the temperature and convert it to celsius
  temp3 = analogRead(tempPin3);
  return temp3 * 0.48828125; } 
int readTemp4() {  // get the temperature and convert it to celsius
  temp4 = analogRead(tempPin4);
  return temp4 * 0.48828125; }
int readTemp5() {  // get the temperature and convert it to celsius
  temp5 = analogRead(tempPin5);
  return temp5 * 0.48828125; }
  
void setup() {
  pinMode(fan1, OUTPUT);
  pinMode(fan2, OUTPUT);
  pinMode(fan3, OUTPUT);
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(relay4, OUTPUT);
  pinMode(led, OUTPUT);
  pinMode(tempPin1, INPUT);
  pinMode(tempPin2, INPUT);
  pinMode(tempPin3, INPUT);
  pinMode(tempPin4, INPUT);
  pinMode(tempPin5, INPUT);
  lcd.begin(16,2);  
}
 
void loop() {                // Fan 1-3 Temp sensor 3-5
   temp3 = readTemp3();     // get the temperature
   if(temp3 < tempMin) {   // if temp is lower than minimum temp
       fanSpeed = 0;      // fan is not spinning
       digitalWrite(fan1, LOW);       
   } 
   if((temp3 >= tempMin) && (temp3 <= tempMax)) {  // if temperature is higher than minimum temp
       fanSpeed = map(temp3, tempMin, tempMax, 32, 255); // the actual speed of fan
       fanLCD = map(temp3, tempMin, tempMax, 0, 100);  // speed of fan to display on LCD
       analogWrite(fan1, fanSpeed);  // spin the fan at the fanSpeed speed
   } 
   temp4 = readTemp4();     // get the temperature
   if(temp4 < tempMin) {   // if temp is lower than minimum temp
       fanSpeed = 0;      // fan is not spinning
       digitalWrite(fan2, LOW);       
   } 
   if((temp4 >= tempMin) && (temp4 <= tempMax)) {  // if temperature is higher than minimum temp
       fanSpeed = map(temp4, tempMin, tempMax, 32, 255); // the actual speed of fan
       fanLCD = map(temp4, tempMin, tempMax, 0, 100);  // speed of fan to display on LCD
       analogWrite(fan2, fanSpeed);  // spin the fan at the fanSpeed speed
   } 
   temp5 = readTemp5();     // get the temperature
   if(temp5 < tempMin) {   // if temp is lower than minimum temp
       fanSpeed = 0;      // fan is not spinning
       digitalWrite(fan3, LOW);       
   } 
   if((temp5 >= tempMin) && (temp5 <= tempMax)) {  // if temperature is higher than minimum temp
       fanSpeed = map(temp5, tempMin, tempMax, 32, 255); // the actual speed of fan
       fanLCD = map(temp5, tempMin, tempMax, 0, 100);  // speed of fan to display on LCD
       analogWrite(fan3, fanSpeed);  // spin the fan at the fanSpeed speed
   } 
   temp1 = readTemp1();     // get the temperature
   if(temp1 < tempMin) {   // if temp is lower than minimum temp
       digitalWrite(relay1, LOW);       
   } 
   if((temp1 >= tempMin) && (temp1 < temprelay)) {   // if temp is Greater than minimum temp but lower then relay temp
       digitalWrite(relay1, HIGH);  // Turn Realy One On     
   } 
   if(temp1 >= temprelay) {       // If Temp 1 Is equal or greater then Temp Realy 
     digitalWrite(relay1, LOW);   // Turn Relay 1 Off
     delay (200);                 // Delay
     digitalWrite(relay2, HIGH);  // Turn Relay 2 on 
   }
    temp2 = readTemp2();     // get the temperature
   if(temp2 < tempMin) {   // if temp is lower than minimum temp
       digitalWrite(relay3, LOW);       
   } 
   if((temp2 >= tempMin) && (temp2 < temprelay)) {   // if temp is Greater than minimum temp but lower then relay temp
       digitalWrite(relay3, HIGH);  // Turn Realy Three On     
   } 
   if(temp3 >= temprelay) {       // If Temp 3 Is equal or greater then Temp Realy 
     digitalWrite(relay3, LOW);   // Turn Relay 3 Off
     delay (200);                 // Delay
     digitalWrite(relay4, HIGH);  // Turn Relay 4 on 
   }
     
   
   if(temp1,temp2,temp3,temp4,temp5 > tempMax) {        // if temp is higher than tempMax
     digitalWrite(led, HIGH);  // turn on led 
   } else {                    // else turn of led
     digitalWrite(led, LOW); 
   }
   
   lcd.print("TEMP: ");
   lcd.print(temp1);      // display the temperature
   lcd.print("C ");
   lcd.setCursor(0,1);   // move cursor to next line
   lcd.print("FANS: ");
   lcd.print(fanLCD);    // display the fan speed
   lcd.print("%");
   delay(200);
   lcd.clear();   
}

[/code]

Please explain what the code that you posted is not doing that you want it to do.

My code Doesnt Display The Different Temperatures ( temp1 - temp5) and it doesnt Display the Active relays and fan speeds, Nor does it switch to the different screens like i want it to do as i showed in the picture. Besides that i believe the code works I just dont know how to program the LCD

HI,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

I see you have an output for each relay and an output for each fan.

How many fans?

Hope to help....Tom..... :slight_smile:

The circuit it self inst built yet so here is the best i could do to try to help you under stand. There are 3 12v fans those are the fans running off of the pwm. There are also two 120v ac fans. Those are the fans running off of the relay. There are two relays per fan to create a "Two speed Fan" Only one relay is powered at a time per AC fan. When the temperature increases to a certain point Relay one will stop and relay two will start and the fan will then receive its power from relay two. Here is a simple Hand drawn schematic. With out the LCD

liljoey112:
My code Doesnt Display The Different Temperatures ( temp1 - temp5) and it doesnt Display the Active relays and fan speeds, Nor does it switch to the different screens like i want it to do as i showed in the picture. Besides that i believe the code works I just dont know how to program the LCD

You will have to add a simple state machine to cycle through your screens.

Something along the lines of:

unsigned long lastMillis;
byte currentScreen;
unsigned int screenChangeTime = 5000;
const byte NUMBER_OF_SCREENS = 3;

void loop()
{
   ... existing sensor code

   if (millis() - lastMillis > screenChangeTime)
   {
        switch (currentScreen)
        {
              case 0:
                  // display first screen on LCD here
                  break;
              case 1:
                  // display second screen on LCD here
                  break;
              case 2:
                  // display third screen on LCD here
                  break;
        }

        currentScreen = (currentScreen + 1) % NUMBER_OF_SCREENS;
        lastMillis = millis();
   }
}

Also, look at millis() and at some point, you may want to replace your calls to delay() with the use of millis(), otherwise your screens will not consistently change at the right time. Not a big issue for now though.

To learn more about programming the LCD itself, see:https://www.arduino.cc/en/Tutorial/LiquidCrystal

Hi,
You have the AC 120V fans connected to gnd and to the box you have drawn, not possible to read what the box has written in it.

If are you slowing down the AC fans how?
Or are you, by two speed mean one fan ON, low speed, both fans ON, full speed.

You need to get your AC circuit sorted out.

Tom.... :slight_smile:

I am sorry I guess it wasn't clear here is a new picture of the relay/fan circuit. So basically the 3.3uf capacitor acts a resistor with out generating heat so that is how the fan is speed controlled. So relay A and relay B control AC fan 1 and Relay C and Relay D control AC fan 2. Once Temperature Min is reached Relay A and Relay C turn on. They connect to the AC fan but they have a 3.3uf 250v capacitor in line. Once temprelay is reached Relay A and Relay C turn off delay 200ms and Relay B and Relay D Turn on these are also connected to the The fan but this time there is no Capacitor so it Runs at full speed

As I am a pedant, please note that an AC fan does not have "+" and "-", these are for DC only.

I assume you meant "A" (active) and "N" (neutral).

You are using a relay shield so please be very careful with the mains connection. Remember that the terminals are connected to the PCB trace so while it looks safe on top, you have live parts of your shield underneath. Treat it as live unless you have the power plug in your hand.

Weedpharma

I am aware thank you, I just didnt want to use any extra letters for less confusion. But would you be able to help me with the code?

liljoey112:
I am aware thank you, I just didnt want to use any extra letters for less confusion. But would you be able to help me with the code?

This forum is to guide you and help you learn. You need to take what we have said, and try to write the code yourself. Then, post the code as you have it, and we will guide you again. If we write it for you, you don't learn anything.

So, try to get the next bit working, then post that code and ask questions about it.

Okay i did the code :slight_smile: But I didnt understand the simple State machine so i did something else that should logically work here it is
```
**// PWM and Speed Control for Power Supply Project

#include <LiquidCrystal.h>
LiquidCrystal lcd(7,6,5,4,3,2);
int tempPin1 = A1;  // the output pin of LM35
int tempPin2 = A2;  // the output pin of LM35
int tempPin3 = A3;  // the output pin of LM35
int tempPin4 = A4;  // the output pin of LM35
int tempPin5 = A5;  // the output pin of LM35
int fan1 = 11;      // the pin where fan is
int fan2 = 12;      // the pin where fan is
int fan3 = 13;      // the pin where fan is
int relay1 =14;      // The pin where the relay is
int relay2 =15;      // The pin where the relay is
int relay3 =16;      // The pin where the relay is
int relay4 =9;      // The pin where the relay is
int led = 8;        // led pin
int temp1;
int temp2;
int temp3;
int temp4;
int temp5;
int tempMin = 30;  // the temperature to start the fan & First Relay stage
int tempMax = 70;  // the maximum temperature when fan is at 100
int temprelay = 50; // Tempture second relay stage starts.
int fanSpeed;
int fanLCD1;
int fanLCD2;
int fanLCD3;
int readTemp1() {  // get the temperature and convert it to celsius
  temp1 = analogRead(tempPin1);
  return temp1 * 0.48828125; }
int readTemp2() {  // get the temperature and convert it to celsius
  temp2 = analogRead(tempPin2);
  return temp2 * 0.48828125; }
int readTemp3() {  // get the temperature and convert it to celsius
  temp3 = analogRead(tempPin3);
  return temp3 * 0.48828125; }
int readTemp4() {  // get the temperature and convert it to celsius
  temp4 = analogRead(tempPin4);
  return temp4 * 0.48828125; }
int readTemp5() {  // get the temperature and convert it to celsius
  temp5 = analogRead(tempPin5);
  return temp5 * 0.48828125; }
  
void setup() {
  pinMode(fan1, OUTPUT);
  pinMode(fan2, OUTPUT);
  pinMode(fan3, OUTPUT);
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(relay4, OUTPUT);
  pinMode(led, OUTPUT);
  pinMode(tempPin1, INPUT);
  pinMode(tempPin2, INPUT);
  pinMode(tempPin3, INPUT);
  pinMode(tempPin4, INPUT);
  pinMode(tempPin5, INPUT);
  lcd.begin(16,2); 
}
 
void loop() {                // Fan 1-3 Temp sensor 3-5
   temp3 = readTemp3();     // get the temperature
   if(temp3 < tempMin) {  // if temp is lower than minimum temp
       fanSpeed = 0;      // fan is not spinning
       digitalWrite(fan1, LOW);     
   } 
   if((temp3 >= tempMin) && (temp3 <= tempMax)) {  // if temperature is higher than minimum temp
       fanSpeed = map(temp3, tempMin, tempMax, 32, 255); // the actual speed of fan
       fanLCD1 = map(temp3, tempMin, tempMax, 0, 100);  // speed of fan to display on LCD
       analogWrite(fan1, fanSpeed);  // spin the fan at the fanSpeed speed
   } 
   temp4 = readTemp4();     // get the temperature
   if(temp4 < tempMin) {  // if temp is lower than minimum temp
       fanSpeed = 0;      // fan is not spinning
       digitalWrite(fan2, LOW);     
   } 
   if((temp4 >= tempMin) && (temp4 <= tempMax)) {  // if temperature is higher than minimum temp
       fanSpeed = map(temp4, tempMin, tempMax, 32, 255); // the actual speed of fan
       fanLCD2 = map(temp4, tempMin, tempMax, 0, 100);  // speed of fan to display on LCD
       analogWrite(fan2, fanSpeed);  // spin the fan at the fanSpeed speed
   } 
   temp5 = readTemp5();     // get the temperature
   if(temp5 < tempMin) {  // if temp is lower than minimum temp
       fanSpeed = 0;      // fan is not spinning
       digitalWrite(fan3, LOW);     
   } 
   if((temp5 >= tempMin) && (temp5 <= tempMax)) {  // if temperature is higher than minimum temp
       fanSpeed = map(temp5, tempMin, tempMax, 32, 255); // the actual speed of fan
       fanLCD3 = map(temp5, tempMin, tempMax, 0, 100);  // speed of fan to display on LCD
       analogWrite(fan3, fanSpeed);  // spin the fan at the fanSpeed speed
   } 
   temp1 = readTemp1();     // get the temperature
   if(temp1 < tempMin) {  // if temp is lower than minimum temp
       digitalWrite(relay1, LOW);     
   } 
   if((temp1 >= tempMin) && (temp1 < temprelay)) {  // if temp is Greater than minimum temp but lower then relay temp
       digitalWrite(relay1, HIGH);  // Turn Realy One On   
   } 
   if(temp1 >= temprelay) {      // If Temp 1 Is equal or greater then Temp Realy
     digitalWrite(relay1, LOW);  // Turn Relay 1 Off
     delay (200);                // Delay
     digitalWrite(relay2, HIGH);  // Turn Relay 2 on
   }
    temp2 = readTemp2();     // get the temperature
   if(temp2 < tempMin) {  // if temp is lower than minimum temp
       digitalWrite(relay3, LOW);     
   } 
   if((temp2 >= tempMin) && (temp2 < temprelay)) {  // if temp is Greater than minimum temp but lower then relay temp
       digitalWrite(relay3, HIGH);  // Turn Realy Three On   
   } 
   if(temp3 >= temprelay) {      // If Temp 3 Is equal or greater then Temp Realy
     digitalWrite(relay3, LOW);  // Turn Relay 3 Off
     delay (200);                // Delay
     digitalWrite(relay4, HIGH);  // Turn Relay 4 on
   }
     
   
   if(temp1,temp2,temp3,temp4,temp5 > tempMax) {        // if temp is higher than tempMax
     digitalWrite(led, HIGH);  // turn on led
   } else {                    // else turn of led
     digitalWrite(led, LOW);
   }
   
   lcd.print("Temp1:");
   lcd.print(temp1);      // display the temperature
   lcd.print("C ");
   lcd.setCursor(9,0);    // Move the Cursor
   lcd.print("Temp2:");
   lcd.print(temp2);    // display the tempture
   lcd.print("C");
   lcd.setCursor(0,1);  // move cursor to next line
   lcd.print("Temp3:");
   lcd.print(temp3);    // display the tempture
   lcd.print("C");
   lcd.setCursor(9,1);    // Move the Cursor
   lcd.print("Temp4:");
   lcd.print(temp4);    // display the tempture
   lcd.print("C");
   delay(10000);
   lcd.clear();
   lcd.print("Temp5:");
   lcd.print(temp5);    //Display the Temp
   lcd.print("C");
   delay(5000);
   lcd.clear();
   if(relay1 == LOW, relay2 == LOW);{
     lcd.print("Fan Off"); }
   if(relay1 == HIGH, relay2 == LOW);{
     lcd.print("Fan Low"); }
   if(relay1 == LOW, relay2 == HIGH);{
     lcd.print("Fan High"); }
   lcd.setCursor(9,0);    // Move the Cursor
   if(relay3 == LOW, relay4 == LOW);{
     lcd.print("Fan Off"); }
   if(relay3 == HIGH, relay3 == LOW);{
     lcd.print("Fan Low"); }
   if(relay3 == LOW, relay4 == HIGH);{
     lcd.print("Fan High"); }
   lcd.setCursor(0,1);  // move cursor to next line
   lcd.print("Fan1:");
   lcd.print(fanLCD1);    // display the fan speed
   lcd.print("%");
   lcd.setCursor(1,9);  // move cursor to next line
   lcd.print("Fan2:");
   lcd.print(fanLCD2);    // display the fan speed
   lcd.print("%");
   delay(8000);
   lcd.clear();
   lcd.print("Fan3:");
   lcd.print(fanLCD3);    // display the fan speed
   lcd.print("%");
   delay(5000);
   lcd.clear();
}**
```

liljoey112:
Okay i did the code :slight_smile: But I didnt understand the simple State machine so i did something else that should logically work here it is

Yes. That should work for now. Does it? If not, what does it not do that you want it to do?

I dont have the parts yet, there still in the mail. So i cant test it just yet. But as soon as it comes ill let you know :slight_smile: but from a visual perspective everything is okay?

liljoey112:
I dont have the parts yet, there still in the mail. So i cant test it just yet. But as soon as it comes ill let you know :slight_smile: but from a visual perspective everything is okay?

Quick glance, things looks basically workable. But, you won't know for sure until you run it.

In the meantime, you really should look at how to use millis() while waiting for your parts to arrive. Delay() stops everything for the period you specify, so you can't collect results, or doing anything else.

Let us know when you've tried it all out.