Advertisement
cryzi

**Sensor Monitoring** rev_02

Jan 2nd, 2025
77
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 Monitoring**
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-12-31 11:59:14
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Arduino code generator for real time remote */
  21.     /* monitoring and automation of distribution */
  22.     /* transformer using Arduino uno, gsm, ac current */
  23.     /* sensor, ac volage sensor, ultrasonic oil level */
  24.     /* sensor, lm35, lcd 20*4 */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /* START CODE */
  28.  
  29. /****** DEFINITION OF LIBRARIES *****/
  30. #include <GSM.h>
  31. #include <ACCurrentSensor.h>
  32. #include <ACVoltageSensor.h>
  33. #include <Ultrasonic.h>
  34. #include <LM35.h>
  35. #include <LiquidCrystal.h>
  36.  
  37. /****** FUNCTION PROTOTYPES *****/
  38. void setup(void);
  39. void loop(void);
  40.  
  41. /****** GLOBAL VARIABLES *****/
  42. GSM gsm; // GSM module object
  43. ACCurrentSensor acCurrentSensor; // AC current sensor object
  44. ACVoltageSensor acVoltageSensor; // AC voltage sensor object
  45. Ultrasonic ultrasonicSensor(7, 8); // Ultrasonic sensor with trigPin 7 and echoPin 8
  46. LM35 lm35Sensor(A0); // LM35 temperature sensor on analog pin A0
  47. LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // LCD object with appropriate pins
  48.  
  49. void setup(void)
  50. {
  51.     // Initialize the GSM module
  52.     gsm.begin();
  53.    
  54.     // Initialize the LCD
  55.     lcd.begin(20, 4); // Set up the LCD's number of columns and rows
  56.     lcd.print("System Init"); // Print message on LCD
  57.  
  58.     // Initialize sensors
  59.     acCurrentSensor.begin();
  60.     acVoltageSensor.begin();
  61.     ultrasonicSensor.setTimeout(20000UL); // Set timeout for ultrasonic sensor
  62. }
  63.  
  64. void loop(void)
  65. {
  66.     // Main code for monitoring and automation
  67.     // Read values from sensors and display them
  68.     double temperature = lm35Sensor.getTemp(); // Get temperature from LM35
  69.     lcd.setCursor(0, 1);
  70.     lcd.print("Temp: ");
  71.     lcd.print(temperature);
  72.     lcd.print(" C");
  73.  
  74.     // Read and display AC current and voltage
  75.     double current = acCurrentSensor.readCurrent(); // Read current
  76.     double voltage = acVoltageSensor.readVoltage(); // Read voltage
  77.     lcd.setCursor(0, 2);
  78.     lcd.print("Current: ");
  79.     lcd.print(current);
  80.     lcd.print(" A");
  81.     lcd.setCursor(0, 3);
  82.     lcd.print("Voltage: ");
  83.     lcd.print(voltage);
  84.     lcd.print(" V");
  85.  
  86.     // Read distance from ultrasonic sensor
  87.     unsigned int distance = ultrasonicSensor.read(); // Read distance
  88.     lcd.setCursor(0, 0);
  89.     lcd.print("Distance: ");
  90.     lcd.print(distance);
  91.     lcd.print(" cm");
  92.  
  93.     delay(1000); // Delay for readability
  94. }
  95.  
  96. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement