mreid_fi:
Hey,
I’m new to the group and now a few months crafting with Arduino and no previous experience in coding is not, so to speak, then started from zero.
I have under construction temperature monitoring in the basement. The hardware is currently a transmitter from the Nano with 4 DallasTemperature DS18B20 sensors and the transmitter is a 433 MHz RF Module and the receiver is Uno.
I need help when my own ideas and skills run out and there doesn’t seem to be any help on the internet.
The device works well with two sensors and the temperatures are displayed and the serial monitor correctly,
but the addition of temperature sensors causes trouble when I don’t get the 433 MHz RF message divided into more than two parts?
Now the code is next and the message seems to be coming in the right length and works with two sensors ok but with more it doesn’t have enough lines.
// Haetaan käytettävät kirjastot
#include <RH_ASK.h>
#include <LiquidCrystal.h>
//Määritetään LCD-näytön tarvitsemat pinnit
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
//Määritetään merkkivalojen pinnit
int pun = 8;
int pun1 = 9;
int vihr = 13;
// Määritetään lähtevä stirng
String str_temp1;
String str_temp2;
String str_temp3;
String str_temp4;
String str_out;
// Määritetään radion nopeus ja pinni
RH_ASK rf_driver(2000, 7);
void setup() {
// Alustetaan radiovastaanotin
rf_driver.init();
// Asennetaan Serial Monitor
Serial.begin(9600);
// Alustetaan LCD ja määritetään sarakkeet ja rivit
lcd.begin(20, 4); // Alustetaan Serial Monitor
Serial.begin(9600);
//Alustetaan ledien pinnit
pinMode(pun, OUTPUT);
pinMode(pun1, OUTPUT);
pinMode(vihr, OUTPUT);
// Varmistetaan, että ledit ovat sammuksissa
digitalWrite (pun, LOW);
digitalWrite (pun1, LOW);
digitalWrite (vihr, LOW);
}
void loop() {
//Stabiloidaan lämpötila-anturi pienellä tauolla
delay (2000);
// Asennetaan bufferi ja koko viestille
uint8_t buf[23];
uint8_t buflen = sizeof(buf);
// Tarkastetaan onko vastaanotettu paketti oikean kokoinen
if (rf_driver.recv(buf, &buflen))
{
// Viesti vastaanotettu kelvollisella tarkistussummalla
// Hae arvoja merkkijonosta
// Muuntaa vastaanotetut tiedot merkkijonoksi
str_out = String((char*)buf);
// Jaa merkkijono kahteen arvoon
for (int i = 0; i < str_out.length(); i++) {
if (str_out.substring(i, i+1) == “,”) {
str_temp1 = str_out.substring(0,i);
str_temp2 = str_out.substring(i+1);
break;
}
}
// Tulostetaan lämpötila Serial Monitoriin
Serial.print("1 on ");
Serial.print(str_temp1);
Serial.println(“C”);
Serial.print("2 on ");
Serial.print(str_temp2);
Serial.println(“C”);
Serial.print("3 on ");
Serial.print(str_temp3);
Serial.println(“C”);
Serial.print("4 on ");
Serial.print(str_temp4);
Serial.println(“C”);
// Asetetaan kursori näytölle column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 0);
lcd.print("Ulkona ");
lcd.print(str_temp1);
lcd.print(“C”);
lcd.setCursor(0, 1);
lcd.print("Sisalla ");
lcd.print(str_temp2);
lcd.print(“C”);
lcd.setCursor(0, 2);
lcd.print("Ylakerta ");
lcd.print(str_temp3);
lcd.print(“C”);
lcd.setCursor(0, 3);
lcd.print(“ulkoseina”);
lcd.print(str_temp4);
lcd.print(“C”);
delay (1000); //Viive 1 sekuntti (1000 millisekunttia)
}
{
//Asetetaan ledien syttymis- ja sammumislämpötilat
if (str_temp2>= “25”) digitalWrite (vihr, HIGH);
if (str_temp2<= “23”) digitalWrite (vihr, LOW);
if (str_temp2<= “24”) digitalWrite (pun1, HIGH);
if (str_temp2>= “25”) digitalWrite (pun1, LOW);
if (str_temp2<= “22”) digitalWrite (pun, HIGH);
if (str_temp2>= “23”) digitalWrite (pun, LOW);
}
}
There is a need to divide the received message into four lines when there are four temperature sensors.
What needs to be added / changed in that code?