Arduino DS18b20 Min Temp IF ELSE CODE

I would like it if statement to call on IF the temperature is above 4 degrees.

Is it possible to call the number af 4 at the top of the script, just as like in a case in C?

//Library temperatuurmeter
#include <OneWire.h>
#include <DallasTemperature.h>
 
// Data port Arduino / DS18b20
#define ONE_WIRE_BUS 4

// Data port DS18b20
OneWire oneWire(ONE_WIRE_BUS);
// Lezen van Data port.
DallasTemperature sensors(&oneWire);

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  Serial.println("Alarm On");

  // Start up the library
  sensors.begin();
}

void loop(void)
{
  // Aanvragen actuele temperatuur in dataport
  Serial.print(" Aanvragen actuele temperatuur...");
  sensors.requestTemperatures(); // actuele temperatuur
  Serial.println("Ontvangen");
   
  Serial.print("Temperatuur *C: ");
  Serial.print(sensors.getTempCByIndex(0)); 

//  if (tempC > 4)
//  {
//    delay(60000); // Wachten voor nieuwe Meting  
//  }  

}

I'd like to save a minimum temperature in a $ variable

C and C++ do not have $ variables.

You can't color code text in a code window. The type is int, not Int. All statements end with ;.

Rename the stupid printTemperature() function. That is NOT what it now does, or, at least not all that it does.

Use Tools + Auto Format before posting code, and make sure that it at least compiles.

{
 Serial.print("Temperatuur *C: ");
 Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"?
  }

Get rid of the useless curly braces. The function has ByIndex in its name because ByFrogLegs doesn't make sense.

The temperature sensor is connected to a bus. How else are you going to identify which sensor on the bus you want to read? YOU may only have one sensor on the bus, but the library needs to handle more than just your case.

Maybe Brick-Temperature-DS18B20 can help. Looks like you have to specify the addresses of the devices. In your case it's only one.

Is it possible to call the number af 4 at the top of the script, just as like in a case in C?

The first thing to understand is that the Arduino is programmed in C++ so anything that you can do in C you can do with the Arduino with very few exceptions.

if (tempC > 4)What type of variable will tempC be ? This will influence how you check its value.

Hello
im new here can i ask u question ?

i wana get temperature from " DS18B20 " and get it in If condition Becuse if temperature is high Get SMS by GSM Module

i write Code But it not working

#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 3

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

int fan = 7;
char phone_no="**********";

void setup() {
Serial.begin(115200);
delay(300);
// Start up the library
sensors.begin();
}
void loop(){

sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println (sensors.getTempCByIndex(0));

if(sensors.getTempCByIndex(0)>= 28.75 ){
digitalWrite(fan, HIGH);
delay(5000);
Serial.println(“AT+CMGF=1”);
delay(2000);
Serial.print(“AT+CMGS=”");
Serial.print(phone_no);
Serial.write(0x22);
Serial.write(0x0D); // hex equivalent of Carraige return
Serial.write(0x0A); // hex equivalent of newline
delay(2000);
Serial.print((char)sensors.getTempCByIndex(0));

//Serial.print(“Hello”);
delay(500);
Serial.println (char(26));//the ASCII code of the ctrl+z is 26
}else{
digitalWrite(fan, LOW);

}
}
Can u help me please … thnx

i write Code But it not working

What should it do ? What does it do ?

By the way. Read my signature below and please take note of it.

UKHeliBob: What should it do ? What does it do ?

By the way. Read my signature below and please take note of it.

i wana get Temperature From DS18B20 and Send it By SMS > By GSM

i wana get Temperature From DS18B20 and Send it By SMS > By GSM

That is what you want, but what does it actually do ?

How is the GSM device connected to the Arduino ? What is the GSM device ?

You appear to be using Serial to debug your sketch AND to talk to you GSM device. Hasn't worked for anyone else. What makes you think you're special?

UKHeliBob: That is what you want, but what does it actually do ?

How is the GSM device connected to the Arduino ? What is the GSM device ?

GSM Print Code in serial monitor normal but i didnt Geting any sms it`s connect with nono arduino TRX to RTX RTX to TRX Gnd to gnd

but code didt send sms

You posted a question here. You read the responses.

You issued an AT command. You totally ignored the responses.

Why?

i did`t ignored the responses :( the massage when i write i geting " Try after 5 Sec Or try later " :(

i Just wana know the problem where so i can fix thanks

i did`t ignored the responses

You did.

Serial.println("AT+CMGF=1");

What did the device respond with? There is NO code in what you posted that reads serial data coming from the device.

You appear to be using Serial to talk to the PC and to the GSM modem. Ain't going to work...

:( im New in arduino :(

what u meen there is no code ? can u explain :) thanks

what u meen there is no code ?

I did not say there was no code. I said there was no code to read the output of the GSM modem. You told it to do something. You haven't a clue whether it said "OK, I did that" or "Go fly I kite. I don't take orders from you".

Until you do, you're pissing into the wind.

PaulS: I did not say there was no code. I said there was no code to read the output of the GSM modem. You told it to do something. You haven't a clue whether it said "OK, I did that" or "Go fly I kite. I don't take orders from you".

Until you do, you're pissing into the wind.

It's quite hard to piss into the wind when you're flying a kite. Just don't ask me how I know.

this is Code … and i dont give u order … i just asking solve of my problem !!!

Mohamed-Atef: and i dont give u order ... i just asking solve of my problem !!!!

That was not directed at you but at your code.

this is Code

But still no code to read the response from the GSM modem.

Where in the code do you think that you are reading the response ?

I WANT TO BLINK LED WHEN TEMPERATURE IS GOES UP 20 DEGREE CELSIUS.WHERE I PUT IF CONDITION IN FOLLOWING CODE.

int val;
int tempPin = 1;

void setup()
{

Serial.begin(9600);
}
void loop()
{
val = analogRead(tempPin);
float mv = ( val/1024.0)5000;
float cel = mv/10;
float farh = (cel
9)/5 + 32;

Serial.print(“TEMPRATURE = “);
Serial.print(cel);
Serial.print(”*C”);
Serial.println();
delay(1000);

/* uncomment this to get temperature in farenhite*/
Serial.print(“TEMPRATURE = “);
Serial.print(farh);
Serial.print(”*F”);
Serial.println();

}