Arduino
• Topics:
• Microcontrollers
• Programming Basics: structure and variables
• Digital Output
• Analog to Digital Conversion
What is a Microcontroller
• A small computer on a single chip
• containing a processor, memory, and input/output
• Typically "embedded" inside some device that they control
• A microcontroller is often small and low cost
What is a Development Board
• A printed circuit
board designed to
facilitate work with a
particular
microcontroller.
• Typical components include:
• power circuit
• programming interface
• basic input; usually buttons and LEDs
• I/O pins
The Arduino Development Board
The Arduino Microcontroller: Atmel
ARV Atmega 328
What is the Arduino
[Link]/blog/bionicarduino
Getting Started
1. Download & install the Arduino environment (IDE)
2. Connect the board to your computer via the UBS cable
3. If needed, install the drivers
4. Launch the Arduino IDE (Integrated Development
Environment)
5. Select your board
6. Select your serial port
7. Open the blink example
8. Upload the program
Connect the USB Cable
Add an External LED to pin 13
• File > Examples > Digital > Blink
• LED’s have polarity
– Negative indicated by flat side of the housing
and a short leg
[Link]
Programming
• Code is case
sensitive
• Statements are
commands and
must end with a
semi-colon
• Comments follow a
// or begin with /*
and end with */
• loop and setup
Terminology
Digital I/0
[Link]/chapters/view/1
pinMode(pin, mode)
Sets pin to either INPUT or OUTPUT
digitalRead(pin)
Reads HIGH or LOW from a pin
digitalWrite(pin, value)
Writes HIGH or LOW to a pin
Electronic stuff
Output pins can provide 40 mA of current
Writing HIGH to an input pin installs a 20KΩ pullup
Arduino Timing
• delay(ms)
– Pauses for a few milliseconds
• delayMicroseconds(us)
– Pauses for a few microseconds
Variables
[Link]
Putting It Together
• Complete the sketch
(program) below.
• What output will be
generated by this program?
• What if the schematic were
changed? ➔
[Link]/learn/arduino
LCD INETERFACE
• 6 digital input pins from the
Arduino Board are used
• The LCD’s registers from D4
to D7 will be connected to
Arduino’s digital pins from 4
to 7.
• The Enable pin will be
connected to pin number 2
• RS pin will be connected to
pin number 1.
• The R/W pin will be
connected to Ground and
the Vo pin will be connected
to the potentiometer
middle pin.
Key board Interface
• The buttons on a keypad are arranged in rows
and columns. A 3X4 keypad has 4 rows and 3
columns, and a 4X4 keypad has 4 rows and 4
columns:
No Button is pressed One Button is pressed
3 x 4 Keyboard
DC motor interface
• DC Motor
• NPN Transistor (e.g., 2N2222 or TIP120) or
Motor Driver (like L298N) - switch
• Diode (1N4007)- protection from voltage
spikes
• External power supply (e.g., 9V battery or
adapter)
• Resistor (1kΩ)
DC motor interface
Temp Sensor interface –LM 35
• The LM35 is one of the most popular and
easy-to-use analog temperature sensors. It
outputs 10mV per °C
• At 25°C → Output = 250mV
• At 0°C → Output = 0V