Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: **Blynk Monitoring**
- - Source Code NOT compiled for: ESP8266 NodeMCU V1.0
- - Source Code created on: 2024-12-22 00:36:13
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* #define BLYNK_PRINT Serial #include <OneWire.h> */
- /* #include <SPI.h> #include <BlynkSimpleEsp8266.h> */
- /* #include <DHT.h> #include <DallasTemperature.h> */
- /* #define ONE_WIRE_BUS D2 OneWi */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #define BLYNK_PRINT Serial
- #include <OneWire.h>
- #include <SPI.h>
- #include <BlynkSimpleEsp8266.h>
- #include <DHT.h>
- #include <DallasTemperature.h>
- #define ONE_WIRE_BUS D2 // Define the pin for the OneWire bus
- // Instantiate objects for the libraries
- OneWire oneWire(ONE_WIRE_BUS); // Create an instance of OneWire
- DallasTemperature sensors(&oneWire); // Create an instance of DallasTemperature
- DHT dht(2, DHT11); // Create an instance of DHT sensor on pin 2
- // Blynk authentication token
- char auth[] = "YourAuthToken"; // Replace with your Blynk auth token
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void setup(void)
- {
- // Initialize serial communication
- Serial.begin(9600);
- // Initialize Blynk
- Blynk.begin(auth, "YourSSID", "YourPassword"); // Replace with your WiFi credentials
- // Initialize sensors
- sensors.begin();
- dht.begin();
- }
- void loop(void)
- {
- // Run Blynk
- Blynk.run();
- // Request temperature readings
- sensors.requestTemperatures();
- float temperature = sensors.getTempCByIndex(0); // Get temperature from the first sensor
- float humidity = dht.readHumidity(); // Read humidity
- float temp = dht.readTemperature(); // Read temperature from DHT
- // Print readings to Serial
- Serial.print("Temperature: ");
- Serial.print(temperature);
- Serial.print(" °C, Humidity: ");
- Serial.print(humidity);
- Serial.println(" %");
- // Send data to Blynk
- Blynk.virtualWrite(V0, temperature); // Send temperature to virtual pin V0
- Blynk.virtualWrite(V1, humidity); // Send humidity to virtual pin V1
- delay(2000); // Delay for 2 seconds
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement