Advertisement
pleasedontcode

"Sensor Integration" rev_04

Mar 6th, 2024
80
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 Integration"
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-03-06 07:52:08
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* turn on the led when it work */
  21. /****** SYSTEM REQUIREMENT 2 *****/
  22.     /* i want the alarm get activated when the gaz sensor */
  23.     /* in on */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26.  
  27. /********* User code review feedback **********
  28. #### Feedback 1 ####
  29. - Adafruit_MLX90614.h: No such file or directory
  30. ********* User code review feedback **********/
  31.  
  32. /****** DEFINITION OF LIBRARIES *****/
  33. #include <Wire.h>
  34. #include <Adafruit_MLX90614.h>
  35.  
  36. /****** SYSTEM REQUIREMENTS *****/
  37. /****** SYSTEM REQUIREMENT 1 *****/
  38. /* Turn on the LED when it works */
  39. /****** SYSTEM REQUIREMENT 2 *****/
  40. /* Activate the alarm when the gas sensor is on */
  41. /****** END SYSTEM REQUIREMENTS *****/
  42.  
  43. /****** FUNCTION PROTOTYPES *****/
  44. void setup(void);
  45. void loop(void);
  46.  
  47. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  48. const uint8_t gas_SENSOR_PIN_D2 = 2;
  49. const uint8_t led_PIN_D13 = 13;
  50.  
  51. /***** DEFINITION OF I2C PINS *****/
  52. const uint8_t mlx_I2C_PIN_SDA_A4 = A4;
  53. const uint8_t mlx_I2C_PIN_SCL_A5 = A5;
  54. const uint8_t mlx_I2C_SLAVE_ADDRESS = 0x5A; // Default I2C address of MLX90614
  55.  
  56. /****** DEFINITION OF LIBRARY CLASS INSTANCES *****/
  57. Adafruit_MLX90614 mlx = Adafruit_MLX90614();
  58.  
  59. void setup(void)
  60. {
  61.   pinMode(gas_SENSOR_PIN_D2, INPUT);
  62.   pinMode(led_PIN_D13, OUTPUT);
  63.  
  64.   Serial.begin(9600);
  65.   while (!Serial)
  66.     ;
  67.  
  68.   Serial.println("Adafruit MLX90614 test");
  69.  
  70.   if (!mlx.begin(mlx_I2C_SLAVE_ADDRESS))
  71.   {
  72.     Serial.println("Error connecting to MLX90614 sensor. Check wiring.");
  73.     while (1)
  74.       ;
  75.   }
  76.  
  77.   Serial.print("Emissivity = ");
  78.   Serial.println(mlx.readEmissivity());
  79.   Serial.println("================================================");
  80. }
  81.  
  82. void loop(void)
  83. {
  84.   if (digitalRead(gas_SENSOR_PIN_D2) == HIGH)
  85.   {
  86.     digitalWrite(led_PIN_D13, HIGH); // Activate the alarm LED
  87.   }
  88.   else
  89.   {
  90.     digitalWrite(led_PIN_D13, LOW); // Turn off the alarm LED
  91.   }
  92.  
  93.   Serial.print("Ambient = ");
  94.   Serial.print(mlx.readAmbientTempC());
  95.   Serial.print("*C\tObject = ");
  96.   Serial.print(mlx.readObjectTempC());
  97.   Serial.println("*C");
  98.   Serial.print("Ambient = ");
  99.   Serial.print(mlx.readAmbientTempF());
  100.   Serial.print("*F\tObject = ");
  101.   Serial.print(mlx.readObjectTempF());
  102.   Serial.println("*F");
  103.  
  104.   Serial.println();
  105.   delay(500);
  106. }
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement