Hi
I'm fairly new to arduino and I'm struggling with my sketch. I can't seem to get it to work properly.
It seems like it's something with the if's. I can't get the arguments to work. the lcd prints the prsV, no load, heating up and the temperature. When pressure is applied the temperature rises and the lcd prints no heat .
Please help me to see if i've gotten something wrong....
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F,16,2); // set the LCD address to 0x3f for a 16 chars and 2 line display
const int temperaturePin1 = A1; //temp sensor heater
const int temperaturePin2 = A2; // temp sensor animal
const int prs_Pin = A0; // pressure sensor
const float VCC = 4.65; // Measured voltage of Ardunio 5V line
const float R_DIV = 4700; // Measured resistance of 4,7k resistor
int relayPin1 = 8; // Pin of Relay Module start heater
int relayPin2 = 7; // Pin of Relay Module coling fan
int relayPin3 = 6; // Pin of Relay Module sensor heater
int relayPin4 = 5; // Pin of Relay Module circulation
void setup()
{
pinMode(relayPin1, OUTPUT);
pinMode(relayPin2, OUTPUT);
pinMode(relayPin3, OUTPUT);
pinMode(relayPin4, OUTPUT); // Set Pin connected to Relays as an OUTPUT
pinMode(prs_Pin, INPUT); // Set Pin connected to relays as an input
digitalWrite(relayPin1,0);
digitalWrite(relayPin2,0);
digitalWrite(relayPin3,0);
digitalWrite(relayPin4,0); // Set Pin to 0 to turn Relays OFF
lcd.init(); // initialize the lcd
lcd.backlight();
}
void loop()
{
int prsADC = analogRead(prs_Pin); // If the prs has no pressure, the resistance will be near infinite. So the voltage should be near 0.
float prsV = prsADC * VCC / 1023.0; //stämmer
float voltage, degreesC1, voltage2, degreesC2;
voltage = getVoltage(temperaturePin1);
degreesC1 = ( (voltage * 100)-4 );
voltage2 = getVoltage(temperaturePin2);
degreesC2 = ((voltage2 * 100));
if (prsV < 0,03){ // If the analog reading is near zero
lcd.setCursor (5,0);
//lcd.print(prsV);
lcd.print("no load");
if (degreesC1 < 30){
digitalWrite(relayPin1, 1);
lcd.setCursor (0,1);
lcd.print("heating up ");
lcd.print(degreesC1);
lcd.setCursor (0,0);
lcd.print(prsV);
}
else
{
digitalWrite(relayPin1, 0);
lcd.clear();
lcd.setCursor (0,1);
lcd.print("no heat");
lcd.setCursor (11,1);
lcd.print(degreesC1);
lcd.print(prsV);
}
}
else
{
lcd.clear();
lcd.setCursor (5,0);
lcd.print("load on");
//delay(1000);
if(degreesC2 < 38){
digitalWrite(relayPin1, 1);
lcd.setCursor (0,0);
lcd.print("heating ");
lcd.print(degreesC2);
}
else if(degreesC2 < 40){
//digitalWrite(relayPin1, 0);
// digitalWrite(relayPin2,1);
lcd.setCursor (1,0);
lcd.print("circulation");
}
else
{
digitalWrite(relayPin1, 0);
digitalWrite(relayPin2, 0);
digitalWrite(relayPin3, 1);
lcd.setCursor (1,1);
lcd.print("cooling");
}
}
delay (1000);
}
float getVoltage(int pin)
{
return (analogRead(pin) * 0.004882814);
}
Thanks!