Microcontrollers : computers designed to take inout from the physical world and control output devices in the physical world-> optimized for control of physical input and output
Optical Sensors -> Light is used in many sensors in a variety of ways.
-> Light is also used in some ranging sensors to determine distance from a sensor to a target.
Ranging Sensors 1. Ultrasonic ranger 2.
Infrared ranger -> Ranging sensors read a range of distance.
MEMS Sensors -> MEMS sensors often form a variable capacitor by moving a capacitive plate in between two other capacitive surfaces.
[ Digital Input ] Digital or binary inputs to microcontrollers have two states : off and on
- Voltage flowing -> circuit is on - Voltage
not flowing -> circuit is off
[ Digital Output ] Digital or binary outputs also have two states : off and on
LAB : Digital Input & Output
Prepare The Breadboard
-> I used Uno R3 to supply power to the breadboard.
Add Digital Input (Pushbutton) -> Since the output changes depending on the state of the pushbutton, it functions as a digital input.
Add Digital Output (LED) -> Since the LED provides an immediate visual result based on the state of the switch, it functions as a digital output.
Programming Arduino
1. Setup -> I set the three pins what I’m using as inputs/outputs
2. Using The Pushbotton -> digitalRead(pin);
•Purpose: This function is used to read the state of a digital pin, determining if it’s HIGH or LOW.
•Parameters: - pin: The pin number you want to read from.
•Returns: - HIGH if the pin is at a high voltage level. - LOW if the pin is at a low voltage level.
•Usage: Used to read the state of digital input devices like buttons, switches, or sensors.
-> digitalWrite(pin, value);
•Purpose: This function is used to set a digital pin to a HIGH or LOW state, essentially turning it on or off.
•Parameters:
- pin: The pin number you want to write to.
- value: Either HIGH or LOW. HIGH sets the pin to a high voltage level (typically 5V or 3.3V, depending on the board), and LOW sets it to a low voltage level (0V).
•Usage: Used to control digital output devices like LEDs, relays, and digital motors.
-> When the pushbutton is not pressed, the blue LED lights up, and when the pushbutton is pressed, the yellow LED turns on. If I swap the HIGH and LOW values in the digitalWrite for each LED, the opposite result will occur.
LAB : Analog Input
Setting Up Breadboard
-> I used Uno R3 to supply power to the breadboard.
Adding Potentiometer & LED
-> At first, I didn't know which direction to insert the potentiometer, but Sky explained that the direction in which it is inserted or the order in which wires are connected affects the direction of the values output when turning the potentiometer.
Programming Module
1. Establishing Global Variables -> int :
• This declares a normal integer variable.
• The value of this variable can be changed at any point in the code.
-> const int :
• This declares a constant integer variable.
• The value of this variable is set at the time of initialization and cannot be changed later in the code.
2. Setup
-> Before using functions like Serial.print(), Serial.read(), or Serial.write() to send and receive data through the serial port, I need to initialize it with Serial.begin().
3-1. Main Loop (LED)
First Try - failed...
-> When I turned the potentiometer, the numbers displayed correctly on the serial monitor, but the LED didn't gradually change in brightness. Instead, it flickered on and off at a certain point. Since the code had no errors, I asked Sky what might be wrong, and he suggested it could be an issue with the LED itself.
Second Try - It worked!! 🥳 🎉 -> So, I tried using a new LED. Both the LED and the serial print worked correctly this time. It was indeed an issue with the LED.
Lighting up LED with Force-Sensing Resistor
1. Making A Circuit -> I'm trying to build circuits on a breadboard by only looking at schematics, but since I'm not fully familiar with them yet, it takes a long time or I end up making incorrect connections. I believe that as I practice more, I'll gradually understand schematics better. 🥲
2. Finding Sensor Range
-> map() : -
used to re-map a number from one range to another. This is useful when I need to convert a value from one scale to another, such as translating the input from a sensor to a range suitable for an output device.
• value: The number you want to re-map.
• fromLow: The lower bound of the value’s current range.
• fromHigh: The upper bound of the value’s current range.
• toLow: The lower bound of the desired range.
• toHigh: The upper bound of the desired range.
-> I observed that the values displayed on the serial monitor change in real-time according to the force applied to the force sensor. Simultaneously, the brightness of the LED linked to each sensor also increases or decreases depending on the amount of force applied.
LAB : Sensor Change Detection
Setting Up Breadboard
-> I used Uno P3 to supply power to the breadboard.
Adding Pushbutton
-> It was quite a simple circuit just using one pushbutton.
Programming Microcontroller
1. Reading Pushbutton’s State Change
-> I was able to see the message "Button was just pressed." displayed on the serial monitor each time the button was pressed.
Long Press & Short Press
1. Establishing Global Variables
2. Setup
3. Loop
-> The code became long and complicated, so it took a long time to understand...
-> millis() :
function that returns the number of milliseconds that have passed since the Arduino board started running the current program.
-> When the button was tapped very briefly, "Tap" was displayed on the serial monitor; for a short press, "Short press" appeared, and for a long press, "Long press" was shown.