• Добро пожаловать на компьютерный форум Tehnari.ru. Здесь разбираемся с проблемами ПК и ноутбуков: Windows, драйверы, «железо», сборка и апгрейд, софт и безопасность. Форум работает много лет, сейчас он переехал на новый движок, но старые темы и аккаунты мы постарались сохранить максимально аккуратно.

    Форум не связан с магазинами и сервисами – мы ничего не продаём и не даём «рекламу под видом совета». Отвечают обычные участники и модераторы, которые следят за порядком и качеством подсказок.

    Если вы у нас впервые, загляните на страницу о форуме и правила – там коротко описано, как задать вопрос так, чтобы быстро получить ответ. Чтобы создавать темы и писать сообщения, сначала зарегистрируйтесь, а затем войдите под своим логином.

    Не знаете, с чего начать? Создайте тему с описанием проблемы – подскажем и при необходимости перенесём её в подходящий раздел.
    Задать вопрос Новые сообщения Как правильно спросить
    Если пришли по старой ссылке со старого Tehnari.ru – вы на нужном месте, просто продолжайте обсуждение.

Arduino

MaxYanuk

Ученик
Регистрация
27 Апр 2021
Сообщения
5
Реакции
0
Баллы
0
Добрый день!
Не могу додумать некоторый элемент в схеме и в коде для ардуино.
Схема рабочая, код тоже но нужно добавить следующее:
Как-то продумать систему ЭРВ (Электронный регулирующий клапан). Т.е.
Например
Имеем температуру уставки например 19 градусов а текущую температуру 21 градус. Нужно чтоб текущая температура подстроилась под уставку (Т.е. открылся/закрылся ЭРВ) в зависимости от выбранной температуры окружающей среды. Вместо ЭРВ можно использовать светодиод, чтобы показать его работу в целом, но лучше было бы использовать осциллограф.

Алгоритм следующий:
Если текущая температура выше температуры уставки на 2 градуса - открывается ЭРВ (Тек. темп. опускается до темп. уст. и загорается светодиод, либо идет сигнал на осциллограф).
если тек. темп. ниже темп. уст. на 2 градуса - закрывается ЭРВ (т.е. тек. темп. поднимается до темп. уст.)

Как это можно реализовать на ардуино и что из себя должен представлять код?
Ниже представлю файлы которые сейчас имеются.

Спасибо заранее!
 

Вложения

MaxYanuk зачем вы усложняете другим жизнь? кому нужны ваши архивы? выкладывайте сюда свои идеи, схемы в нормальном виде и опишите как сейчас работает устройство

Код:
// written by Dylon Jamna, modified by Micah Beeler
// include the library code
#include <LiquidCrystal.h>// include the library code
int tempPin = A0;  // make variables// thermistor is at A0
int tup = 7; //Temp up button
int tdown = 9; //Temp down button
int tcf = 8; //F to C toggle
boolean far = true; //Default F to true
boolean cel = false; //Default C to false
boolean lightMe; //Light up LED
char abbrv; //Shortcut for C or F abbreviation
float temp; //Raw temp value
float settemp; //Desired temp
int defF = 65; //Default Far.
int defC = 19; //Default Cel.
int upstate = 0; //Temp up button state
int downstate = 0; //Temp down button state 
int tcfstate = 0; //C to F button state
int ledPin = 13; //LED's pin
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // lcd is at 12,11,5,4,3,2 on the breadboard

void setup() {
  Serial.begin (9600); // set the serial monitor tx and rx speed
  lcd.begin(16, 2); // set up all the "blocks" on the display
  lcd.setCursor(0, 0); // set the cursor to colum 0 row 0
  lcd.print("hello, world!"); // display hello world for 1 second
  lcd.clear(); // clear the lcd
  pinMode(tup, INPUT); //Set temp up button to input
  pinMode(tdown, INPUT); //Set temp down button to input
  pinMode(tcf, INPUT); //Set C to F button to input
  pinMode(ledPin, OUTPUT); //Set LED to output
}

