Pessoal de uma forma um pouco "vagarosa" por falta de tempo tenho feitos varios projetos pequenos com o Arduino.

Porem agora preciso de uma coisa maior e então a minha duvida é como eu posso juntas 2 ou mais codigos do arduino em apenas um codigo? Sou leigo em programação e estou apreendendo meio na raça...

EXEMPLO: 

TENHO ESSE: 

Sensor de temperatura e umidade RHT03 com Arduino

#include <dht.h>

dht DHT;


#define DHT22_PIN 5

void setup()
{
Serial.begin(115200);
Serial.println("DHT TEST PROGRAM ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT_LIB_VERSION);
Serial.println();
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
}

void loop()
{
// READ DATA
Serial.print("DHT22, \t");
int chk = DHT.read22(DHT22_PIN);
switch (chk)
{
case DHTLIB_OK: 
Serial.print("OK,\t"); 
break;
case DHTLIB_ERROR_CHECKSUM: 
Serial.print("Checksum error,\t"); 
break;
case DHTLIB_ERROR_TIMEOUT: 
Serial.print("Time out error,\t"); 
break;
default: 
Serial.print("Unknown error,\t"); 
break;
}
// DISPLAY DATA
Serial.print(DHT.humidity, 1);
Serial.print(",\t");
Serial.println(DHT.temperature, 1);

delay(1000);

}

ACRESCENTAR ESSE: LCD...Quero mostar os dados no LCD

*/

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
// set up the LCD's number of columns and rows: 
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");    // Write on LCD
}

void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);
}

Exibições: 1554

Responder esta

Respostas a este tópico

Amigo,

Abaixo, o seu código modificado para exibir a umidade e a temperatura também no display;

[],

Mauro

#include <LiquidCrystal.h>
#include <dht.h>

#define DHT22_PIN 5

dht DHT;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
Serial.begin(115200);
Serial.println("DHT TEST PROGRAM ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT_LIB_VERSION);
Serial.println();
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
lcd.begin(16, 2);
}
void loop()
{
// READ DATA
Serial.print("DHT22, \t");
int chk = DHT.read22(DHT22_PIN);
switch (chk)
{
case DHTLIB_OK:
Serial.print("OK,\t");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.print("Checksum error,\t");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.print("Time out error,\t");
break;
default:
Serial.print("Unknown error,\t");
break;
}
// DISPLAY DATA
Serial.print(DHT.humidity, 1);
Serial.print(",\t");
Serial.println(DHT.temperature, 1);
lcd.setCursor(0, 1);
lcd.print(DHT.humidity);
lcd.setCursor(0, 2);
lcd.print(DHT.temperature);
delay(1000);
}

Obrigado Mauro Assis , aqui sim temos amigos...rrrsrss...

Vou montar e posto o resultado aqui.

Abraços...

um pequeno Bug.

Tanto lcd quanto o DHT estão iniciando o pino 5?

É verdade, os dois vão brigar. Troque então:

#define DHT22_PIN 5

por:

#define DHT22_PIN 6

 

"Na multidão de ideias, a sabedoria."

Freedman, que DHT tu usa?

Testa e me manda o link dessa lib (tem trocentas), que a noite posto as demais instruções, pra acionar 2 motores (dispositivos) de acordo com a variação de T e H.

Mas a coisa é simples:
---

//no cabeçalho--------

#define ATUADOR1PIN 9;  //varia com a temperatura
#define ATUADOR2PIN 10; //varia com a umidade

int setPointT = 28;  // nome ja diz tudo. se der algum erro, tenta mudar pra float
int setPointH = 60; //  "  " " "

//===no setup

 pinMode(ATUADOR1PIN, OUTPUT);
  pinMode(ATUADOR2PIN, OUTPUT);

//==== dentro do loop

  testaT();
  testaH();

//===== abaixo do loop  ======


void testaT(){
  if (DHT.temperature >= setPointT){              //liga o ventilador se a T subir
    digitalWrite(ATUADOR1PIN, HIGH);   // set the LED on
  }
  else{
    digitalWrite(ATUADOR1PIN, LOW);    // set the LED off
  }
}
//----------

void testaH(){
  if (DHT.humidity <= setPointH){                // liga o aspersor/irrigador se a H baixar
    digitalWrite(ATUADOR2PIN, HIGH);   // set the LED on
  }
  else{
    digitalWrite(ATUADOR2PIN, LOW);    // set the LED off
  }
}


Sendo que os setpoints pode configurar por serial, por potenciometro, pushbutton... vai da tua criatividade e componentes disponíveis.

* Deve ter bug aí, digitei direto aqui no site. Qualquer coisa posta os erros.

certo, testa o código que o Mauro ja adiantou. Depois faz essa inserções e posta os erros aqui.

e aí? como ficou o codigo?

Opa Jonatas Freitas...Vou testar hoje a noite.

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço