Programming for Artificial
Intelligence
Lecture 2
1
Physical AI
- Physical AI is an Interdisciplinary field between AI and Robotics - While
traditional AI operates in purely digital environments, physical AI
manifests embodied intelligence
- It’s mainly applicable in scenarios where decision-making relies on physical
actions and real-time feedback
- Physical AI systems perceive their environment through sensors, make
decisions using some algorithms, and interact physically with the environment
using actuators.
2
Physical AI systems are made up of several interdependent components: -
Sensing System (Perception Layer)
- Sensors – devices that collect data
- Signal Processing Units – convert raw sensor signals into usable data
- Processing and Intelligence (Cognitive Layer)
- Microcontrollers / Microprocessors (Hardware Brain)
- Algorithms (Software Brain)
- Embedded Systems / Edge Computing
- Actuation System (Action Layer)
- Actuators and Motors (DC, Servo, Stepper etc)
- End Effectors
3
- Power System
- Power Supply
- Energy Management System
- Communication System (Connectivity Layer)
- Wired Protocols
- Wireless Technologies
- Cloud or IoT Integration
- Mechanical & Material Structure (Embodiment)
- Frame / Body
4
World Model
A world model is an internal representation of the external environment that an intelligent
agent builds to understand, predict, and interact with the real world.
Important to understand that what a world model does for a physical AI system is what a
language model is doing for an NLP system.
World Model
Language Model
An AI system’s internal representation of the
external world used to predict, plan, and act in
physical or simulated environments.
An AI system trained on human language to
predict the next word or token, used to
understand and generate text.
Models how the real world behaves.
Models how language behaves.
Predict future states of the world.
Predict the next word or sentence.
5
Scope
Boston
Dynamics Amazon Robotics
NVIDIA Cosmos Intuitive Surgical
6
Ethical Considerations
- Safety and Harm Prevention
- Responsibility and Accountability
- Transparency and Explainability
- Privacy and Surveillance
- Bias and Fairness
- Human Autonomy and Control
- Employment and Socioeconomic Impact
- Environmental Impact
- Moral and Emotional Interaction
- Misuse
7
Hardware
8
ESP32
The ESP32 is a powerful, low-cost, low-power microcontroller with integrated Wi
Fi and Bluetooth, developed by Espressif Systems.
It is designed for IoT (Internet of Things), smart home automation, sensor
networks, and embedded systems that require wireless communication, high
processing power, and low energy consumption.
12
ESP32 components
13
Architecture
Dual-Core Processor – Handles multitasking (e.g., Wi-Fi + sensor
control). Wi-Fi & Bluetooth Modules – Provides wireless connectivity.
GPIO Pins – Interface with sensors, motors, LEDs, etc.
Analog Interfaces – ADC, DAC, touch sensors.
Timers and PWM – For precise control of motors and LEDs.
ULP (Ultra-Low Power) Co-processor – Runs tasks during deep sleep for battery
powered applications.
14
Esp32 Pinout
A common development board is the ESP32 DevKit V1, which has 30 or 38
pins depending on the version.
15
Power Pins
Pin
Function
VIN
Input voltage (5V from USB or external
source)
3V3
Regulated 3.3V output
GND
Ground pins (several available)
EN (Enable)
Resets the chip when pulled LOW
16
Input/Output Pins
Pin
Function
GPIO0 – GPIO39
General-purpose digital I/O pins
GPIO34 – GPIO39
Input only pins (cannot output)
GPIO6 – GPIO11
Used internally for SPI Flash (avoid using)
GPIO12
Special boot pin – use cautiously (can affect startup)
17
Analog Pins (ADC / DAC)
Type
Pins
Description
ADC (Analog to Digital Converter)
GPIOs 32–39
12-bit ADC, up to 18 channels
DAC (Digital to Analog Converter)
GPIO25, GPIO26
8-bit DAC output
18
Pulse Width Modulation Pins
19
Important
20
Touch Sensing in ESP32
21
ESP8266
➢ The ESP8266 is a low-cost Wi-Fi microchip with full TCP/IP networking
capability and microcontroller functionality, developed by Espressif
Systems.
➢ It is a precursor to ESP32 but can be used as a cheaper alternative for it.
➢ It can be used both as a Wi-Fi adapter for other microcontrollers (like Arduino)
or as a standalone microcontroller, since it has its own CPU, memory, and
GPIO pins.
22
Architecture
The ESP8266 integrates:
CPU (Tensilica L106) — 32-bit processor for logic and control
Wi-Fi Module — Built-in 2.4 GHz transceiver and TCP/IP stack
Memory — Internal SRAM and external SPI flash storage
GPIO Interface — Digital I/O pins for sensors and actuators
Serial Interfaces — UART, SPI, I²C for external communication
It operates as both a microcontroller and a Wi-Fi communication device,
eliminating the need for an external MCU in many projects.
23
Esp8266 PinOut
24
Power Pins
Pin
Function
Description
VIN
Power Input (5V)
Provides 5V to the board via USB
or external supply.
3V3
3.3V Output
Regulated 3.3V output from the
onboard voltage regulator (max
~600mA).
GND
Ground
Common ground for all circuits.
EN (CH_PD)
Chip Enable
Must be pulled HIGH to enable the
chip; pulling LOW resets it.
25
Digital I/O Pins (GPIO)
Pin Name (NodeMCU)
ESP8266 Pin (GPIO)
Functions / Notes
D0
GPIO16
No PWM or I2C; used for wake-up
from deep sleep.
D1
GPIO5
I2C SCL (default).
D2
GPIO4
I2C SDA (default).
D3
GPIO0
Must be HIGH at boot; used in
flashing mode (keep pulled up).
D4
GPIO2
Must be HIGH at boot; often
connected to onboard LED.
D5
GPIO14
SPI CLK (SCK).
D6
GPIO12
SPI MISO; must be LOW at boot.
26
D7
GPIO13
SPI MOSI.
D8
GPIO15
Must be LOW at boot; used as SPI CS.
RX
GPIO3
UART0 RX (used for serial
communication).
TX
GPIO1
UART0 TX (used for serial
communication).
D9
GPIO11
Used internally for flash memory
(avoid using).
D10
GPIO10
Used internally for flash memory
(avoid using).
D11
GPIO9
Used internally for flash memory
(avoid using).
27
Boot Mode-Dependent Pins
Some pins affect the boot mode (startup behavior) of the ESP8266.
If set incorrectly, the board won’t start properly.
Pin
Boot Mode Requirement
GPIO0
Must be HIGH during normal boot; LOW to
enter flash mode
GPIO2
Must be HIGH at boot
GPIO15
Must be LOW at boot
28
Differences between ESP32 and Esp8266
ESP8266
ESP32
Connectivity
Wi-Fi only
Wi-Fi + Bluetooth
Performance
Single-core, slower
Dual-core, faster
Power Efficiency
Moderate
Excellent (ULP mode)
GPIO/ADC/DAC
Fewer
More and richer features
Price
Lower
Slightly higher
Best For
Basic IoT, Wi-Fi projects
More advanced IoT,
robotics, wearables
29
Arduino Uno
Arduino UNO is the most popular microcontroller board in the Arduino family.
It is designed for beginners and educators, so it allows users to easily
connect sensors, actuators, and displays to build interactive electronic
projects.
It can be programmed using the Arduino IDE with C/C++-based language. 30
Arduino Uno PinOut
31
Arduino Uno Pin Summary
Category
Pins
Summary
Digital I/O
D0–D13
14 pins (6 with PWM)
Analog Input
A0–A5
6 pins (10-bit ADC)
PWM Output
D3, D5, D6, D9, D10, D11
6 pins
Serial Communication (UART)
D0 (RX), D1 (TX)
For USB or external
communication
SPI Interface
D10–D13
For SPI devices
I²C Interface
A4 (SDA), A5 (SCL)
For I²C sensors
Power
VIN, 5V, 3.3V, GND
Power supply pins
Special Pins
RESET, AREF
Reset and reference voltage
32
Motors
DC motor converts direct electrical energy (DC) into rotational mechanical motion and is used for continuous rotation A servo
motor provides precise control of angular position, velocity, and acceleration using feedback control. A stepper motor rotates
in fixed angular steps rather than continuous rotation. Each pulse to the motor moves it a precise
“step”
DC Motor
Servo Motor Stepper Motor 33
Actuators/Effectors
34
Motor Driver
A motor driver is an electronic circuit or module that acts as a bridge between a
microcontroller (like Arduino or ESP32) and a motor.
Microcontrollers cannot supply enough current or voltage to drive motors
directly. A motor driver:
- Takes low-power control signals from the microcontroller
- Uses an external power source to supply high current to the motors Controls the direction and speed of the motor
35
H-Bridge circuit
The core concept behind most motor drivers (including the L298N) is the HBridge circuit.
An H-Bridge uses four electronic switches arranged in an “H” shape to
control the direction of current flow through the motor.
- Turning ON specific pairs of switches controls current direction i.e. forward
or reverse rotation
- Using PWM (Pulse Width Modulation) signals adjusts motor speed 36
L298n
The L298N is a dual H-Bridge motor driver IC designed by STMicroelectronics. It
can control two DC motors or one stepper motor, including direction and speed.
37
How the L298N Controls Motors
IN1
HIGH
IN2
LOW
Motor A Direction
Clockwise
LOW
HIGH
Counterclockwise
LOW
LOW
Stop
HIGH
HIGH
Stop
38
39
Wires
a) male to male b) male to female c)female to
female
41
Bread board
42
Arduino IDE
The Arduino IDE is a free, open-source programming environment that makes it easy to
develop and upload code to Arduino boards and other compatible microcontrollers.
43
Result
WhatsApp Vide o 202 5-1 0-2 0 at 1.01.4 0 AM.mp4
44