void loop() {
  upstate = digitalRead(tup); //Read state of temp up
  downstate = digitalRead(tdown); //Read state of temp down
  tcfstate = digitalRead(tcf); //Read state of C to F button
  int tvalue = analogRead(tempPin);  // make tvalue what ever we read on the tempPin

  if (tcfstate == LOW) { //If the C to F button is pressed
    if (far == true) { //And Farenheit is true already
      far = false;
      cel = true; //Enable Celsius
    }
    else if (far == false) { //Otherwise if Farenheit isn't true
      far = false; //Enable Farenheit
      cel = true;
    }
  }

  if (far == true) { //If Farenheit is true
    temp = farenheit(tvalue); //Caclulate temp in F
    abbrv = 'F'; //Set label to F
  }
  if (cel == true) { //If Celsius is true
    temp = celsius(tvalue); //Calculate temp in C
    abbrv = 'C'; //Set label to C
  }

  if (upstate == LOW) { //if up button is pressed,
    defF = defF + 1; //raise desired F by 1
    defC = defC + 1; //Raise desired C by 1
  }
  if (downstate == LOW) { //if down button is pressed
    defF = defF - 1; //lower desired F by 1
    defC = defC - 1; //lower desired C by 1
  }

  lcd.setCursor(0, 0);
  lcd.print("Tek-aya ");
  lcd.print (temp);  // Print the current temp in f
  lcd.print (abbrv);
  delay(255);
  if (cel == true) {
    lcd.setCursor (0, 1); // set the cursor to 0,1
    lcd.print ("Ystavka "); // Print set to and your ideal temperature in f
    lcd.print (defC);
    lcd.print (abbrv);
  }
  if (far == true) {
    lcd.setCursor (0, 1); // set the cursor to 0,1
    lcd.print ("Desired "); // Print set to and your ideal temperature in f
    lcd.print (defF);
    lcd.print (abbrv);
  }

  lightUp(temp, defC, defF); //run custom light up command
  
  if (lightMe == true) { //if light up is true
    digitalWrite(ledPin, HIGH); //turn on LED
  } else if (lightMe == false) { //otherwise
    digitalWrite(ledPin, LOW); //turn off LED
  }
} // we're done

float farenheit(float raw) { //calculate far value
  float f; //create temporary variable F
  f = raw / 2.07; //calculate temperature from raw value
  return f; //return temperature
}

float celsius(float raw) { //calculate cel value
  float c; //create temp variable C
  c = raw / 7.1; //calculate temperature from raw value
  return c; //return temperature
}

boolean lightUp(float act, int desC, int desF) { //Decides if LED should light up, imports current temp, desired C, and desired F
  if (act < desC || act < desF) { //if the actual is less than the desired F or C value
    lightMe = true; //Turn on the LED
  } else { //otherwise
    lightMe = false; //Turn the LED off
  }
  return lightMe; //return that value
}
 
MaxYanuk зачем вы усложняете другим жизнь? кому нужны ваши архивы? выкладывайте сюда свои идеи, схемы в нормальном виде и опишите как сейчас работает устройство

Код:
// written by Dylon Jamna, modified by Micah Beeler
// include the library code
#include <LiquidCrystal.h>// include the library code
int tempPin = A0;  // make variables// thermistor is at A0
int tup = 7; //Temp up button
int tdown = 9; //Temp down button
int tcf = 8; //F to C toggle
boolean far = true; //Default F to true
boolean cel = false; //Default C to false
boolean lightMe; //Light up LED
char abbrv; //Shortcut for C or F abbreviation
float temp; //Raw temp value
float settemp; //Desired temp
int defF = 65; //Default Far.
int defC = 19; //Default Cel.
int upstate = 0; //Temp up button state
int downstate = 0; //Temp down button state 
int tcfstate = 0; //C to F button state
int ledPin = 13; //LED's pin
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // lcd is at 12,11,5,4,3,2 on the breadboard

void setup() {
  Serial.begin (9600); // set the serial monitor tx and rx speed
  lcd.begin(16, 2); // set up all the "blocks" on the display
  lcd.setCursor(0, 0); // set the cursor to colum 0 row 0
  lcd.print("hello, world!"); // display hello world for 1 second
  lcd.clear(); // clear the lcd
  pinMode(tup, INPUT); //Set temp up button to input
  pinMode(tdown, INPUT); //Set temp down button to input
  pinMode(tcf, INPUT); //Set C to F button to input
  pinMode(ledPin, OUTPUT); //Set LED to output
}

