Input Devices
This week, I will be using some new sensors for input.
1.1 Assignments of the Week
- Group assignment:
1.Probe an input device(s)'s analog levels and digital signals.
2.Document your work on the group work page and reflect on your individual page what you learned.
- Individual assignment:
1.Measure something: add a sensor to a microcontroller board that you have designed and read it.
1.2 Group Work
1.3 Individual Work
1.3.1 ultrasonic sensor
The ultrasonic sensor is a type of sensor that measures distance using the principle of ultrasonic waves. It calculates the distance to an object by emitting ultrasonic pulses and receiving their echoes. This sensor typically consists of a transmitter and a receiver and can accurately measure the distance to a target object without physical contact.
Wiring:
Coding:
I used ChatGPT to obtain sample code and made modifications for measuring ultrasonic distance and controlling a small light. The code uses the pulseIn() function to read the duration of the high pulse on the Echo pin and converts it to distance in centimeters. If the measured distance is less than or equal to 5 centimeters, it turns on the LED; otherwise, it turns off the LED.
Ultrasonic_ranging_lighting:
Video:
1.3.2 touch sensor
The capacitive touch switch module is a module that utilizes capacitive sensing principles to detect touch, commonly used for proximity sensing or switch control applications. This module can sense human proximity or touch to trigger corresponding actions or controls.
Its operation is similar to a capacitive sensor, detecting changes in capacitance in the surrounding environment to achieve touch detection. When an object (typically a human finger) approaches or touches the module, it alters the capacitive sensing state, which is then detected by the module.
Wiring:
Coding:touch_communication:
Video:
However, there was an issue with the serial communication. Without touch, the values fluctuated between 1 and 3, and when touched, they fluctuated above 1018. At first, I thought this was due to electrical noise in the environment causing the values to drift when there was no touch, so I didn't pay much attention to it. Later, my mentor Henk brought up the issue again, and suddenly I realized that the output type of the sensor might be digital. After confirming with the supplier, it turned out to be true. I then re-uploaded the code and changed the pin to a digital input pin (D0), and it worked successfully.
New code:touch_communication:
Video: