Advertisement
pleasedontcode

Sensor Integration rev_01

Jan 12th, 2024
72
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 Nano
  14.     - Source Code created on: 2024-01-12 10:34:00
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* potentiometer value is mapped to led brightness */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <Arduino.h>
  25. #include <forcedBMX280.h>
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30.  
  31. /***** DEFINITION OF ANALOG INPUT PINS *****/
  32. const uint8_t pot1_Potentiometer_Vout_PIN_A0 = A0;
  33.  
  34. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  35. ForcedBME280Float climateSensor;
  36. uint8_t ledPin = 9;
  37.  
  38. void setup(void)
  39. {
  40.   // put your setup code here, to run once:
  41.   pinMode(pot1_Potentiometer_Vout_PIN_A0, INPUT);
  42.   pinMode(ledPin, OUTPUT);
  43.  
  44.   // Initialize the climate sensor
  45.   Wire.begin();
  46.   while (climateSensor.begin())
  47.   {
  48.     delay(1000);
  49.   }
  50. }
  51.  
  52. void loop(void)
  53. {
  54.   // put your main code here, to run repeatedly:
  55.   int potValue = analogRead(pot1_Potentiometer_Vout_PIN_A0);
  56.   int brightness = map(potValue, 0, 1023, 0, 255);
  57.   analogWrite(ledPin, brightness);
  58.  
  59.   // Climate sensor measurements
  60.   climateSensor.takeForcedMeasurement();
  61.   float temperature = climateSensor.getTemperatureCelsiusAsFloat(true);
  62.   float pressure = climateSensor.getPressureAsFloat();
  63.   float humidity = climateSensor.getRelativeHumidityAsFloat();
  64.  
  65.   // Print temperature
  66.   Serial.print("Temperature: ");
  67.   Serial.print(temperature);
  68.   Serial.println(" °C");
  69.  
  70.   // Print pressure
  71.   Serial.print("Pressure: ");
  72.   Serial.print(pressure);
  73.   Serial.println(" hPa");
  74.  
  75.   // Print humidity
  76.   Serial.print("Humidity: ");
  77.   Serial.print(humidity);
  78.   Serial.println(" %rh");
  79.  
  80.   delay(1000);
  81. }
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement