Narzędzia użytkownika

Narzędzia witryny


projekty:projektsystemupomiarowokontrolnegonabaziearduino

Różnice

Różnice między wybraną wersją a wersją aktualną.

Odnośnik do tego porównania

Poprzednia rewizja po obu stronachPoprzednia wersja
Nowa wersja
Poprzednia wersja
projekty:projektsystemupomiarowokontrolnegonabaziearduino [2025/05/07 14:31] administratorprojekty:projektsystemupomiarowokontrolnegonabaziearduino [2025/05/16 17:30] (aktualna) administrator
Linia 1: Linia 1:
-Jeżeli chcesz zacytować tą pracę to wejdź na zenodo.org:\\ +Jeżeli chcesz zacytować tą pracę to użyj indetyfikatora DOI:\\ 
-[[https://doi.org/10.5281/zenodo.15270122|Projekt systemu pomiarowo-kontrolnego na bazie Arduino]]\\+Ostrowski, K. (2025). Projekt systemu pomiarowo-kontrolnego na bazie Arduino (Wersja 1). Zenodo. https://doi.org/10.5281/zenodo.15270122
  
-**Projekt Systemu pomiarowo-kontrolnego na bazie Arduino**\\+======= Arduino: Projekt Systemu pomiarowo-kontrolnego =======
 ****\\ ****\\
 **Kacper Ostrowski**\\ **Kacper Ostrowski**\\
Linia 598: Linia 598:
 ===== Wykaz załączników ===== ===== Wykaz załączników =====
  
-  - Kod dla platformy Arduino MEGA {{ :projekty:arduino.zip |}} 
   - Skrypt bazy danych oraz dane które system zebrał {{ :projekty:db.zip |}}   - Skrypt bazy danych oraz dane które system zebrał {{ :projekty:db.zip |}}
 +  - Kod dla platformy Arduino MEGA 
 +<code cpp arduino.ino>
 +#include <Streaming.h> 
 +#include <SimpleDHT.h> 
 +#include <SPI.h>
 +#include <Ethernet.h>
 +#include <C:\Users\kostrowski\Desktop\program\AVT5636lib.h>
 +#include <Servo.h>
 +#include <C:\Users\kostrowski\Desktop\program\MemoryFree.h>
 +
 +
 +AVT5636 myBoard;
 +Servo myServo;
 +
 +SimpleDHT11 dht11;
 +
 +byte mac[] = {
 +  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
 +};
 +IPAddress ip(192, 168, 80, 53);
 +
 +// Initialize the Ethernet server library
 +EthernetServer server(8080);
 +
 +float temperature;
 +float humidity;
 +
 +int term2=0;                                                 
 +int  term3=0;                                                 
 +int term4=0;                                                 
 +int  term5=0;
 +
 +uint32_t prevMillis = millis();
 +
 +
 +void setup() {
 +  pinMode(22, INPUT_PULLUP);
 +  pinMode(24, INPUT_PULLUP);
 +  pinMode(26, INPUT_PULLUP);
 +  pinMode(28, INPUT_PULLUP);
 +  pinMode(30, INPUT_PULLUP);
 +  myBoard.init(); 
 +  myServo.attach(PULSE2_PIN);
 +  //delay(3000);
 +
 +  //Serial.begin(9600);
 +  //while (!Serial) {
 +  //  ; // wait for serial port to connect. Needed for native USB port only
 +  //}
 +
 +  Ethernet.begin(mac, ip);
 +  server.begin();
 +  //Serial.print("server is at ");
 +  //Serial.println(Ethernet.localIP());
 +
 +}
 +
 +String HTTP_req;
 +bool LED_status4 = 0;
 +bool LED_status3 = 0;
 +bool LED_status2 = 0;
 +
 +int IntTemperature;
 +int IntHumidity;
 +
 +unsigned long previousMillis = 0;
 +
 +float CurrentSensor = 0;
 +
 +void loop() {
 +  CurrentSensor = ((5.0/1024.0)*analogRead(10))*10;
 +  //Serial.println(CurrentSensor);
 +
 +  LED_status4 = 0;
 +  LED_status3 = 0;
 + 
 +  unsigned long currentMillis = millis();
 +
 +  if (currentMillis - previousMillis >= 60000) {
 +    
 +    previousMillis = currentMillis;
 +    delay(2000);
 +    
 +    byte temperature = 0;
 +    byte humidity = 0;
 +    byte err = SimpleDHTErrSuccess;
 +
 +    if ((err = dht11.read(31, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
 +      //Serial.print("Failed to read from DHT sensor, err=");
 +      //Serial.println(err);
 +      return;
 +    }
 +    
 +    IntTemperature = temperature;
 +    IntHumidity = humidity;
 +    term2 = temperature;
 +    term3 = humidity;
 +  }
 +
 +
 +  term4 = 444;
 +  term5 = 555;
 +  
 +  EthernetClient a = server.available();
 +  serveWebsite(a);
 +
 +
 +}
 +
 +EthernetClient serveWebsite(EthernetClient client){
 +  if (client) {
 +    //Serial.println("new client");
 +    bool currentLineIsBlank = true;
 +    while (client.connected()) {
 +      //Serial.println("test1");
 +      if (client.available()) {
 +        //Serial.println("test2");
 +        char c = client.read();
 +        //Serial.write(c);
 +        HTTP_req += c;
 +        if (c == '\n' && currentLineIsBlank) {
 +          //Serial.println("test3");
 +          if (HTTP_req.indexOf("LED4=On") > -1) { LED_status4 = 1; }
 +          if (HTTP_req.indexOf("LED4=Off") > -1) { LED_status4 = 0; }
 +          if (HTTP_req.indexOf("LED3=On") > -1) { LED_status3 = 1; }
 +          if (HTTP_req.indexOf("LED3=Off") > -1) { LED_status3 = 0; }
 +          if (HTTP_req.indexOf("LED2=On") > -1) { LED_status2 = 1; }
 +          if (HTTP_req.indexOf("LED2=Off") > -1) { LED_status2 = 0; }
 +
 +          client.println(F("HTTP/1.1 200 OK"));
 +          client.println("Content-Type: text/html");
 +          client.println("Connection: close");
 +          //client.println("Refresh: 10; URL=/");
 +          client.println();
 +          client.println("<!DOCTYPE HTML>");
 +          client.println("<html>");
 +          client.println("<head>");
 +          client.println("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
 +          // client.println("<style>");
 +          // client.println("body { font-family: Arial, sans-serif; margin: 0; padding: 0; font-size: 12px; }");
 +          // client.println("h2 { color: #333; }");
 +          // client.println(".container { width: 80%; margin: 0 auto; padding: 20px; }");
 +          // client.println("table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }");
 +          // client.println("th, td { padding: 8px; text-align: left; border-bottom: 1px solid #ddd; }");
 +          // client.println("tr:hover { background-color: #f5f5f5; }");
 +          // client.println(".btn { padding: 8px 16px; margin: 5px; text-decoration: none; color: white; border: none; display: inline-block; font-size: 12px; }");
 +          // client.println(".btn-on { background-color: #4CAF50; }");
 +          // client.println(".btn-off { background-color: #f44336; }");
 +          // client.println(".status-on { background-color: #39FF14; }"); // Neon green
 +          // client.println(".status-off { background-color: #FF073A; }"); // Neon red
 +          // client.println("</style>");
 +          client.println("</head>");
 +          client.println("<body>");
 +          client.println("<div class=\"container\">");
 +          client.println("<h2>System Pomiarowo-Kontrolny TTCOMM Sp.z.o.o.</h2>");
 +          client.println("<h4>Opracowano przez: Kacper Ostrowski</h4>");
 +          client.println("<h4>Wersja z dnia: 11.06.2024</h4>");
 +          client.println("<h2>Analog Sensor Readings</h2>");
 +          client.println("<table>");
 +          client.println("<tr><th>Sensor</th><th>Value</th></tr>");
 +
 +          client.println("<tr><td>Temperature</td><td>" + String(IntTemperature) + " C</td></tr>");
 +          client.println("<tr><td>Humidity</td><td>" + String(IntHumidity) + " %</td></tr>");
 +
 +          client.println("<tr><td>Electric Current</td><td>   "+String(CurrentSensor)+"     A</td></tr>");
 +          client.println("</table>");
 +          client.println("<h2>Digital Input Readings</h2>");
 +          client.println("<table>");
 +          client.println("<tr><th>Sensor</th><th>Value</th></tr>");
 +          client.print("<tr><td>Door Open/Closed</td><td>");
 +          client.print(digitalRead(22));
 +          client.println("</td></tr>");
 +          client.print("<tr><td>Flood sensor</td><td>");
 +          client.print(digitalRead(24));
 +          client.println("</td></tr>");
 +          client.print("<tr><td>Waveguide Position 1</td><td>");
 +          client.print(digitalRead(26));
 +          client.println("</td></tr>");
 +          client.print("<tr><td>Waveguide Position 2</td><td>");
 +          client.print(digitalRead(28));
 +          client.println("</td></tr>");
 +          client.print("<tr><td>Waveguide Power Supply</td><td>");
 +          client.print(digitalRead(30));
 +          client.println("</td></tr>");
 +          client.println("</table>");
 +          client.println("<h2>Control Buttons</h2>");
 +          client.println("Override Control Buttons:");
 +          client.println("<form method='get'>");
 +          
 +          // LED4 control and mode selection
 +          client.println("<p>Waveguide position 1: <button name='LED4' type='submit' class='btn btn-on' value='On'>ON</button> Please check afterwards the status of position in the above table");
 +          //client.println("<button name='LED4' type='submit' class='btn btn-off' value='Off'>OFF</button>");
 +
 +          if (LED_status4) {
 +            myBoard.ledOn(4);
 +            delay(3000);
 +            myBoard.ledOff(4);
 +            delay(3000);
 +          } else {
 +            myBoard.ledOff(4);
 +          }
 +
 +          // LED3 control and mode selection
 +          client.println("<p>Waveguide position 2: <button name='LED3' type='submit' class='btn btn-on' value='On'>ON</button> Please check afterwards the status of position in the above table");
 +          //client.println("<button name='LED3' type='submit' class='btn btn-off' value='Off'>OFF</button>");
 +
 +          
 +          if (LED_status3) {
 +            myBoard.ledOn(3);
 +            delay(3000);
 +            myBoard.ledOff(3);
 +            delay(3000);
 +          } else {
 +            myBoard.ledOff(3);
 +          }
 +
 +          // LED2 control and mode selection
 +          client.println("<p>Room Heater: <button name='LED2' type='submit' class='btn btn-on' value='On'>ON</button>");
 +          client.println("<button name='LED2' type='submit' class='btn btn-off' value='Off'>OFF</button>");
 +
 +
 +          if (LED_status2) {
 +            myBoard.ledOn(2);
 +            client.println("<p class='status-on'>Status: ON");
 +          } else {
 +            myBoard.ledOff(2);
 +            client.println("<p class='status-off'>Status: OFF");
 +          }
 +
 +          client.println("</form>");
 +          client.println("</div>");
 +          client.println("</body>");
 +          client.println("</html>");
 +          
 +          HTTP_req = "";
 +          break;
 +        }
 +        if (c == '\n') {
 +          currentLineIsBlank = true;
 +        } else if (c != '\r') {
 +          currentLineIsBlank = false;
 +        }
 +      }
 +    }
 +    client.stop();
 +
 +    //Serial.println("client disconnected");
 +  }
 +}
 +</code>
 +
  
  
  
projekty/projektsystemupomiarowokontrolnegonabaziearduino.1746621110.txt.gz · ostatnio zmienione: 2025/05/07 14:31 przez administrator