void loop() {
  upstate = digitalRead(tup); //Read state of temp up
  downstate = digitalRead(tdown); //Read state of temp down
  tcfstate = digitalRead(tcf); //Read state of C to F button
  int tvalue = analogRead(tempPin);  // make tvalue what ever we read on the tempPin

  if (tcfstate == LOW) { //If the C to F button is pressed
    if (far == true) { //And Farenheit is true already
      far = false;
      cel = true; //Enable Celsius
    }
    else if (far == false) { //Otherwise if Farenheit isn't true
      far = false; //Enable Farenheit
      cel = true;
    }
  }

  if (far == true) { //If Farenheit is true
    temp = farenheit(tvalue); //Caclulate temp in F
    abbrv = 'F'; //Set label to F
  }
  if (cel == true) { //If Celsius is true
    temp = celsius(tvalue); //Calculate temp in C
    abbrv = 'C'; //Set label to C
  }

  if (upstate == LOW) { //if up button is pressed,
    defF = defF + 1; //raise desired F by 1
    defC = defC + 1; //Raise desired C by 1
  }
  if (downstate == LOW) { //if down button is pressed
    defF = defF - 1; //lower desired F by 1
    defC = defC - 1; //lower desired C by 1
  }

  lcd.setCursor(0, 0);
  lcd.print("Tek-aya ");
  lcd.print (temp);  // Print the current temp in f
  lcd.print (abbrv);
  delay(255);
  if (cel == true) {
    lcd.setCursor (0, 1); // set the cursor to 0,1
    lcd.print ("Ystavka "); // Print set to and your ideal temperature in f
    lcd.print (defC);
    lcd.print (abbrv);
  }
  if (far == true) {
    lcd.setCursor (0, 1); // set the cursor to 0,1
    lcd.print ("Desired "); // Print set to and your ideal temperature in f
    lcd.print (defF);
    lcd.print (abbrv);
  }

  lightUp(temp, defC, defF); //run custom light up command
  
  if (lightMe == true) { //if light up is true
    digitalWrite(ledPin, HIGH); //turn on LED
  } else if (lightMe == false) { //otherwise
    digitalWrite(ledPin, LOW); //turn off LED
  }
} // we're done

float farenheit(float raw) { //calculate far value
  float f; //create temporary variable F
  f = raw / 2.07; //calculate temperature from raw value
  return f; //return temperature
}

float celsius(float raw) { //calculate cel value
  float c; //create temp variable C
  c = raw / 7.1; //calculate temperature from raw value
  return c; //return temperature
}

boolean lightUp(float act, int desC, int desF) { //Decides if LED should light up, imports current temp, desired C, and desired F
  if (act < desC || act < desF) { //if the actual is less than the desired F or C value
    lightMe = true; //Turn on the LED
  } else { //otherwise
    lightMe = false; //Turn the LED off
  }
  return lightMe; //return that value
}


Да, согласен, усложнил.
На данный момент схема работает следующим образом.
При запуске идет измерение окружающей температуры , которую можно изменять на датчике температуры (TMP) и имеется температура Уставки, которую можно изменять кнопками. При изменении температуры на датчике, происходит изменение температуры окружающей среды и на дисплее, так же отображается изменении температуры уставки.
Это все что на данный момент "Умеет" схема.
Задача следующая:
Необходимо, чтобы температура окружающей среды "подстраивалась" под температуру уставки.
(Например уставка +5 градусов, а температура окружающей среды +10, значит нужно сделать так, чтобы температура окружающей упала до температуры уставки с погрешностью +- 0.5 градуса.)
Причем нужно вот эту вод "подстройку" температур показать при помощи осциллографа. Т.е. Идет температура на "+", соответственно пошел сигнал на осциллограф и наоборот.
Это нужно реализовать и в коде.
Отсюда и мой вопрос: Как это собственно реализовать? Не могу продумать алгоритм, схему и код для поставленной задачи.
 

Вложения

  • Снимок.PNG.webp
    Снимок.PNG.webp
    32.3 KB · Просмотры: 57
На данный момент код выглядит следующим образом.
Код:
// written by Dylon Jamna, modified by Micah Beeler
// include the library code
#include <LiquidCrystal.h>// include the library code
int tempPin = A0;  // make variables// thermistor is at A0
int tup = 7; //Temp up button
int tdown = 9; //Temp down button
int tcf = 8; //F to C toggle
boolean far = true; //Default F to true
boolean cel = false; //Default C to false
boolean lightMe; //Light up LED
char abbrv; //Shortcut for C or F abbreviation
float temp; //Raw temp value
float settemp; //Desired temp
int defF = 65; //Default Far.
int defC = 5; //Default Cel.
int upstate = 0; //Temp up button state
int downstate = 0; //Temp down button state 
int tcfstate = 0; //C to F button state
int ledPin = 13; //LED's pin
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // lcd is at 12,11,5,4,3,2 on the breadboard

