Interface and Application Programming

Group assignment:
Compare as many tool options as possible.
Document your work on the group work page and reflect on your individual page what you learned.

Individual assignment: Write an application for the embedded board that you made, that interfaces a user with an input and/or output device(s)

This assignment covers both output and input device communication with the interface. The devices are connected to micro-controller through breadboard as a switch. Tha application send commands to the output devices and read data from input devices and display it on the interface.
It firstly connect to the micro-controller using usb serial through web serial port.

Interface programming and communication
/*********
          Arduino IDE script
          *********/
          
          #include 
          
            #include 

              // Pins
              const int ledPin = A3;
              const int pirPin = A1;          // PIR motion sensor input
              const int tempPin = A2;        // Temperature sensor analog input (e.g., LM35)
              const int servoPin = D9;
              
              Servo myServo;
              int currentAngle = 0;
              
              void setup() {
                Serial.begin(9600);
                pinMode(ledPin, OUTPUT);
                pinMode(pirPin, INPUT);
                myServo.attach(servoPin);
                myServo.write(currentAngle);
              }
              
              void loop() {
                // Read sensors
                int pirValue = digitalRead(pirPin);
                float voltage = analogRead(tempPin) * (0.5/1023.0); // Simulated LM35
                float temperature = voltage * 10.0 *4; // LM35: 10mV/°C
              
                // Send data as JSON
                Serial.print("{\"angle\":");
                Serial.print(currentAngle);
                Serial.print(",\"temperature\":");
                Serial.print(temperature, 1);
                Serial.print(",\"motion\":\"");
                Serial.print(pirValue == HIGH ? "Detected" : "None");
                Serial.println("\"}");
              
                // Handle incoming serial commands
                if (Serial.available()) {
                  String command = Serial.readStringUntil('\n');
                  command.trim();
              
                  if (command == "1") {
                    digitalWrite(ledPin, HIGH);
                  } else if (command == "0") {
                    digitalWrite(ledPin, LOW);
                  } else if (command.startsWith("m")) {
                    int angle = command.substring(1).toInt();
                    angle = constrain(angle, 0, 180);
                    myServo.write(angle);
                    currentAngle = angle;
                  }
                }
              
                delay(1000); // Adjust rate of updates
              }
              
  1. Before connection and after


Motor angles

Temperature readings

Project connection and the components


Code files
HTML file
Arduino IDE code file