I am making a project named "smart garden irrigation system" in which i am using a soil moisture sensor if the soil is dry it will switch a water pump (working at 220V ac ) via a 5v relay and displays all the condition of soil and the status of pump on 16x2 LCD but sometimes after working fine lcd start showing garbage values and sometimes relay get triggered before the set elay time.How can i fix this problem ?.
I am attaching the copy of code.
[code]
#include<LiquidCrystal.h>
LiquidCrystal lcd(7,8,9,10,11,12);
const int relayPin = 5;
const int sensorPin = 0;
void setup() {
// put your setup code here, to run once:
lcd.begin(16,2);
pinMode(relayPin,OUTPUT);
lcd.print("Smart Garden Ir-");
lcd.setCursor(0,1);
lcd.print("rigation System");
delay(1000);
}
void loop() {
// put your main code here, to run repeatedly:
int sensorReading = sensorValue();
if(sensorReading < 700 && sensorReading > 100)
{
lcd.clear();
delay(100);
digitalWrite(relayPin,HIGH);
lcd.print("Condition: Dry ");
lcd.setCursor(0,1);
lcd.print("Watering Plants.");
delay(5000);
lcd.clear();
delay(100);
digitalWrite(relayPin,LOW);
lcd.print("Smart Garden Ir-");
lcd.setCursor(0,1);
lcd.print("rigation System");
delay(5000);
sensorReading = sensorValue();
}
else if(sensorReading>=700)
{
lcd.clear();
lcd.print("Condition: Wet");
delay(5000);
lcd.clear();
lcd.print("Smart Garden Ir-");
lcd.setCursor(0,1);
lcd.print("rigation System");
delay(5000);
sensorReading = sensorValue();
}
else if(sensorReading < 100)
{
lcd.print("Smart Garden Ir-");
lcd.setCursor(0,1);
lcd.print("rigation System");
delay(5000);
sensorReading = sensorValue();
}
}
int sensorValue()
{
int sensorReading = analogRead(sensorPin);
return sensorReading;
}
I am making a project named "smart garden irrigation system" in which i am using a soil moisture sensor if the soil is dry it will switch a water pump (working at 220V ac ) via a 5v relay and displays all the condition of soil and the status of pump on 16x2 LCD but sometimes after working fine lcd start showing garbage values and sometimes relay get triggered before the set elay time.How can i fix this problem ?.
I am attaching the copy of code
[code]
#include<LiquidCrystal.h>
LiquidCrystal lcd(7,8,9,10,11,12);
const int relayPin = 5;
const int sensorPin = 0;
void setup() {
// put your setup code here, to run once:
lcd.begin(16,2);
pinMode(relayPin,OUTPUT);
lcd.print("Smart Garden Ir-");
lcd.setCursor(0,1);
lcd.print("rigation System");
delay(1000);
}
void loop() {
// put your main code here, to run repeatedly:
int sensorReading = sensorValue();
if(sensorReading < 700 && sensorReading > 100)
{
lcd.clear();
delay(100);
digitalWrite(relayPin,HIGH);
lcd.print("Condition: Dry ");
lcd.setCursor(0,1);
lcd.print("Watering Plants.");
delay(5000);
lcd.clear();
delay(100);
digitalWrite(relayPin,LOW);
lcd.print("Smart Garden Ir-");
lcd.setCursor(0,1);
lcd.print("rigation System");
delay(5000);
sensorReading = sensorValue();
}
else if(sensorReading>=700)
{
lcd.clear();
lcd.print("Condition: Wet");
delay(5000);
lcd.clear();
lcd.print("Smart Garden Ir-");
lcd.setCursor(0,1);
lcd.print("rigation System");
delay(5000);
sensorReading = sensorValue();
}
else if(sensorReading < 100)
{
lcd.print("Smart Garden Ir-");
lcd.setCursor(0,1);
lcd.print("rigation System");
delay(5000);
sensorReading = sensorValue();
}
}
int sensorValue()
{
int sensorReading = analogRead(sensorPin);
return sensorReading;
}
Your problem stems from the relay and/or the motor. You can verify this by temporarily substituting an LED (with current limiting resistor) for the relay coil at the output pin of your Arduino.
Use the stealth search box at the upper right and look for terms such as 'LED garbage', 'LED weird', etc. There are lots of previous threads about this, typically dealing with the power.
PaulRB:
I don't think the problem is in your code, I think it is in your circuit. Please post a schematic.
Yes i also think probkem is somewhere in hardware.I red at various places this problem is Electro magnetic interference of relay or something like that and many people were telling many things to fix that i tried but nothing worked out.I will try to post schematics.
Your problem stems from the relay and/or the motor. You can verify this by temporarily substituting an LED (with current limiting resistor) for the relay coil at the output pin of your Arduino.
Use the stealth search box at the upper right and look for terms such as 'LED garbage', 'LED weird', etc. There are lots of previous threads about this, typically dealing with the power.
Don
Problem roots are in relay as i tried to switch relay while not switching ac everything on lcd is fine only when i switch ac from relay lcd start showing garbage values and sometimes the system would stop and other time it would work fine.I then searched at google and found out it is sonething electro magnetic interference and tried other people ways of dealing it bit nothing worked out.
Use the stealth search box at the upper right and look for terms such as 'LED garbage', 'LED weird', etc.
I think Don meant LCD where he wrote LED.
Switching mains AC voltage is not my area of expertise, perhaps someone more expert can offer advice. But maybe suppressor capacitors on the motor and perhaps the relay contacts might help, and inductors are also useful for suppressing unwanted interference.
Switching mains AC voltage is not my area of expertise, perhaps someone more expert can offer advice. But maybe suppressor capacitors on the motor and perhaps the relay contacts might help, and inductors are also useful for suppressing unwanted interference.
You mean across relay? And what value of capacitor shall i use?
Yes I did. I had recently worked on another thread involving a backlight and had LED on my brain.
Maybe you should ask the moderators to move this thread to the "Motors & Power" forum section.
I think this forum is appropriate. Even though the relay and/or the motor could be the cause it is the LCD controller that is susceptible and is being affected.
The description sound more like a hardware than a software problem. Post a wiring diagram. I guess either the flyback diode on the relay is missing or the power supply isn't robust enough to feed both, the Arduino and the relay.