void setup() {
  Serial.begin (9600); // set the serial monitor tx and rx speed
  lcd.begin(16, 2); // set up all the "blocks" on the display
  lcd.setCursor(0, 0); // set the cursor to colum 0 row 0
  lcd.print("hello, world!"); // display hello world for 1 second
  lcd.clear(); // clear the lcd
  pinMode(tup, INPUT); //Set temp up button to input
  pinMode(tdown, INPUT); //Set temp down button to input
  pinMode(tcf, INPUT); //Set C to F button to input
  pinMode(ledPin, OUTPUT); //Set LED to output
}

void loop() {
  upstate = digitalRead(tup); //Read state of temp up
  downstate = digitalRead(tdown); //Read state of temp down
  tcfstate = digitalRead(tcf); //Read state of C to F button
  int tvalue = analogRead(tempPin);  // make tvalue what ever we read on the tempPin

  if (tcfstate == LOW) { //If the C to F button is pressed
    if (far == true) { //And Farenheit is true already
      far = false;
      cel = true; //Enable Celsius
    }
    else if (far == false) { //Otherwise if Farenheit isn't true
      far = false; //Enable Farenheit
      cel = true;
    }
  }

  if (far == true) { //If Farenheit is true
    temp = farenheit(tvalue); //Caclulate temp in F
    abbrv = 'F'; //Set label to F
  }
  if (cel == true) { //If Celsius is true
    temp = celsius(tvalue); //Calculate temp in C
    abbrv = 'C'; //Set label to C
  }

  if (upstate == LOW) { //if up button is pressed,
    defF = defF + 1; //raise desired F by 1
    defC = defC + 1; //Raise desired C by 1
  }
  if (downstate == LOW) { //if down button is pressed
    defF = defF - 1; //lower desired F by 1
    defC = defC - 1; //lower desired C by 1
  }

  lcd.setCursor(0, 0);
  lcd.print("Tek-aya ");
  lcd.print (temp);  // Print the current temp in f
  lcd.print (abbrv);
  delay(255);
  if (cel == true) {
    lcd.setCursor (0, 1); // set the cursor to 0,1
    lcd.print ("YctaBka "); // Print set to and your ideal temperature in f
    lcd.print (defC);
    lcd.print (abbrv);
  }
  if (far == true) {
    lcd.setCursor (0, 1); // set the cursor to 0,1
    lcd.print ("YctaBka "); // Print set to and your ideal temperature in f
    lcd.print (defF);
    lcd.print (abbrv);
  }

  lightUp(temp, defC, defF); //run custom light up command
  
  if (lightMe == true) { //if light up is true
    digitalWrite(ledPin, HIGH); //turn on LED
  } else if (lightMe == false) { //otherwise
    digitalWrite(ledPin, LOW); //turn off LED
  }
} // we're done

float farenheit(float raw) { //calculate far value
  float f; //create temporary variable F
  f = raw / 2.07; //calculate temperature from raw value
  return f; //return temperature
}

float celsius(float raw) { //calculate cel value
  float c; //create temp variable C
  c = raw / 7.1; //calculate temperature from raw value
  return c; //return temperature
}

boolean lightUp(float act, int desC, int desF) { //Decides if LED should light up, imports current temp, desired C, and desired F
  if (act < desC || act < desF) { //if the actual is less than the desired F or C value
    lightMe = true; //Turn on the LED
  } else { //otherwise
    lightMe = false; //Turn the LED off
  }
  return lightMe; //return that value
}
 
Извиняюсь за оффтом, не нашел как редактировать текст..
Вообще идея повторить принцип работы холодильного оборудования, но проще. С одним или двумя датчиками температур, с эмуляцией вентиляторов и с работой ЭРВ (Электронный регулирующий клапан). Т.е. ЭРВ открывается - температура окружающей среды падает и наоборот. Проблема в реализации этого самого ЭРВ на ардуино и в написании кода.

Естественно само ЭРФ никак не добавить в схему, по этому пришел к решению, что показать работу ЭРВ можно через осциллограф.
 
Сейчас есть много решений Iot, в том числе и клапанов с сервоприводами, управляемыми контроллерами. Возможно, вам поможет решить вашу проблему этот материал: Климат-контроль на Arduino [Амперка / Вики]
 
Сейчас есть много решений Iot, в том числе и клапанов с сервоприводами, управляемыми контроллерами.
Спасибо большое. Но я так понимаю это можно собрать и грубо говоря потрогать руками. Но мне нужно для курсового проекта. Т.е. не нужно собирать физическую схему, нужно именно показать эту эмуляцию через софт.
 
Назад
Сверху