Hello. I have arduino uno connected to lcd, reset button, motor driver uln 2003 with external power and relay. When relay is turned on or off arduino resets (sometimes).. on relay i have connected dimmer and 230v light bulb. I dont know what could be wrong so i am asking for a little help.
You didn't post any diagram.
...and you posted in completely the wrong sub forum.
@lziga55 - your topic moved to a more appropriate place.
That's typical for a missing kick back diode on inductive loads.
Post schematics. Using pen and paper surely does well.
From the data provided the OP has a power issue, mark the issue as resolved and move on or provide more useful info so that someone may get to the actual faulty thingy. An image of the project wiring. A schematic. Code posted in code tags.
so there is a screenshot i hope its ok.. i will send the code too i just have so translate some names in it.. and i also used 3.3k ohm resistor instead of potentiometer.. 230 V is AC, arduino is connected to 12V 2A
i forgot to add the fan in circuit. it is connected to uln 2003 5v supply
Is that an opto-isolated relay module or is the Uno directly driving the relay's coil?
If the relay is driving the coil, look up how much current a Uno can supply from its GPIO pins vs the relay's coil current requirement.
Relay looks like that in the photo.. it has resistors, leds... i dont realy know but i think its an opto-isolated relay module.
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int val;
int lightbulb = 7;
int sec = 45;
int min = 59;
int i=0;
#define A 8
#define B 9
#define C 10
#define D 13
#define NUMBER_OF_STEPS_PER_REV 2048
#include <Adafruit_Sensor.h>
#include <DHT.h>
#define DHTPIN 6
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht = DHT(DHTPIN, DHTTYPE);
int chk;
byte tem[8] = //thermometer
{
B00100,
B01010,
B01010,
B01110,
B01110,
B11111,
B11111,
B01110
};
byte drop[8] = //droplet
{
B00100,
B00100,
B01010,
B01010,
B10001,
B10001,
B10001,
B01110,
};
byte bulb[8] = //light bulb
{
B01110,
B10001,
B10001,
B10001,
B01110,
B01110,
B01110,
B00000
};
byte degree[8] = //degree
{
B01100,
B10010,
B10010,
B01100,
B00000,
B00000,
B00000,
B00000
};
byte Motor[8] = //motor
{
B00010,
B11111,
B00010,
B00000,
B10001,
B11011,
B10101,
B10001
};
void setup() {
Serial.begin(9600);
lcd.begin(16,2);
lcd.createChar(1,tem);
lcd.createChar(2,drop);
lcd.createChar(3,bulb);
lcd.createChar(4,degree);
lcd.createChar(5,Motor);
pinMode(A,OUTPUT);
pinMode(B,OUTPUT);
pinMode(C,OUTPUT);
pinMode(D,OUTPUT);
dht.begin();
delay(2000);
}
void write(int a,int b,int c,int d){
digitalWrite(A,a);
digitalWrite(B,b);
digitalWrite(C,c);
digitalWrite(D,d);
}
void onestep(){
write(1,1,0,0);
delay(2);
write(0,1,0,0);
delay(2);
write(0,1,1,0);
delay(2);
write(0,0,1,0);
delay(2);
write(0,0,1,1);
delay(2);
write(0,0,0,1);
delay(2);
write(1,0,0,1);
delay(2);
write(1,0,0,0);
delay(2);
write(0,0,0,0);
}
void loop() {
// Read the humidity in %:
float h = dht.readHumidity();
// Read the temperature as Celsius:
float t = dht.readTemperature();
// Read the temperature as Fahrenheit:
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again):
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Compute heat index in Fahrenheit (default):
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius:
float hic = dht.computeHeatIndex(t, h, false);
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" % ");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" \xC2\xB0");
Serial.print("C | ");
Serial.print(f);
Serial.print(" \xC2\xB0");
Serial.print("F ");
Serial.print("Heat index: ");
Serial.print(hic);
Serial.print(" \xC2\xB0");
Serial.print("C | ");
Serial.print(hif);
Serial.print(" \xC2\xB0");
Serial.println("F");
lcd.setCursor(2,0);
lcd.print(t);
lcd.write(4);
lcd.print("C");
lcd.print(" ");
lcd.setCursor(0,0);
lcd.write(1);
lcd.setCursor(2,1);
lcd.print(h);
lcd.print("%");
lcd.print(" ");
lcd.setCursor(0,1);
lcd.write(2);
if(t<37.5){
analogWrite(lightbulb,0);
lcd.setCursor(15,0);
lcd.write(3);}
if(t>38.5){
analogWrite(lightbulb,255);
lcd.setCursor(15,0);
lcd.print(" ");
}
sec=sec+1;
delay (825);
lcd.setCursor(11,1);
if(min<10)lcd.print("0");
lcd.print(min);
lcd.print(":");
if(sec<10)lcd.print("0");
lcd.print(sec);
if(sec==59){
sec=-1;
min=min+1;
}
if(min>59){
lcd.setCursor(11,1);
lcd.print("00:00");
lcd.setCursor(13,0);
lcd.write(5);
delay(10);
while(i<NUMBER_OF_STEPS_PER_REV){
onestep();
i++;
}
if(min>59){
min=0;}
if(i=2048){ i=0;}
}
lcd.setCursor(13,0);
lcd.print(" ");
}
Do you maybe know can i connect relay (5v and gnd) to external power supply?
I just checked and now its working fine for almost 2h. Problem somethimes come after few minutes and somethimes after few hours..
And the relay turns on and off approximately every 25 min.
That relay doesn't look opto-isolated. You might try giving it separate power. Connect the ground to the Arduino though.
sounds like you are powering everything from arduino…oh wait you do
The relay module pictured does not look like it is an opto-isolated relay. Make note of the relay's coil current requirements and compare to the ability of the MCU to supply current on its GPIO pins.
No, i am not.. just relay and lcd and stepper motor driver pins for steps..
And what current all those things require?
No, but it does look like it has a transistor and a diode, so the problem is probably not the GPIO signal current but the coil power curretn.
So advices to power the relay module directly with 5 volts, not through the Arduino, should improve things.
a7