Hi I'm working on two arduinos that communicate to each other by I2C method. One board acts like a master in monitoring room temp and sending the message to the receiver with the following condition: normal (below 30), alert( 30-70) and danger( above70). The receiver will use the input message to blink the led lights with the following condition: green for normal, yellow for alert, red for danger.
This is what I did so far for the master code #include <Wire.h>
int allowableTemp=0;
byte I2C_temperaturesensor;
int temp= 0;
int tempC=0;
void setup()
{
pinMode(A0, INPUT);
Wire.begin(1);
}
void loop()
{
allowableTemp=30;
temp = analogRead(A0);
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 degrees
if (tempC < allowableTemp) //temp below 30
{
Serial.println("normal"); // blink normal
Wire.beginTransmission(1);
Wire.write(I2C_temperaturesensor);
Wire.endTransmission();
}
if (tempC >= allowableTemp && tempC < allowableTemp + 40) //temp between 30 and 70
{
Serial.println("alert"); //blink alert
Wire.beginTransmission(1);
Wire.write(I2C_temperaturesensor);
Wire.endTransmission();
}
Look at the line before this line. Does the line end with ;? It should.
This and the next error is because you use a : (colon) to end the line. Should be a ; (semi-colon).
You have mismatched { and } so the compiler thinks that you are trying to define a function inside of another function. Hence the error.
Using the autoformat tool will point out some of those errors. If you post the code I can help with the others. Please post code in code tags and use the autoformat tool.
Hi, Thank you. I was able to fix my code however, there was an issue with my slaver code the LED light couldn't change to different colors. Here is my codes
Master code
char chArray[7];
int tmp36=A0;
int allowableTemp = 0;
double temp;
double tempC;
void setup()
{
Serial.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) //temp below 30
{
strcpy(chArray,"normal"); // blink normal
}
else if (tempC >= allowableTemp && tempC < allowableTemp + 40) //temp between 30 and 70
{
strcpy(chArray,"alert"); //blink alert
}