MAE 106 Learning Objectives
• One highlight from last lecture:
• How to use a potentiometer as a sensor (via a voltage divider analysis)
• This lecture – Introduction to Arduino
• Be able to state the basics of programming an Arduino
• Be able to identify the input/output ports of an Arduino
Potentiometer: Example Midterm Question
Power MOSFET:
Example midterm problem
Introduction to Arduinos
What is an Arduino?
• Arduino is an electronics platform based on easy-to-use hardware (including a
microcontroller) and software (based on C/C++).
• Arduino boards are able to read inputs - light on a sensor, a finger on a button, or
a Twitter message - and turn it into an output - activating a motor, turning on an
LED, publishing something online.
• You tell your board what to do by sending a set of instructions to the
microcontroller on the board.
Arduino board and IDE (Integrated Development
Environment)
Note: Install on your laptop before first lab https://www.arduino.cc/en/software
Why are Arduinos so popular?
• Easy-to-use and well-supported
• Inexpensive (~$20)
• Simple and accessible user experience
• Do not require extra hardware to program and use the microcontroller
• Wide variety of C/C++ functions that work with all the “Arduino family”
• Open-source
• Huge amount of online documentation (projects, samples, etc)
• e.g. https://lifehacker.com/top-10-kickass-arduino-projects-1747407543
• Large amount of “shields” that you can add on to do more things
• e.g. https://playground.arduino.cc/Main/SimilarBoards/
How/when will we use Arduinos?
• All the labs in MAE106 use Arduino, to acquire data and send signals
to systems (like the RC filter in Lab 1)
• Some of the code will be provided to you, but in most cases you will
have to understand and change it accordingly to finish your lab and
collect data for the write-ups
• Your final project robot will use an Arduino to implement its
controller
Proposed Final Project Variation
Proposed Final Project Variation
• Robot starts at Engineering Gateway Plaza
• Navigates to Java City and takes coffee cup
off counter with a robot arm
• Brings coffee cup into EG, up elevator, then
through double doors to Prof.
Reinkensmeyer’s office
• Team size 1; Due in Week 4
• Extra Credit if you disable any Zotbot robots
you can find on the way
• Extra Credit if you do it through direct brain
control
Example
• Potentiometer: • Servomotor:
Arduino:
#include <Servo.h>
Servo myservo;
void setup()
{
myservo.attach(9);
}
Example, continued
• Potentiometer:
Arduino Language
• Is actually C language with extra functions ready to be used with any
Arduino board
• Reference
• Open source
Getting started programming Arduino:
setup() and loop() functions
• setup(): This function is called once when a sketch starts after power-
up or reset. It is used to initialize variables, input and output pin
modes, and other libraries needed in the sketch
• loop(): After setup() has been called, function loop() is executed
repeatedly in the main program. It controls the board until the board
is powered off or is reset.
Built-in timer
Compass
Reed Switches
Switches
(for optional whiskers)
Servo Motor
Solenoid Valve
Steering Mechanism
Pneumatic Cylinder
Arduino
How is the Arduino used for the robot car?
For a detailed
description of
all of this see:
https://www.circuito.io/blog/arduino-uno-pinout/
Analog Input Pins
AnalogRead()
DigitalRead()
DigitalWrite()
Battery Input
5V Output
Ground
Reset
Button
Digital Pins
DigitalRead()
DigitalWrite()
AnalogWrite() ~ only
See: http://arduino.cc/en/Guide/Environment for more information
Arduino IDE
ALWAYS: Select Serial Port and Board
Serial communication
• Used for communication between the Arduino board and a computer or other devices
• Useful for debugging and acquiring data to analyze
• Serial functions:
• begin(), print(), println(), available()
• Using these commands you can send information to the serial port then view it with Tools -
> Serial Monitor (shows numbers) or Tools -> Serial Plotter (shows graphs)
Note that using serial communication
slows down the execution of your
code, so your robot may behave
differently when you have serial
communication on versus not.
One solution is to save data into an
array, then dump it at the end to the
serial port. This is what several of
the labs do.
However, the on-board memory on
the Arduino is limited, so you can’t
save a lot of data with this method.
• Referenced from the perspective of the Arduino
Input is a signal / information
going into the board.
Output is any signal exiting the
board.
Examples: Buttons Switches, Light Sensors, Flex
Sensors, Humidity Sensors, Temperature Sensors,
…
Examples: LEDs, DC motor, servo motor, a piezo
buzzer, relay, an RGB LED, …
Inputs vs Outputs
pinMode()
• pinMode(pin, mode) configures the specified pin to behave either as
an input or an output
• Modes: INPUT, OUTPUT, or INPUT_PULLUP
• Why INPUT_PULLUP?
INPUT_PULLUP
Digital vs Analog
Digital Input: value = digitalRead(pin)
• value = digitalRead(3);
• value is 0, if input <= 1.5 V
• value is 1, if input >= 3.0 V
• Value is not determined, if input 1.5 < input < 3.0
Analog Input: value = analogRead(pin)
• value = analogRead(A0);
• Converts analog input to digital signal with a 10 bit converter:
Input voltage Analog to digital conversion value (read in analogRead function)
0V 0000000000b 0
5V 1111111111b 1023
? 0000000001b 1
Digital Output: digitalWrite(pin, value)
• digitalWrite(3, LOW);
• Output pin will be set to 0V
• digitalWrite(3, HIGH);
• Output pin will be set to 5V
Analog Output: analogWrite(pin, value)
• analogWrite(3, 100);
• pin limited to pins with the ~ symbol
• value can be any number from 0 to 255
• 0 -> 0V | 255 -> 5V | 128 -> ?
Fixed cycle length; constant number
of cycles/sec
Lab Write-Ups
• Due in the first 10 minutes of the following lab
• Save as… LASTNAME_01 where 01 will be the lab number
Lab Write-Ups
Lab Write-Ups
Practical Exams - Construction Quality
Fritzing (https://fritzing.org/)
Breadboard Diagram vs. Circuit Schematic

teststststststLecture_3_2022_Arduino.pptx

  • 1.
    MAE 106 LearningObjectives • One highlight from last lecture: • How to use a potentiometer as a sensor (via a voltage divider analysis) • This lecture – Introduction to Arduino • Be able to state the basics of programming an Arduino • Be able to identify the input/output ports of an Arduino
  • 2.
  • 3.
  • 4.
  • 5.
    What is anArduino? • Arduino is an electronics platform based on easy-to-use hardware (including a microcontroller) and software (based on C/C++). • Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter message - and turn it into an output - activating a motor, turning on an LED, publishing something online. • You tell your board what to do by sending a set of instructions to the microcontroller on the board.
  • 6.
    Arduino board andIDE (Integrated Development Environment) Note: Install on your laptop before first lab https://www.arduino.cc/en/software
  • 7.
    Why are Arduinosso popular? • Easy-to-use and well-supported • Inexpensive (~$20) • Simple and accessible user experience • Do not require extra hardware to program and use the microcontroller • Wide variety of C/C++ functions that work with all the “Arduino family” • Open-source • Huge amount of online documentation (projects, samples, etc) • e.g. https://lifehacker.com/top-10-kickass-arduino-projects-1747407543 • Large amount of “shields” that you can add on to do more things • e.g. https://playground.arduino.cc/Main/SimilarBoards/
  • 8.
    How/when will weuse Arduinos? • All the labs in MAE106 use Arduino, to acquire data and send signals to systems (like the RC filter in Lab 1) • Some of the code will be provided to you, but in most cases you will have to understand and change it accordingly to finish your lab and collect data for the write-ups • Your final project robot will use an Arduino to implement its controller
  • 9.
  • 10.
    Proposed Final ProjectVariation • Robot starts at Engineering Gateway Plaza • Navigates to Java City and takes coffee cup off counter with a robot arm • Brings coffee cup into EG, up elevator, then through double doors to Prof. Reinkensmeyer’s office • Team size 1; Due in Week 4 • Extra Credit if you disable any Zotbot robots you can find on the way • Extra Credit if you do it through direct brain control
  • 11.
    Example • Potentiometer: •Servomotor: Arduino: #include <Servo.h> Servo myservo; void setup() { myservo.attach(9); }
  • 12.
  • 13.
    Arduino Language • Isactually C language with extra functions ready to be used with any Arduino board • Reference • Open source
  • 14.
    Getting started programmingArduino: setup() and loop() functions • setup(): This function is called once when a sketch starts after power- up or reset. It is used to initialize variables, input and output pin modes, and other libraries needed in the sketch • loop(): After setup() has been called, function loop() is executed repeatedly in the main program. It controls the board until the board is powered off or is reset.
  • 15.
    Built-in timer Compass Reed Switches Switches (foroptional whiskers) Servo Motor Solenoid Valve Steering Mechanism Pneumatic Cylinder Arduino How is the Arduino used for the robot car?
  • 16.
    For a detailed descriptionof all of this see: https://www.circuito.io/blog/arduino-uno-pinout/
  • 17.
    Analog Input Pins AnalogRead() DigitalRead() DigitalWrite() BatteryInput 5V Output Ground Reset Button Digital Pins DigitalRead() DigitalWrite() AnalogWrite() ~ only
  • 18.
  • 19.
    ALWAYS: Select SerialPort and Board
  • 20.
    Serial communication • Usedfor communication between the Arduino board and a computer or other devices • Useful for debugging and acquiring data to analyze • Serial functions: • begin(), print(), println(), available() • Using these commands you can send information to the serial port then view it with Tools - > Serial Monitor (shows numbers) or Tools -> Serial Plotter (shows graphs) Note that using serial communication slows down the execution of your code, so your robot may behave differently when you have serial communication on versus not. One solution is to save data into an array, then dump it at the end to the serial port. This is what several of the labs do. However, the on-board memory on the Arduino is limited, so you can’t save a lot of data with this method.
  • 21.
    • Referenced fromthe perspective of the Arduino Input is a signal / information going into the board. Output is any signal exiting the board. Examples: Buttons Switches, Light Sensors, Flex Sensors, Humidity Sensors, Temperature Sensors, … Examples: LEDs, DC motor, servo motor, a piezo buzzer, relay, an RGB LED, … Inputs vs Outputs
  • 22.
    pinMode() • pinMode(pin, mode)configures the specified pin to behave either as an input or an output • Modes: INPUT, OUTPUT, or INPUT_PULLUP • Why INPUT_PULLUP? INPUT_PULLUP
  • 23.
  • 24.
    Digital Input: value= digitalRead(pin) • value = digitalRead(3); • value is 0, if input <= 1.5 V • value is 1, if input >= 3.0 V • Value is not determined, if input 1.5 < input < 3.0
  • 25.
    Analog Input: value= analogRead(pin) • value = analogRead(A0); • Converts analog input to digital signal with a 10 bit converter: Input voltage Analog to digital conversion value (read in analogRead function) 0V 0000000000b 0 5V 1111111111b 1023 ? 0000000001b 1
  • 26.
    Digital Output: digitalWrite(pin,value) • digitalWrite(3, LOW); • Output pin will be set to 0V • digitalWrite(3, HIGH); • Output pin will be set to 5V
  • 27.
    Analog Output: analogWrite(pin,value) • analogWrite(3, 100); • pin limited to pins with the ~ symbol • value can be any number from 0 to 255 • 0 -> 0V | 255 -> 5V | 128 -> ? Fixed cycle length; constant number of cycles/sec
  • 28.
    Lab Write-Ups • Duein the first 10 minutes of the following lab • Save as… LASTNAME_01 where 01 will be the lab number
  • 29.
  • 30.
  • 31.
    Practical Exams -Construction Quality
  • 32.

Editor's Notes