Assignments

  • Group Assignment: Probe an input device(s)'s analog levels and digital signals
  • 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.
  • All the important links are Here

    Learning outcomes

  • Demonstrate workflows used in sensing something with input device(s) and MCU board
  • Group Assignment

    For further information, please check our Group Assignment

    For this week's group task, we were tasked with using test instruments like multimeters and oscilloscopes to observe the signals produced by a sensor. We opted to test an ultrasound sensor and utilize an oscilloscope to view the signal.

    Measurement with the Oscilloscope

    Firstly, here is a little information about an oscilloscope!!

    Your Image Description

    An oscilloscope is a device used to visualize electrical signals. It converts these signals into visible waveforms, which are displayed on a screen. The oscilloscope consists of several components, including signal input probes, signal conditioning systems, vertical and horizontal.

    We were instructed to use test instruments (multimeters, oscilloscopes, etc.) to observe the signal that a sensor was producing for this week's group task. We made the decision to test an ultrasound sensor and use an oscilloscope to view the signal.

    SO lets begin by writing the Arduino code in Arduino IDE!!!

    Here is the code we used:

    
    const int pingPin = 7; // Trigger Pin of Ultrasonic Sensor
    const int echoPin = 6; // Echo Pin of Ultrasonic Sensor
    
    void setup() {
        Serial.begin(9600); // Starting Serial Terminal
    }
    
    void loop() {
        long duration, inches, cm;
        pinMode(pingPin, OUTPUT);
        digitalWrite(pingPin, LOW);
        delayMicroseconds(2);
        digitalWrite(pingPin, HIGH);
        delayMicroseconds(10);
        digitalWrite(pingPin, LOW);
        pinMode(echoPin, INPUT);
        duration = pulseIn(echoPin, HIGH);
        inches = microsecondsToInches(duration);
        cm = microsecondsToCentimeters(duration);
        Serial.print(inches);
        Serial.print("in, ");
        Serial.print(cm);
        Serial.print("cm");
        Serial.println();
        delay(100);
    }
    
    long microsecondsToInches(long microseconds) {
        return microseconds / 74 / 2;
    }
    
    long microsecondsToCentimeters(long microseconds) {
        return microseconds / 29 / 2;
    }
    
        

    Connections

    Here is how we connected our pins:

    • Echo - Digital pin 6
    • Trig - Digital pin 7
    • Gnd - Gnd
    • Vcc - Vcc

    Now connect it to the oscilloscope whereby probes are connected to Gnd and Echo pins!!

    Your Image Description

    So after a few tries of displaying the signal, here is how it looks:

    Your Image Description

    And this is how it looks in the serial monitor!

    Your Image Description

    Sound Sensor

    Your Image Description

    A sound sensor is a device that converts sound waves into an electrical signal that can be processed by an electronic circuit. They can be used to detect and measure the amplitude, frequency, and duration of sound waves. It has both analog and digital output pins. We decided to check the analog signal!

    Setting Up

    Your Image Description

    Here is the connection we made:

      Your Image Description

    Now for the code, we decided to use the analog serial example code. To find it go to files -> examples -> Analog -> AnalogInOutSerial -> then change the pins according to your connections.

    Here is the code:

    
    // These constants won't change. They're used to give names to the pins used:
    const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
    const int analogOutPin = 9; // Analog output pin that the LED is attached to
    
    int sensorValue = 0;        // value read from the pot
    int outputValue = 0;        // value output to the PWM (analog out)
    
    void setup() {
        // initialize serial communications at 9600 bps:
        Serial.begin(9600);
    }
    
    void loop() {
        // read the analog in value:
        sensorValue = analogRead(analogInPin);
        // map it to the range of the analog out:
        outputValue = map(sensorValue, 0, 1023, 0, 255);
        // change the analog out value:
        analogWrite(analogOutPin, outputValue);
    
        // print the results to the Serial Monitor:
        Serial.print("sensor = ");
        Serial.print(sensorValue);
        Serial.print("\t output = ");
        Serial.println(outputValue);
    
        // wait 2 milliseconds before the next loop for the analog-to-digital
        // converter to settle after the last reading:
        delay(2);
    }
    
        

    So the sensor does not really detect the sound waves that efficiently so here is how the serial monitor and the oscilloscope display looks like:

    Individual Assignment

  • Measure something: add a sensor to a microcontroller board that you have designed and read it.
  • For this week, I wanted to try a NTC thermistor sensor since my final project uses one. I chose to print Professor Neil's NTC thermistor board to test how a NTC thermistor works and operates.

    What is a NTC thermistor?

    Your Image Description

    10K NTC thermistor (NHQ103B375T10)

    The definition for this is chatgpt generated for its simplicity in the description

    An NTC (Negative Temperature Coefficient) thermistor is a small electronic component that changes its electrical resistance in response to changes in temperature. Unlike most materials, which become less conductive as they heat up, NTC thermistors become more conductive as the temperature rises. This unique characteristic makes them useful for measuring temperature in various applications. They're commonly found in electronic devices, automotive systems (like engine temperature sensors), and industrial equipment for monitoring and controlling temperature.

    Amphenol NTC Thermistor Sensor NHQ103B375T10

    Note that the following information are referred from mouser.com

    Overview:

    The Amphenol NHQ103B375T10 is an NTC (Negative Temperature Coefficient) thermistor sensor designed for accurate temperature sensing in various applications.

    Key Specifications:

    • Type: NTC Thermistor
    • Resistance at 25°C (R25): 10 kΩ ±1%
    • B-Value (25/50): 3750 K ±1%
    • Operating Temperature Range: -40°C to +125°C
    • Tolerance: ±1% at 25°C
    • Power Rating: 200 mW

    Features:

    • Small size and rugged construction suitable for various environments.
    • High accuracy and stability in temperature sensing applications.
    • Fast response time.

    Pin Configuration:

    • Pin 1: Connected to one end of the NTC thermistor element.
    • Pin 2: Connected to the other end of the NTC thermistor element.

    Functionality:

    The NHQ103B375T10 operates based on the principle of NTC thermistors, where the resistance decreases with an increase in temperature. This change in resistance can be accurately measured to determine the temperature in the vicinity of the sensor.

    Applications:

    • Temperature monitoring and control in industrial and consumer electronics.
    • HVAC systems.
    • Automotive applications.
    • Medical equipment.
    • Battery management systems.

    Power Requirements:

    The NHQ103B375T10 operates with a power rating of up to 200 mW, suitable for low-power applications where energy efficiency is crucial.

    Typical Connection Diagram:

    Vcc (Supply Voltage): Typically connected to a regulated voltage source.

    GND: Connected to the ground reference of the system.

    Analog Output: The analog voltage output varies with temperature and is connected to an analog input of a microcontroller or temperature monitoring circuit.

    Milling the baord

    Milling
    Image 1
    Image 2
    Image 1
    Image 2
    Components
    Your Image Description
    Soldered
    Your Image Description

    Programming

    Your Image Description

    I connected a programmable LED externally to test whether the NTC thermistor board was programmable or not.

    After that I uploaded the following code to get the following outcome

                                #include <SoftwareSerial.h>
                                
                                SoftwareSerial mySerial = SoftwareSerial(1, 0);
                                
                                int sensorPin = 3;
                                int sensorValue = 0;
                                
                                void setup() {
                                  mySerial.begin(9600);
                                }
                                
                                void loop() {
                                  sensorValue = analogRead(sensorPin);
                                  mySerial.println(sensorValue);
                                  // if (sensorValue < 500)
                                  // {
                                  //   mySerial.println(" I sensed warmth.");
                                  // }
                                  // else if (sensorValue == 1023)
                                  // {
                                  //   mySerial.println(" Reading error.");
                                  // }
                                  // else if (sensorValue >= 540)
                                  // { 
                                  //   mySerial.println(" It's cold.");  
                                  // }
                                  // else 
                                  // {
                                  //   mySerial.println(" I feel normal.");
                                  // }
                                  delay(1000);
                                }
                                

    When I touched the sensor with my finger the temperature decreased beacuse my hand was cold and increased as the heat of my finger increased.

    NTC thermistor module and DF player

    Since, the assignment requires that the board I use is one you designed

    I will be using my Final Project board for which more information is below.

    NTC thermistor Sensor Module

    Your Image Description

    Image Source

    The following information is referred from JS Electronics

    Overview:

    The NTC Thermistor Sensor is designed for precise temperature sensing in various applications.

    Key Specifications:

    • Type: NTC Thermistor
    • Resistance at 25°C (R25): 10 kΩ ±1%
    • B-Value (25/50): Not specified on the website
    • Operating Temperature Range: -40°C to +125°C
    • Tolerance: Not specified on the website
    • Power Rating: Not specified on the website

    Features:

    • Designed for accurate temperature measurement.
    • Suitable for various industrial and consumer electronics applications.
    • Compact and durable design.

    Pin Configuration:

    • Pin 1: Not specified on the website
    • Pin 2: Not specified on the website

    Functionality:

    The NTC Thermistor operates on the principle of temperature-dependent resistance, providing an analog signal proportional to the temperature.

    Applications:

    • Temperature monitoring and control systems.
    • Environmental monitoring.
    • Automotive electronics.
    • Medical devices.

    Power Requirements:

    Power requirements are typically low for NTC thermistors, suitable for battery-operated devices and low-power applications.

    Typical Connection Diagram:

    Vcc (Supply Voltage): Connect to a regulated power supply.

    GND: Connect to the ground of the system.

    Analog Output: Output voltage varies with temperature.

    DF player mini

    Your Image Description

    Image source

    The information below is referred from picaxe.com

    Overview:

    The DFPlayer Mini is a compact and low-cost MP3 player module capable of playing audio files stored on a microSD card.

    Key Specifications:

    • Supported Formats: MP3, WAV
    • Operating Voltage: 3.3V - 5V DC
    • Current Consumption: 20 mA (typical)
    • Storage: Supports up to 32 GB microSD card
    • Output Power: 3W (4Ω load) / 5W (8Ω load)
    • Output: 3.5mm stereo headphone jack and line-out pins
    • Control Interface: UART serial control or button control
    • Dimensions: 21mm x 16mm x 3.5mm

    Features:

    • Supports playback control functions: play, pause, previous, next, volume adjustment.
    • Integrated amplifier for direct speaker connection.
    • Serial communication for easy integration with microcontrollers.
    • Low power consumption suitable for battery-powered applications.

    Pin Configuration:

    • VCC: Power supply input (3.3V - 5V DC)
    • GND: Ground
    • TX: UART Transmit (connects to microcontroller RX)
    • RX: UART Receive (connects to microcontroller TX)
    • SPK1/SPK2: Speaker output or line-out (3.5mm jack or pins)

    Functionality:

    The DFPlayer Mini module allows seamless playback of audio files from a microSD card with simple control via UART or buttons, making it ideal for embedded audio applications.

    Applications:

    • Embedded audio systems
    • Interactive projects requiring audio feedback
    • DIY electronics and robotics projects
    • Educational demonstrations

    Power Requirements:

    The module operates within a voltage range of 3.3V to 5V DC with typical current consumption of 20 mA, suitable for various low-power applications.

    Connections

    Your Image Description
    Your Image Description
    Your Image Description

    Programming

    The code below is Chatgpt generated, and the prompt I used is as follows

    User:

    Write an Arduino sketch to read temperature from an NTC thermistor connected to an analog pin (A0) and control the volume of a DFPlayer Mini module based on the temperature reading. The sketch should:

    • Use the DFRobotDFPlayerMini library to communicate with the DFPlayer Mini.
    • Play audio when the temperature exceeds a defined threshold (e.g., 25°C).
    • Stop audio when the temperature drops below the threshold.
    • Allow volume adjustment via two buttons: one to increase volume (connected to digital pin 1) and another to decrease volume (connected to digital pin 2), with debounce handling.
    • Print the temperature readings and volume changes to the Serial Monitor.
    • Include necessary initialization and pin configurations.

    ChatGPT:

    "The response was,"The following code""

    
            #include 
            #include 
            #include "DFRobotDFPlayerMini.h"
            
            
            #define SENSORPIN A0                    // Analog pin connected to the analog output of the LM393 module
            #define VOLUME_UP_BUTTON_PIN 1        // Button to increase volume connected to IO1
            #define VOLUME_DOWN_BUTTON_PIN 2     // Button to decrease volume connected to IO2
            #define THRESHOLD_TEMPERATURE 25       // Temperature threshold in Celsius
            #define DEBOUNCE_DELAY 50               // Debounce delay in milliseconds
            #define AUDIO_DELAY 500                 // Delay after starting audio playback in milliseconds
            
            
            HardwareSerial MySerial0(0);
            DFRobotDFPlayerMini myDFPlayer;
            
            
            void printDetail(uint8_t type, int value);
            
            
            void setup() {
              delay(5000); // Delay for 5 seconds to allow time for initialization
              MySerial0.begin(9600, SERIAL_8N1, -1, -1); // TX=7, RX=8
              Serial.begin(115200);
            
            
              Serial.println();
              Serial.println(F("DFRobot DFPlayer Mini Demo"));
              Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
            
            
              pinMode(VOLUME_UP_BUTTON_PIN, INPUT_PULLUP);
              pinMode(VOLUME_DOWN_BUTTON_PIN, INPUT_PULLUP);
            
            
              if (!myDFPlayer.begin(MySerial0)) {
                Serial.println(F("Unable to begin:"));
                Serial.println(F("1. Please recheck the connection!"));
                Serial.println(F("2. Please insert the SD card!"));
                while (true); // Infinite loop if initialization fails
              }
              Serial.println(F("DFPlayer Mini online."));
            
            
              myDFPlayer.volume(20);  // Set volume value. From 0 to 30
            }
            
            
            float readTemperature() {
              int analogValue = analogRead(SENSORPIN);
              float voltage = analogValue * (3.3 / 4095.0);
            
            
              // Assuming a 10k NTC thermistor with a 10k resistor in a voltage divider configuration.
              float resistance = (10000.0 * voltage) / (3.3 - voltage);
            
            
              // Convert the resistance to temperature using the Steinhart-Hart equation
              float temperature = 1.0 / (0.001129148 + (0.000234125 * log(resistance)) + (0.0000000876741 * log(resistance) * log(resistance) * log(resistance)));
              temperature = temperature - 273.15; // Convert Kelvin to Celsius
            
            
              return temperature;
            }
            
            
            void loop() {
              static bool volumeUpButtonPressed = false;
              static bool volumeDownButtonPressed = false;
              static bool audioPlaying = false;
            
            
              float temperature = readTemperature();
              Serial.print("Temperature: ");
              Serial.print(temperature);
              Serial.println(" °C");
            
            
              if (temperature > THRESHOLD_TEMPERATURE && !audioPlaying) {
                Serial.println("Threshold exceeded");
                myDFPlayer.play(); // Start playing
                audioPlaying = true;
                delay(AUDIO_DELAY); // Delay after starting audio playback
              } else if (temperature <= THRESHOLD_TEMPERATURE && audioPlaying) {
                Serial.println("Threshold not exceeded");
                myDFPlayer.stop(); // Stop playing
                audioPlaying = false;
              }
            
            
              if (digitalRead(VOLUME_UP_BUTTON_PIN) == LOW && !volumeUpButtonPressed) {
                delay(DEBOUNCE_DELAY); // Debounce delay
                if (digitalRead(VOLUME_UP_BUTTON_PIN) == LOW) {
                  int currentVolume = myDFPlayer.readVolume();
                  if (currentVolume < 30) {
                    myDFPlayer.volume(currentVolume + 1);
                    Serial.print(F("Volume increased to "));
                    Serial.println(currentVolume + 1);
                  }
                  volumeUpButtonPressed = true;
                }
              } else if (digitalRead(VOLUME_UP_BUTTON_PIN) == HIGH) {
                volumeUpButtonPressed = false;
              }
            
            
              if (digitalRead(VOLUME_DOWN_BUTTON_PIN) == LOW && !volumeDownButtonPressed) {
                delay(DEBOUNCE_DELAY); // Debounce delay
                if (digitalRead(VOLUME_DOWN_BUTTON_PIN) == LOW) {
                  int currentVolume = myDFPlayer.readVolume();
                  if (currentVolume > 0) {
                    myDFPlayer.volume(currentVolume - 1);
                    Serial.print(F("Volume decreased to "));
                    Serial.println(currentVolume - 1);
                  }
                  volumeDownButtonPressed = true;
                }
              } else if (digitalRead(VOLUME_DOWN_BUTTON_PIN) == HIGH) {
                volumeDownButtonPressed = false;
              }
            
            
              delay(1000); // Wait for 1 second before reading again
            }
            
            
    Your Image Description