Question
I want combine 2 codes one for getting temp data and the second one is to send the data to sms Arduino First code #define
I want combine 2 codes one for getting temp data and the second one is to send the data to sms
Arduino
First code
#define SENSOR_PIN 21 // ESP32 pin GIOP21 connected to DS18B20 sensor's DQ pin
OneWire oneWire(SENSOR_PIN);
DallasTemperature DS18B20(&oneWire);
float tempC; // temperature in Celsius
float tempF; // temperature in Fahrenheit
void setup() {
Serial.begin(9600); // initialize serial
DS18B20.begin(); // initialize the DS18B20 sensor
}
void loop() {
DS18B20.requestTemperatures(); // send the command to get temperatures
tempC = DS18B20.getTempCByIndex(0); // read temperature in C
tempF = tempC * 9 / 5 + 32; // convert C to F
Serial.print("Temperature: ");
Serial.print(tempC); // print the temperature in C
Serial.print("C");
Serial.print(" ~ "); // separator between C and F
Serial.print(tempF); // print the temperature in F
Serial.println("F");
delay(500);
}
Second code
#include "twilio.hpp"
// Set these - but DON'T push them to GitHub!
static const char *ssid = "";
static const char *password = "";
// Values from Twilio (find them on the dashboard)
static const char *account_sid = "";
static const char *auth_token = "";
// Phone number should start with "+
static const char *from_number = "";
// You choose!
// Phone number should start with "+
static const char *to_number = "";
static const char *message = "Sent from my ESP32";
Twilio *twilio;
void setup() {
Serial.begin(115200);
Serial.print("Connecting to WiFi network ;");
Serial.print(ssid);
Serial.println("'...");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.println("Connecting...");
delay(500);
}
Serial.println("Connected!");
twilio = new Twilio(account_sid, auth_token);
delay(1000);
String response;
bool success = twilio->send_message(to_number, from_number, message, response);
if (success) {
Serial.println("Sent message successfully!");
} else {
Serial.println(response);
}
}
void loop() {
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started