Week 10

Output devices

Learning outcomes

  • Demonstrate workflows used in controlling an output device(s) with MCU board you have designed
Week 3 cover

Assignment requirements

Group assignment

  • Measure the power consumption of an output device
  • Document your work on the group work page and reflect on your individual page what you learned

Individual assignment

  • Measure something: add a sensor to a microcontroller board that you have designed and read it

Progress status

Group work Done

Test an output device and measure power consumption

Individual work In progress

Measure the power consumption of an output device

Documentation Done

Upload source files

1) Introduction

Closing gaps

  • Learn about output devices
  • Interact more with Arduino IDE
  • Discuss the group project
  • Develop the individual project
Step right image

2) Group assignment 1 - Test an output device

For more details visit Fab Lab Peru Week 10 Group assignment


Problems

Designed microcontroller board doesn't work

Review connections

Step 1 - Protoboard

Mesasure something with the microcontroller RP2040

Running 1
Reviewing output devices on lab
Running 2
Reviewing other projects
Running 3
Testing cables
Running 4
Connection with screen - download RP 2040 libraries
Swimming 2
Arduino Ide Code
Swimming 2
Uploading code to the Xiao RP 2040
Camera 1
Uploading code to the Xiao RP 2040
// Programming LCD + I2Cing three TCRT5000L reflective optical sensor
                       // Board: Seeed Studio XIAO RP 2040

                #include  
                #include 

                // Set the LCD address to 0x27 for a 16 chars and 2 line display
                // If 0x27 doesn't work, try 0x3F. You may need an I2C scanner.
                LiquidCrystal_I2C lcd(0x27, 16, 2); 

                void setup() {
                  Wire.setSDA(D4); //D4
                  Wire.setSCL(D5); //D5
                  // Initialize the I2C bus
                   Wire.begin(); 
                  
                  // Initialize the LCD screen
                  lcd.init();

                  // Turn on the backlight
                  lcd.backlight();
                  
                  // Set the cursor to column 0, row 0 (0-indexed)
                  lcd.setCursor(0, 0);
                  // Print a message to the LCD.
                  lcd.print("Fab Academy");
                  
                  // Set the cursor to column 0, row 1
                  lcd.setCursor(0, 1);
                  lcd.print("Fab Academy Peru");
                }

                void loop() {
                  // Main loop is empty, display updates once in setup
          }

            
Camera 1
Connecting multimeter
Camera 1
Measuring voltage
Camera 1
Measuring voltage and changing resistance
Camera 1
Multimeter in use
Video demonstration

3) Individual assigment

Problems

Designed microcontroller board doesn't work

Posible solution - make a new board

Step 1 - Protoboard

Mesasure something with the microcontroller Xiao ESP32 C3

Step 2 - Repeat with a new board

Measure and test devices using a multimeter or an oscilloscope

Swimming 2
Considering last week's assignment - input: test with three sensors: left - center - right
Camera 1
Connections at Xiao ESP 32 C3 using the protoboard
// Using three TCRT5000L reflective optical sensor
            // Input devices 
            // Board: Seeed Studio XIAO ESP 32 C3

              #define sensor1 D6   // cambia al GPIO/pin que uses
              #define sensor2 D5   // cambia al GPIO/pin que uses
              #define sensor3 D4   // cambia al GPIO/pin que uses

              void setup() {
                  Serial.begin(115200);
                  pinMode(sensor1, INPUT);  
                  pinMode(sensor2, INPUT);  
                  pinMode(sensor3, INPUT);  
              }

              void loop() {
                  int val1 = digitalRead(sensor1);
                  int val2 = digitalRead(sensor2);
                  int val3 = digitalRead(sensor3);
            
              if(val1==1){
                  Serial.println("izquierda");
                  }
              else if(val2==1){
                  Serial.println("centro");
               }
              else if(val3==1){
                   Serial.println("derecha");
              }
              else{
                    Serial.println("error");
              }
              delay(100);
              }

            
Camera 2
Testing devices
Camera 1
Using three TCRT5000L reflective optical sensor & buzzer output
// Using three TCRT5000L reflective optical sensor & buzzer - Center or not
              // Input devices 
              // Board: Seeed Studio XIAO ESP 32 C3

              #define sensor1 D6   // cambia al GPIO/pin que uses
              #define sensor2 D5   // cambia al GPIO/pin que uses
              #define sensor3 D4   // cambia al GPIO/pin que uses


              void setup() {
                  Serial.begin(115200);
                  pinMode(sensor1, INPUT);  
                  pinMode(sensor2, INPUT);  
                  pinMode(sensor3, INPUT);  
                  pinMode(D3, OUTPUT);
              }

              void loop() {
                int val1 = digitalRead(sensor1);
                int val2 = digitalRead(sensor2);
                int val3 = digitalRead(sensor3);
                if(val1==1){
                  Serial.println("izquierda");
                    digitalWrite (D3, HIGH);
                    delayMicroseconds (5000);
                    digitalWrite (D3, LOW);
                    delayMicroseconds (100000);
                }
                else if(val2==1){
                  Serial.println("centro");
                }
                else if(val3==1){
                  Serial.println("derecha");
                    digitalWrite (D3, HIGH);
                    delayMicroseconds (5000);
                    digitalWrite (D3, LOW);
                    delayMicroseconds (100000);
                }
                else{
                  Serial.println("error");
                    digitalWrite (D3, HIGH);
                    delayMicroseconds (5000);
                    digitalWrite (D3, LOW);
                    delayMicroseconds (100000);
                }
                delay(100);
              }
            
Camera 1
Using A PIR sensor (Passive Infrared sensor) is a device that detects motion by sensing changes in heat in its surroundings. People, animals, and other warm objects naturally give off infrared energy, and when they move, the sensor notices the change in the heat pattern
Camera 1
The PIR receives heat, which is why it is called passive. Inside the sensor are special materials that react to infrared radiation and a lens that helps focus the heat from different areas. PIR sensors are widely used in security systems, automatic lighting, smart home devices, and energy-saving applications because they are reliable, low power, and inexpensive
Camera 1
Arduino code for PIR sensor
// Using PIR sensor and led for testing
              // Input devices 
              // Board: Seeed Studio XIAO ESP 32 C3

                    #define PIR_PIN 2
                    #define LED_PIN 10
                    #define LED_PIN2 3

                    void setup() {
                      Serial.begin(115200);

                      pinMode(PIR_PIN, INPUT);
                      pinMode(LED_PIN, OUTPUT);
                      pinMode(LED_PIN2, OUTPUT);

                      Serial.println("PIR Sensor Initializing...");
                      delay(60000); // 1 minute stabilization
                      Serial.println("Ready!");
                    }

                    void loop() {
                      int motion = digitalRead(PIR_PIN);

                      

                      if (motion == HIGH) {
                        Serial.println("Motion detected!");
                        digitalWrite(LED_PIN, LOW);   // ON (inverted logic)
                        digitalWrite(LED_PIN2, HIGH);
                      } else {
                        Serial.println("No motion");
                        digitalWrite(LED_PIN, HIGH);  // OFF
                        digitalWrite(LED_PIN2, LOW);
                      }

                      delay(500);
                    }
            
Camera 1
Connecting HC-SR04 and OLED
Camera 1
Setting HC-SR04 and OLED
Camera 1
Testing HC-SR04 and OLED
Camera 1
Arduino code for HC-SR04 and OLED
Camera 1
Final test
Camera 1
Final test with PCB
// HC-SR04 sensor & OLED display
              // Input devices 
              // Board: Seeed Studio XIAO ESP 32 C3

                  #include 
                  #include 

                  #define TRIG_PIN 3
                  #define ECHO_PIN 4

                  U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);

                  void setup() {
                    Serial.begin(115200);

                    pinMode(TRIG_PIN, OUTPUT);
                    pinMode(ECHO_PIN, INPUT);

                    Wire.begin(6, 7); // SDA, SCL
                    u8g2.begin();
                  }

                  long readDistance() {
                    digitalWrite(TRIG_PIN, LOW);
                    delayMicroseconds(2);

                    digitalWrite(TRIG_PIN, HIGH);
                    delayMicroseconds(10);
                    digitalWrite(TRIG_PIN, LOW);

                    long duration = pulseIn(ECHO_PIN, HIGH);
                    long distance = duration * 0.034 / 2;

                    return distance;
                  }

                  void loop() {
                    long distance = readDistance();

                    Serial.print("Distance: ");
                    Serial.print(distance);
                    Serial.println(" cm");

                    u8g2.clearBuffer();

                    if (distance < 20) {
                      u8g2.setFont(u8g2_font_logisoso24_tr);
                      u8g2.drawStr(0, 40, "CLOSE!");
                    } else {
                      u8g2.setFont(u8g2_font_ncenB08_tr);
                      u8g2.drawStr(0, 25, "Distance:");

                      char buf[20];
                      sprintf(buf, "%ld cm", distance);
                      u8g2.drawStr(0, 50, buf);
                    }

                    u8g2.sendBuffer();

                    delay(300);
                  }
            
Video demonstration

Project - LM 393 Photosensitive light dependent resistor (LDR)

4) Final project advance

Devices

GP2Y0A21YK0F Sharp, infrared distance sensor, 10-80 cm

GP2Y0A02YK0F Sharp, infrared distance sensor, 20-150 cm

2Y0A710K Sharp, infrared distance sensor, 100 a 550cm

Camera 1
Sharp, line detector, screen
Camera 2
Grove- Vision AI Module V2, camera and signal sensort
Final project page

5) Final results

  • Linked to the group assignment page
  • Documented how you determined power consumption of an output device with your group
  • Documented what you learned from interfacing output device(s) to microcontroller and controlling
  • Linked to the board you made in a previous assigment or documented your design and fabrication
  • Explain how your code works
  • Explained any problems you encountered and how you fixed them
  • Include original source code and any design files
  • Included a 'hero shot' of your board

6) References files

We learn how to design, make and test a PCB with sensor. Files: in each section

Sections