#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int veri;
int role1 = 3;
int role2 = 4;
void setup()
{
Serial.begin(9600);
pinMode(role1, OUTPUT);
pinMode(role2, OUTPUT);
digitalWrite(role2, HIGH);
lcd.init();
lcd.backlight();
lcd.begin(16,2);
}
float sabit = 5.0044;
void loop()
{
float oku = analogRead(A0);
float ohm = oku/sabit;
float sicaklik = (ohm-100)/0.18;
{
lcd.clear();
lcd.home();
lcd.print(" sicaklik = ");
lcd.setCursor(0,1);
lcd.print(sicaklik);
lcd.print(" derece");
delay(350);
}
{
if (Serial.available())
{
veri = Serial.read();
if (sicaklik >= 60)
{
digitalWrite(role1,HIGH);
}
if (sicaklik <= 50)
{
digitalWrite(role1,LOW);
}
if (veri == '1')
{
digitalWrite(role2, LOW);
}
if (veri == '2')
{
digitalWrite(role2, HIGH);
}
{
if (veri == '3')
{
digitalWrite(role2, LOW);
delay(10000);
digitalWrite(role2, HIGH);
delay(10000);
}
if (veri == '4')
{
digitalWrite(role2, LOW);
delay(20000);
digitalWrite(role2, HIGH);
delay(20000);
}
if (veri == '5')
{
digitalWrite(role2, LOW);
delay(30000);
digitalWrite(role2, HIGH);
delay(30000);
}
}
}
}
}
you only test for if (sicaklik >= 60) when you receive serial data
try moving it before the Serial.available(), e.g.
if (sicaklik >= 60)
digitalWrite(role1,HIGH);
if (Serial.available())
{
veri = Serial.read();
okay thank you so much but when timer is open if veri4 if veri5 and if veri 3 are work tempature meausurement dont work. How i can solver this?
you have very long delays of 10, 20, 30 seconds in the code which is probably the problem
remember delay() in effect stops program execution for the specified time
consider using millis() to time events
i dont how i use millis() Can you pls help me?
simple example - if 1 is entered LED lights for 5 seconds
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
static long int timer1 = 0; // static - value is maintained from call to call
if (Serial.available())
if (Serial.read() == '1') { // if 1 entered light LED for 5 seconds
timer1 = millis();
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
}
// if timer1 is running and 5 seconds elapsed switch off LED
if (timer1 > 0 && (millis() - timer1 > 5000)) {
timer1 = 0;
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
}
}
also don't double post! you end up wasting peoples time by duplicating effort
lcd.clear();
lcd.home();
lcd.print(" sicaklik = ");
lcd.setCursor(0,1);
lcd.print(sicaklik);
lcd.print(" derece");
delay(350);
What do you hope to achieve when you do replace a delay with one made using millis()?
A lot has to do with what the rest of the code does.
The code you posted has very little to go on, it is just a delay at the end of a few lines of printing.
Do you want other code to run at the same time as the "delay" ?
See Using millis() for timing. A beginners guide, Several things at the same time and the BlinkWithoutDelay example in the IDE
i want the solve this problem in this code : when timer is open if veri4 if veri5 and if veri 3 are work tempature meausurement dont work. How i can solver this?
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int veri;
int role1 = 3;
int role2 = 4;
void setup()
{
Serial.begin(9600);
pinMode(role1, OUTPUT);
pinMode(role2, OUTPUT);
digitalWrite(role2, HIGH);
lcd.init();
lcd.backlight();
lcd.begin(16,2);
}
float sabit = 5.0044;
void loop()
{
float oku = analogRead(A0);
float ohm = oku/sabit;
float sicaklik = (ohm-100)/0.18;
lcd.clear();
lcd.home();
lcd.print(" sicaklik = ");
lcd.setCursor(0,1);
lcd.print(sicaklik);
lcd.print(" derece");
delay(350);
{
}
if (sicaklik >= 60)
{
digitalWrite(role1,HIGH);
}
if (sicaklik <= 50)
{
digitalWrite(role1,LOW);
}
{
if (Serial.available())
{
veri = Serial.read();
if (veri == '1')
{
digitalWrite(role2, LOW);
}
if (veri == '2')
{
digitalWrite(role2, HIGH);
}
{
if (veri == '3')
{
digitalWrite(role2, LOW);
delay(10000);
digitalWrite(role2, HIGH);
delay(10000);
}
if (veri == '4')
{
digitalWrite(role2, LOW);
delay(20000);
digitalWrite(role2, HIGH);
delay(20000);
}
if (veri == '5')
{
digitalWrite(role2, LOW);
delay(30000);
digitalWrite(role2, HIGH);
delay(30000);
}
}
}
}
}
Press CTRL-T in your Arduino IDE and format the code.
Delete empty lines.
Repost your code.
Now open the Example "Blink without Delay" in the IDE and learn how to omit the delay.
Step 1: Instead of blinking the LED you want to update the LCD.
Step 2: remove the delays for your relay activation.
Do one step after another.
P.S.: Solve on ONE problem before you start another one.
Your two topics on the same or similar subject have been merged.
Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.
Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.
Repeated duplicate posting could result in a temporary or permanent ban from the forum.
Could you take a few moments to Learn How To Use The Forum
It will help you get the best out of the forum in the future.
Thank you.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.