Advertisement
pleasedontcode

**Blynk Monitoring** rev_01

Dec 21st, 2024
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: **Blynk Monitoring**
  13.     - Source Code NOT compiled for: ESP8266 NodeMCU V1.0
  14.     - Source Code created on: 2024-12-22 00:36:13
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* #define BLYNK_PRINT Serial  #include <OneWire.h> */
  21.     /* #include <SPI.h>  #include <BlynkSimpleEsp8266.h> */
  22.     /* #include <DHT.h>  #include <DallasTemperature.h> */
  23.     /* #define ONE_WIRE_BUS D2  OneWi */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /* START CODE */
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #define BLYNK_PRINT Serial
  30. #include <OneWire.h>
  31. #include <SPI.h>
  32. #include <BlynkSimpleEsp8266.h>
  33. #include <DHT.h>
  34. #include <DallasTemperature.h>
  35.  
  36. #define ONE_WIRE_BUS D2 // Define the pin for the OneWire bus
  37.  
  38. // Instantiate objects for the libraries
  39. OneWire oneWire(ONE_WIRE_BUS); // Create an instance of OneWire
  40. DallasTemperature sensors(&oneWire); // Create an instance of DallasTemperature
  41. DHT dht(2, DHT11); // Create an instance of DHT sensor on pin 2
  42.  
  43. // Blynk authentication token
  44. char auth[] = "YourAuthToken"; // Replace with your Blynk auth token
  45.  
  46. /****** FUNCTION PROTOTYPES *****/
  47. void setup(void);
  48. void loop(void);
  49.  
  50. void setup(void)
  51. {
  52.     // Initialize serial communication
  53.     Serial.begin(9600);
  54.    
  55.     // Initialize Blynk
  56.     Blynk.begin(auth, "YourSSID", "YourPassword"); // Replace with your WiFi credentials
  57.  
  58.     // Initialize sensors
  59.     sensors.begin();
  60.     dht.begin();
  61. }
  62.  
  63. void loop(void)
  64. {
  65.     // Run Blynk
  66.     Blynk.run();
  67.  
  68.     // Request temperature readings
  69.     sensors.requestTemperatures();
  70.     float temperature = sensors.getTempCByIndex(0); // Get temperature from the first sensor
  71.     float humidity = dht.readHumidity(); // Read humidity
  72.     float temp = dht.readTemperature(); // Read temperature from DHT
  73.  
  74.     // Print readings to Serial
  75.     Serial.print("Temperature: ");
  76.     Serial.print(temperature);
  77.     Serial.print(" °C, Humidity: ");
  78.     Serial.print(humidity);
  79.     Serial.println(" %");
  80.  
  81.     // Send data to Blynk
  82.     Blynk.virtualWrite(V0, temperature); // Send temperature to virtual pin V0
  83.     Blynk.virtualWrite(V1, humidity); // Send humidity to virtual pin V1
  84.  
  85.     delay(2000); // Delay for 2 seconds
  86. }
  87.  
  88. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement