Lm35 lcd 2arduinos compim

hello all,

if someone could give me a hand on what should i code to send a temp data from master to slave ..

also, i intend to use a "Compim" to read data via a serial monitor : how exactly can i code that ?

MASTER CODE :



int tempPin = 0
float valBrute;

void setup() {

  // Initialise la communication avec le PC
  Serial.begin(9600);
}

// Fonction loop(), appelée continuellement en boucle tant que la carte Arduino est alimentée
void loop() {
  
  // Mesure la tension sur la broche A0
  float valBrute= analogRead(temPin);
  
  // Transforme la mesure (nombre entier) en température via un produit en croix
  int temperature_celcius = valBrute * (5.0 / 1023.0 * 100.0);
  
  // Envoi la mesure au PC pour affichage et attends 250ms
  Serial.write(temperature_celcius);
  delay(250);
}

SLAVE CODE :

#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);

lcd.begin(16,2);
lcd.print ("temperature is : ");
}

void loop() {
  // put your main code here, to run repeatedly:
if (Serial.available())
 {
   int  temperature_celsius = Serial.read();
    if(temperature_celsius > 0) // si le buffer n'est pas vide
    {  
     lcd.setCursor(0,1);
     lcd.print(temperature_celsius);
     lcd.print("C");}
}
}```

A what?

1. Connect your Master-UNO and Slave-UNO using software UART Port (SUART Port) as per Fig-1.
uartUnoUno-3
Figure-1:

2. There is no need to connect K1 with UNO-1. Connect your LM35 sensor with UNO-1.
3. Upload the following sketch into UNO-1. (Your one but modified.; compiled and not tested.)

#include<SoftwareSerial.h>
SoftwareSerial SUART(5, 6);

int tempPin = 0;
int valBrute;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  valBrute = analogRead(tempPin);
  int temperature_celcius = (int)(valBrute * (5.0 / 1023.0) * 100.0);

  Serial.println(temperature_celcius);
  SUART.println(temperature_celcius);
  delay(1000);
}

4. Upload the following sketch in Slave. (Your one but modified; compiled and not tested.)


#include<SoftwareSerial.h>
SoftwareSerial SUART(5, 6);

#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup()
{
  Serial.begin(9600);

  lcd.begin(16, 2);
  lcd.print ("temperature is : ");
}

void loop()
{
  byte n = SUART.available();
  if ( n != 0)
  {
    char ch = SUART.read();
    Serial.print(ch);
    lcd.setCursor(0, 1);
    lcd.print(ch);
  }
}

5. Check that SM and LCD of Slave shows the temperature.

thank uu sir , but if i want to use compim for simulation ? because the main project is to commmunicate with 2 xbee , but i dont know how to use it in proteus isis , so i try with compim

@saadlrq, welcome

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project :wink: See About the Installation & Troubleshooting category.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.