The microcontroller acts as the central unit that coordinates the robot's actions by collecting
information from input devices, executing programmed instructions, and controlling output
devices. Here's how it works:
   1. Collecting Information from Input Devices (Sensors):
         o Sensors (such as temperature sensors, distance sensors, or light sensors) detect
             changes in the environment or the robot itself.
         o The microcontroller reads data from these sensors to understand the robot's
             surroundings or its own state. For example, a distance sensor might detect the
             proximity of an object, while a temperature sensor could monitor the robot's
             operating temperature.
   2. Executing a Program:
         o Based on the data it receives from sensors, the microcontroller executes a pre-
             programmed set of instructions (or algorithm). This program dictates how the
             robot should react to different sensor inputs. For instance, if the distance sensor
             detects an object too close, the robot might be programmed to stop or change
             direction.
   3. Controlling Output Devices:
         o After processing the sensor information, the microcontroller sends commands to
             output devices, such as:
                  LED lights: These can signal different states, such as the robot being
                     active, indicating a warning, or showing the status of a specific process.
                  Sound Devices: Speakers or buzzers can be used to produce sounds, like
                     beeps or alarms, to alert users or signify different robot states.
                  Motors and Actuators: Based on the program, the microcontroller may
                     also control motors for movement or servos to perform actions like lifting
                     or rotating.
In essence, the microcontroller is the brain of the robot, taking input from the environment
through sensors, making decisions based on its program, and using output devices like lights and
sounds to communicate and act upon those decisions.
Common microcontroller ports are used to connect the microcontroller to other devices, power
sources, and communication systems. Here are some of the most common ports:
   1. Power Port:
         o Purpose: Provides the necessary voltage and current for the microcontroller to
             operate.
         o Types: Typically, a DC power jack, USB power port, or pin headers for
             external power supply connections.
         o Common Examples: 5V, 3.3V pins, or a dedicated power input port on the
             board.
   2. USB Port:
         o Purpose: Used for communication between the microcontroller and a computer or
             other USB-enabled devices. It can also provide power to the microcontroller.
         o Types: Standard USB Type-B, Micro USB, or USB-C connectors.
         o Common Examples: Arduino boards often use USB Type-B or Micro USB
             ports for programming and power.
   3. Wireless Port:
         o Purpose: Allows the microcontroller to communicate wirelessly with other
             devices over Wi-Fi, Bluetooth, or other wireless communication protocols.
         o Types: Bluetooth (e.g., HC-05/HC-06 module), Wi-Fi (e.g., ESP8266, ESP32),
             RF (Radio Frequency), or Zigbee.
         o Common Examples: The ESP8266 or ESP32 microcontrollers have built-in Wi-
             Fi, while other microcontrollers like Arduino may require external wireless
             modules.
   4. Input Ports:
         o Purpose: Used to receive signals from external devices or sensors (like
             temperature sensors, buttons, or switches).
         o Types: Digital input pins, Analog input pins, or specialized sensor input ports.
         o Common Examples: The Arduino has digital and analog pins for inputs. GPIO
             (General Purpose Input/Output) pins are often used for simple digital input
             (e.g., a push button).
   5. Output Ports:
         o Purpose: Used to send signals or control external devices like LEDs, motors, or
             relays.
         o Types: Digital output pins, PWM (Pulse Width Modulation) output pins, or
             specific ports for controlling external devices.
         o Common Examples: LEDs, motors, and displays are controlled through digital
             output pins or PWM pins. The Arduino has pins labeled as D1, D2, etc. for
             digital outputs and A0, A1, etc. for analog outputs.
Each of these ports plays a crucial role in connecting the microcontroller to other systems and
devices, allowing it to interact with the environment and perform tasks based on the program it
runs.
The actuator system is responsible for converting energy (typically electrical) into mechanical
movement or action. The main parts of an actuator system include:
   1. Switch:
         o Purpose: A switch controls the operation of the actuator by turning it on or off. It
             acts as an input device to initiate or stop the movement.
         o Types: Push-button switches, toggle switches, limit switches, or relays.
   2. Motor:
         o Purpose: The motor is the core component that drives movement in the actuator
             system. It converts electrical energy into mechanical motion.
         o Types:
                  DC Motor: Provides continuous rotation in one direction.
                  Stepper Motor: Moves in discrete steps, allowing precise control over
                     positioning.
                  Servo Motor: Provides precise angular movement within a limited range.
                  AC Motor: Runs on alternating current and is typically used for higher
                     power applications.
   3. Power Supply:
         o Purpose: The power supply provides the necessary electrical energy to drive the
             motor and switch. It could be a battery, power adapter, or another source of
             energy.
         o Types: DC power supply, AC power supply, or batteries.
   4. Controller:
         o Purpose: The controller (like a microcontroller or PLC) sends signals to the
             motor to determine the direction, speed, and timing of movement.
         o Types: Arduino, Raspberry Pi, PLC (Programmable Logic Controller), or
             other control circuits.
   5. Driver Circuit:
         o Purpose: The driver circuit controls the flow of current to the motor. It acts as an
             interface between the low-power control signal from the microcontroller and the
             high-power needs of the motor.
         o Types: H-Bridge motor driver for controlling motor direction, PWM drivers
             for speed control.
   6. Mechanical Linkage:
         o Purpose: The mechanical linkage transmits the movement from the motor to the
             desired action, such as rotating a wheel, lifting a lever, or moving a robotic arm.
         o Types: Gears, belts, chains, levers, or couplings.
These parts work together to create controlled movement or action in an actuator system,
enabling robots or machines to perform physical tasks.
An actuator is a crucial component in robotics that transforms electrical power into
mechanical power, enabling the robot to move or perform actions. It acts as the "muscle" of the
robot, converting electrical signals from the microcontroller into physical movement.
How an Actuator Works:
   1. Receives Electrical Power
         o The actuator is powered by a battery or external power supply.
         o The microcontroller sends control signals to regulate movement.
   2. Converts Electrical Energy into Motion
         o The actuator (such as a motor, solenoid, or hydraulic piston) converts the
            electrical energy into rotational or linear motion.
         o Example: A DC motor rotates a wheel, or a servo motor moves a robotic arm.
   3. Enables the Robot to Perform Functions
         o Robots use actuators to walk, grab objects, rotate, lift, or push.
         o For example:
                 Wheels driven by motors allow a robot to move.
                 A robotic arm with servo motors can pick and place objects.
                 A robotic gripper with actuators can open and close.
Types of Actuators in Robotics:
      Electric Actuators (e.g., DC motors, stepper motors, servo motors)
      Pneumatic Actuators (use compressed air for movement)
      Hydraulic Actuators (use fluid pressure for movement)
      Piezoelectric Actuators (use electrical charge to create precise movement)
In summary, actuators are essential for transforming electrical energy into physical action,
allowing robots to interact with the world and complete tasks.
A sensor is a device that detects changes in its environment and provides data to the
microcontroller for decision-making. Sensors help robots perceive their surroundings by
measuring various physical properties such as light intensity, distance, and angle.
How a Sensor Works:
   1. Detects a Change in the Environment
         o The sensor picks up variations in physical conditions like light, temperature, or
             motion.
   2. Converts the Information into an Electrical Signal
         o The detected change is transformed into an electrical signal, which is sent to the
             microcontroller.
   3. Microcontroller Processes the Data
         o The microcontroller reads the sensor input and decides how the robot should
             react.
Examples of Sensors and What They Detect:
   1. Light Sensor (LDR - Light Dependent Resistor)
         o Detects light intensity (e.g., used in automatic lights or robots that follow light
             sources).
   2. Ultrasonic Sensor (HC-SR04)
         o Measures distance by sending sound waves and detecting their reflection (used in
             obstacle-avoiding robots).
   3. Gyroscope Sensor (MPU6050)
         o Detects angle and orientation (used in balancing robots, drones, and motion
             control systems).
Why Sensors are Important in Robotics
      Help robots navigate and avoid obstacles.
      Enable automatic responses (e.g., turning on lights in the dark).
      Improve precision in robotic arms and self-balancing systems.
In summary, sensors allow a robot to perceive its environment by detecting changes in light,
distance, and angle, enabling it to respond intelligently.
Functions of Different Types of Sensors in Robotics
Sensors help robots understand and interact with their environment by detecting different
physical changes. Here are the functions of light, sound, and gyroscope sensors:
   1. Light Sensor (e.g., LDR - Light Dependent Resistor, Photodiode)
         o Function: Detects the intensity of light.
         o Uses:
                 Enables robots to follow or avoid light (e.g., solar tracking systems).
                 Helps in automatic lighting control (e.g., streetlights turning on at night).
                 Used in barcode scanners and optical sensors.
   2. Sound Sensor (e.g., Microphone, Ultrasonic Sensor)
         o Function: Detects sound waves or vibrations.
         o Uses:
                 Helps in voice recognition for voice-controlled robots.
                 Detects nearby objects using ultrasonic waves (e.g., ultrasonic distance
                    sensors in obstacle avoidance robots).
                 Used in noise monitoring systems.
   3. Gyroscope Sensor (e.g., MPU6050, IMU Sensor)
         o Function: Measures angular velocity, orientation, and tilt.
         o Uses:
                 Helps robots balance (e.g., self-balancing robots, Segways, drones).
                 Used in motion tracking (e.g., virtual reality, gaming).
                 Helps detect direction changes in navigation systems.
Why These Sensors Are Important in Robotics
      Light sensors help robots detect day/night conditions or follow light sources.
      Sound sensors enable robots to react to sound commands or detect obstacles.
      Gyroscope sensors ensure robots maintain stability and correct movement.
Each sensor plays a critical role in enhancing the robot’s intelligence and interaction with its
surroundings.
Parts of a Robot That Support Motion
Robots use various components to enable movement and perform tasks. Here are the main parts
that support motion:
   1. Wheels
         o Function: Provide mobility, allowing the robot to move forward, backward, and
            turn.
         o Types:
                 Standard wheels – Common for ground robots.
                 Omnidirectional wheels – Allow movement in multiple directions.
                 Tank tracks – Used for rough terrains.
         o Example: Used in line-following robots, obstacle-avoiding robots, and
            autonomous vehicles.
   2. Arms
         o Function: Provide controlled movement for picking, placing, or manipulating
            objects.
         o Types:
                 Robotic arms – Used in industrial automation.
                 Humanoid arms – Mimic human movements for advanced tasks.
         o Example: Found in robotic arms in factories, prosthetic arms, and space
            exploration robots.
   3. Legs
         o Function: Enable walking or climbing movements, often in humanoid or
            quadruped robots.
         o Types:
                 Bipedal legs – Two-legged robots (e.g., humanoid robots).
                 Quadruped legs – Four-legged robots (e.g., robotic dogs).
         o Example: Used in Boston Dynamics’ robots, humanoid robots, and rescue
            robots.
   4. Actuators
         o Function: Convert electrical energy into mechanical motion for movement.
         o Types:
                 Motors – Drive wheels, arms, and other moving parts.
                 Pneumatic or hydraulic actuators – Use air or fluid pressure for
                    movement.
         o Example: Found in robotic arms, motorized wheels, and industrial machines.
   5. Joints
          o    Function: Allow controlled movement in arms, legs, and other parts.
          o    Types:
                   Rotational joints – Enable twisting or turning motions.
                   Linear joints – Allow straight movements.
          o    Example: Used in robotic arms, humanoid robots, and industrial robots.
Why Motion Parts Are Important
      Wheels provide efficient movement on surfaces.
      Arms allow robots to interact with objects.
      Legs help in uneven terrain movement.
      Actuators and joints enable controlled and precise movement.
Together, these parts allow robots to perform tasks ranging from simple movement to
complex manipulations.
Power Sources for Robots
Robots need a reliable power source to function. Here are common power sources used in
robotics:
   1. Batteries
         o Function: Store and supply electrical energy to power the robot’s components.
         o Types:
                 Lithium-ion (Li-ion) – Common in modern robots due to high energy
                   density and rechargeable capability.
                 Nickel-metal hydride (NiMH) – Used in some small robots, rechargeable
                   but with lower capacity than Li-ion.
                 Lead-acid – Used in large robots and industrial applications, heavy but
                   cost-effective.
         o Example: Used in mobile robots, drones, and humanoid robots.
   2. Solar Power
         o Function: Converts sunlight into electricity using solar panels.
         o Uses:
                 Ideal for robots operating in outdoor environments.
                 Reduces dependency on traditional power sources.
         o Example: Used in space exploration robots (e.g., Mars rovers), solar-powered
             drones, and environmental monitoring robots.
   3. Direct Power Supply (Plug-in)
         o Function: Provides continuous power by connecting the robot to a wall socket.
         o Uses:
                   Used in robots that do not require mobility.
                   Common in industrial robots and robotic arms in factories.
         o Example: Used in automated manufacturing robots, welding robots, and lab-
            based robotic systems.
   4. Fuel Cells
         o Function: Converts hydrogen or other fuels into electricity, providing long-
            lasting power.
         o Uses:
                  Suitable for high-power applications.
                  Used in experimental and advanced robotics.
         o Example: Used in autonomous underwater robots and experimental military
            robots.
   5. Capacitors and Supercapacitors
         o Function: Store and release energy quickly, often used alongside batteries.
         o Uses:
                  Helps with power surges in robotic systems.
                  Improves efficiency in energy storage.
         o Example: Used in high-speed robotic systems and emergency backup power.
Why Power Sources Are Important in Robotics
      Batteries provide mobility and flexibility.
      Solar power is sustainable and useful for outdoor robots.
      Direct power supply ensures continuous operation for stationary robots.
      Fuel cells and capacitors enhance efficiency in high-power applications.
Choosing the right power source depends on the robot’s size, function, and operating
environment.
Elements of a Control System in Robotics
A control system is responsible for managing the operation of a robot by processing inputs and
generating appropriate outputs. The main elements include:
   1. Input (Sensor or User Command)
         o Provides data or instructions to the system.
         o Example: A sensor detecting an obstacle or a user pressing a button.
   2. Controller (Microcontroller or Processor)
         o Processes input data and decides the action.
          o Example: An Arduino or Raspberry Pi computing movement commands.
   3. Actuator (Motor, Servo, Hydraulic System)
         o Converts electrical signals into motion or physical action.
         o Example: A motor rotating wheels or a robotic arm moving.
   4. Output (Response of the Robot)
         o The result of the control system’s action.
         o Example: The robot turning left to avoid an obstacle.
   5. Feedback (Only in Closed-Loop Systems)
         o Information sent back to the controller to adjust the response.
         o Example: A speed sensor ensuring a motor maintains the correct speed.
Basic Types of Control Systems
   1. Open-Loop Control System
         o Definition: A system that performs an action without feedback.
         o How it works:
                The controller sends a signal to the actuator.
                The action happens without checking if it was correct.
         o Example:
                A washing machine runs for a set time without sensing if clothes are
                  clean.
                A light switch simply turns a light on or off.
   2. Closed-Loop Control System
         o Definition: A system that monitors feedback and adjusts actions based on it.
         o How it works:
                The controller receives input from sensors.
                If the output is incorrect, the system adjusts its action.
         o Example:
                A thermostat adjusts the temperature by turning heating on or off.
                A self-balancing robot continuously checks its tilt angle and adjusts
                  motors.
Why Control Systems Are Important in Robotics
      Open-loop systems are simple and work for predictable tasks.
      Closed-loop systems improve accuracy and adaptability in robots.
      Most advanced robots use closed-loop control for better performance.
Would you like examples of control systems in a specific type of robot? 😊
Recognizing Connections to a Microcontroller
A microcontroller is the brain of a robot, controlling inputs and outputs. It connects to various
components to function properly.
Common Microcontroller Connections
   1. Button (Input Device)
         o Function: Sends a signal when pressed, triggering an action.
         o Connection: Connected to digital input pins.
         o Example: A start button for a robot or a reset button.
   2. Power Supply
         o Function: Provides electrical energy to the microcontroller.
         o Connection:
                 Battery pack (connected via a power input port).
                 USB cable (provides power and data transfer).
                 External adapter (for continuous power supply).
   3. Motor (Actuator)
         o Function: Converts electrical energy into mechanical motion.
         o Connection: Connected to motor driver pins (H-bridge or motor driver module
            required).
         o Example: Motors for wheels, robotic arms, or fans.
   4. USB Input
         o Function: Allows data transfer between the microcontroller and a computer.
         o Connection: Connected to a USB port.
         o Example: Used for programming and debugging (e.g., Arduino or Raspberry Pi).
   5. Wireless Technology (Communication Module)
         o Function: Enables wireless control and communication.
         o Connection: Uses UART, SPI, or I2C pins.
         o Types:
                 Wi-Fi module (ESP8266, ESP32) for internet connectivity.
                 Bluetooth module (HC-05, HC-06) for remote control.
                 RF module for radio frequency communication.
   6. Sensors (Input Devices)
         o Function: Detects environmental changes and sends data to the microcontroller.
         o Connection:
                 Analog sensors (connected to analog input pins, A0-A5).
                 Digital sensors (connected to digital pins).
         o Example:
                 Ultrasonic sensor (distance measurement).
                 Light sensor (detects brightness).
                 Temperature sensor (monitors heat levels).
   7. Output Devices (Actuators & Displays)
         o Function: Performs actions based on microcontroller signals.
         o Connection: Connected to digital output pins (PWM, GPIO).
         o Examples:
                     LEDs (visual output).
                     Buzzer (sound output).
                     LCD display (shows text or data).
Why These Connections Are Important
      Inputs (buttons, sensors) collect data for decision-making.
      Outputs (motors, LEDs, buzzers) allow the robot to respond to commands.
      Power and communication (USB, wireless) ensure proper operation and control.
Would you like a simple circuit example for one of these connections? 😊
Here’s a simple block diagram representing the connections to a microcontroller:
            +---------------------------------+
            |        Microcontroller          |
            +---------------------------------+
                   |       |       |       |
         ----------|       |       |       |----------
       |           |       |       |       |          |
+------------+ +----+ +-----+ +------+ +------------+
|   Power     | |USB | |Button| |Motor | |        Sensor |
| (Battery) | |Port| |(Input)| |(Actuator)| |(Input Device)|
+------------+ +----+ +-----+ +------+ +------------+
                                                |
                                           +-------+
                                           |Output |
                                           |(LED, |
                                           |Buzzer)|
                                           +-------+
Explanation of the Diagram
   1. Power Source (Battery or Adapter)
         o Connects to the power input of the microcontroller to supply energy.
   2. USB Port
         o Used for programming and data transfer with a computer.
   3. Button (Input Device)
         o Connected to a digital input pin to send signals when pressed.
   4. Motor (Actuator)
         o Connected via a motor driver to control movement.
   5. Sensor (Input Device)
         o Connected to an analog or digital input pin to send environmental data.
         o Examples: Temperature sensor, ultrasonic sensor, light sensor.
   6. Output Devices (LED, Buzzer, Display)
         o Connected to digital output pins to provide feedback.
         o Example: LED for indication, buzzer for sound alerts.
How It Works
       Inputs (button, sensors) send signals to the microcontroller.
       The microcontroller processes the data and controls outputs (motors, LEDs, buzzers).
       The power source ensures everything functions.
       USB and wireless connections enable communication with external devices.
Would you like a more detailed diagram with specific components labeled? 😊
Setting Up a Simple Control System Using Power, Motor, and Sensors
This setup will create a basic obstacle-avoiding robot using a microcontroller, a motor, and an
ultrasonic sensor.
Components Needed
   1.   Power Source: 9V battery or rechargeable Li-ion battery.
   2.   Microcontroller: Arduino Uno (or any similar board).
   3.   Motor: DC motor with an H-Bridge motor driver (L298N).
   4.   Sensor: Ultrasonic sensor (HC-SR04) for obstacle detection.
   5.   Connections: Jumper wires and a breadboard.
Wiring Diagram
             +---------------------------+
             |       Microcontroller       |
             +---------------------------+
                 |       |       |
         ------|             |       |------
       |        |            |       |       |
+------------+         +------+ +--------+ +------------+
|   Power     |        |Sensor| | Motor | | Motor Driver |
| (Battery) |          |(HC-SR04) |(DC)    | | (L298N)     |
+------------+         +------+ +--------+ +------------+
Step-by-Step Setup
1. Connect the Power Source
       Connect the battery (9V or Li-ion pack) to the Vin and GND of the Arduino.
       If using an L298N motor driver, connect the battery to its VCC and GND terminals.
2. Connect the Ultrasonic Sensor (HC-SR04) to Arduino
Ultrasonic Sensor Arduino Pin
VCC                  5V
GND                  GND
Trig (Trigger)       Digital Pin 9
Echo                 Digital Pin 10
3. Connect the DC Motor to the L298N Motor Driver
Motor Driver (L298N) Arduino Pin
IN1 (Motor Control)       Digital Pin 5
IN2 (Motor Control)       Digital Pin 6
Enable A (PWM)            Digital Pin 3
Motor Output A            Motor Terminals
4. Upload Code to Arduino
Here is a simple Arduino sketch for controlling the motor based on sensor input:
const   int      trigPin = 9;         //   Ultrasonic Trigger Pin
const   int      echoPin = 10;        //   Ultrasonic Echo Pin
const   int      motor1 = 5;          //   Motor Driver Input 1
const   int      motor2 = 6;          //   Motor Driver Input 2
const   int      enableMotor =        3;   // Motor speed control
void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(motor1, OUTPUT);
  pinMode(motor2, OUTPUT);
    pinMode(enableMotor, OUTPUT);
    Serial.begin(9600);
}
void loop() {
  long duration;
  int distance;
    // Send ultrasonic pulse
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    // Read echo time
    duration = pulseIn(echoPin, HIGH);
    distance = duration * 0.034 / 2; // Convert time to distance (cm)
    Serial.print("Distance: ");
    Serial.println(distance);
    if (distance > 10) { // If no obstacle, move forward
      digitalWrite(motor1, HIGH);
      digitalWrite(motor2, LOW);
      analogWrite(enableMotor, 150); // Control speed
    } else { // If obstacle detected, stop
      digitalWrite(motor1, LOW);
      digitalWrite(motor2, LOW);
    }
    delay(100);
}
How It Works
     1.   The ultrasonic sensor detects objects in front of the robot.
     2.   If the distance is greater than 10 cm, the motor runs (robot moves forward).
     3.   If an obstacle is detected (less than 10 cm), the motor stops.
     4.   The microcontroller processes sensor data and controls the motor accordingly.
Why This is a Simple Control System
✅ Power Source: Provides energy to the system.
✅ Sensor (Ultrasonic): Detects obstacles.
✅ Microcontroller (Arduino): Processes sensor input and makes decisions.
✅ Actuator (Motor): Moves the robot based on sensor data.
Would you like modifications, such as making the robot turn when detecting an obstacle? 😊
Running Pre-defined Programs to Provide Output Values (Light Intensity,
Sound, Distance, Angle)
Below are simple Arduino programs to measure and display values from different sensors:
1. Measure Light Intensity (LDR Sensor)
Hardware Required:
       LDR (Light Dependent Resistor)
       10KΩ Resistor
       Arduino Board
Connections:
  LDR Pin                    Arduino Pin
One side (VCC) 5V
Other side     Analog Pin A0 (with 10KΩ resistor to GND)
Code:
const int LDR_PIN = A0; // LDR connected to A0
void setup() {
  Serial.begin(9600);
}
void loop() {
  int lightValue = analogRead(LDR_PIN); // Read light intensity
  Serial.print("Light Intensity: ");
  Serial.println(lightValue);
  delay(500);
}
✅ Output: Displays light intensity values from 0 (dark) to 1023 (bright).
2. Measure Sound Levels (Sound Sensor)
Hardware Required:
          KY-038 or LM393 Sound Sensor
          Arduino Board
Connections:
Sound Sensor Pin Arduino Pin
VCC                  5V
GND                  GND
Analog OUT           A1
Code:
const int SOUND_PIN = A1;
void setup() {
  Serial.begin(9600);
}
void loop() {
  int soundLevel = analogRead(SOUND_PIN);
  Serial.print("Sound Level: ");
  Serial.println(soundLevel);
  delay(500);
}
✅ Output: Displays sound intensity, higher values mean louder noise.
3. Measure Distance (Ultrasonic Sensor)
Hardware Required:
          HC-SR04 Ultrasonic Sensor
          Arduino Board
Connections:
HC-SR04 Pin Arduino Pin
VCC            5V
GND            GND
Trig           9
Echo           10
Code:
const int trigPin = 9;
const int echoPin = 10;
void setup() {
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}
void loop() {
  long duration;
  int distance;
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    distance = duration * 0.034 / 2;
    Serial.print("Distance: ");
    Serial.print(distance);
    Serial.println(" cm");
    delay(500);
}
✅ Output: Displays distance in centimeters (cm).
4. Measure Angle (Gyroscope Sensor - MPU6050)
Hardware Required:
         MPU6050 Gyroscope Sensor
         Arduino Board
Connections:
MPU6050 Pin Arduino Pin
VCC            5V
GND            GND
SDA            A4 (I2C Data)
SCL            A5 (I2C Clock)
Code:
#include <Wire.h>
#include <MPU6050.h>
MPU6050 mpu;
void setup() {
  Serial.begin(9600);
  Wire.begin();
  mpu.initialize();
}
void loop() {
  int16_t ax, ay, az, gx, gy, gz;
  mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
    Serial.print("Angle X: ");
    Serial.print(ax);
    Serial.print(" Angle Y: ");
    Serial.print(ay);
    Serial.print(" Angle Z: ");
    Serial.println(az);
    delay(500);
}
✅ Output: Displays angle changes on X, Y, and Z axes.
Final Notes:
        Each program reads sensor data and outputs values to the Serial Monitor.
        Can be used in robots, automation systems, or IoT projects.
Would you like me to combine multiple sensors in one program? 😊