Challenge

Project 1 - Interfacing a 16*2 LCD with Arduino using I2C protocol

abinaya

slave node 

#include

SoftwareSerial(5, 6);  //DPin-5 = SRX, DPin-6 = STX

char chArray[7];

int tmp36=A0;

int allowableTemp = 0;

double temp;

double tempC;

void setup()

{

    Serial.begin(9600);

    SUART.begin(9600);

    pinMode(tmp36, INPUT);

}

void loop()

{

    allowableTemp = 30;

    temp = analogRead(tmp36);

    temp = temp / 1024; //* find percentage of input reading

    temp = temp * 5; //* multiply by 5V to get voltage

    temp = temp - 0.5; //* Subtract the offset

    tempC = temp * 100; //* Convert to degree

   if (tempC < allowableTemp>

   {

       strcpy(chArray,"normal"); // blink normal

       SUART.println(chArray);       //send message to Slave (UNO-2)

   }

   else if (tempC >= allowableTemp && tempC < allowableTemp>

   {

         strcpy(chArray,"alert"); //blink alert

         SUART.println(chArray);       //send message to Slave (UNO-2)

   }

   else //temp above 70

  {

      strcpy(chArray,"danger");//blink danger

      SUART.println(chArray);       //send message to Slave (UNO-2)

  }

}

master node

#include

SoftwareSerial(5, 6);  //DPin-5 = SRX, DPin-6 = STX

char roomtemp [10];

int LED1=4;

int LED2=3;

int LED3=2;

byte m;

void setup ()

{

    Serial.begin(9600);

    SUART.begin(9600);

    pinMode(LED1, OUTPUT);

    pinMode(LED2, OUTPUT);

}

void loop()

{

     while(SUART.available() >0)

     {

            m =  SUART.readBytesUntil('\n', roomtemp, 10);

     }

     roomtemp[m] = '\0';

     if(strcmp(roomtemp, "normal") == 0)

     {

                  digitalWrite(LED1, HIGH);

                  delay(1000);

                  digitalWrite(LED1, LOW);

                  delay(1000);

      }

      if(strcmp(roomtemp, "alert") == 0)

      {

                  digitalWrite(LED2, HIGH);

                  delay(1000);

                  digitalWrite(LED2, LOW);

                  delay(1000);

      }

      if(strcmp(roomtemp, "normal") == 0)

      {

                  digitalWrite(LED1, HIGH);

                  delay(1000);

                  digitalWrite(LED1, LOW);

                  delay(1000);

      } 

}

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.