Advertisement
pleasedontcode

Sensor Transmission rev_01

Dec 13th, 2023
70
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: Sensor Transmission
  13.     - Source Code compiled for: Arduino Mega
  14.     - Source Code created on: 2023-12-13 11:28:27
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* recebe informação via adaptador sr485 to ttl, e */
  21.     /* transmite os dados para outros dois arduinos */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <Arduino.h>
  26. #include <DHT.h>
  27. #include <SoftwareSerial.h>
  28.  
  29. /****** SYSTEM REQUIREMENTS *****/
  30. /****** SYSTEM REQUIREMENT 1 *****/
  31.   /* Receives information via SR485 to TTL adapter */
  32.   /* Transmits data to two other Arduinos */
  33.  
  34. /****** FUNCTION PROTOTYPES *****/
  35. void setup(void);
  36. void loop(void);
  37.  
  38. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  39. const uint8_t temp_DHT11_DOUT_PIN_D2 = 2;
  40. const uint8_t sr485_RX_PIN = 3;
  41. const uint8_t sr485_TX_PIN = 4;
  42.  
  43. /****** DEFINITION OF LIBRARY CLASS INSTANCES *****/
  44. DHT dht(temp_DHT11_DOUT_PIN_D2, DHT11);
  45. SoftwareSerial sr485(sr485_RX_PIN, sr485_TX_PIN);
  46.  
  47. void setup(void)
  48. {
  49.   // put your setup code here, to run once:
  50.   Serial.begin(9600);
  51.   sr485.begin(9600);
  52.   dht.begin();
  53. }
  54.  
  55. void loop(void)
  56. {
  57.   // put your main code here, to run repeatedly:
  58.   float temperature = dht.readTemperature();
  59.   float humidity = dht.readHumidity();
  60.  
  61.   if (isnan(temperature) || isnan(humidity))
  62.   {
  63.     Serial.println("Failed to read from DHT sensor!");
  64.     return;
  65.   }
  66.  
  67.   Serial.print("Temperature: ");
  68.   Serial.print(temperature);
  69.   Serial.print(" °C, Humidity: ");
  70.   Serial.print(humidity);
  71.   Serial.println(" %");
  72.  
  73.   // Transmit data to other Arduinos via SR485
  74.   sr485.print("Temperature: ");
  75.   sr485.print(temperature);
  76.   sr485.print(" °C, Humidity: ");
  77.   sr485.print(humidity);
  78.   sr485.println(" %");
  79.  
  80.   delay(2000);
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement