Introduction To Arduino: (Programming, Wiring, and More!)
Introduction To Arduino: (Programming, Wiring, and More!)
Battery
Connector Analog
(Input)
Pins
Power
Pins
Arduino Uno – more details (Ref. 2)
Arduino Mega – Larger, more pins
(we won’t be using this today)
USB Serial Pins Digital Pins
Connector
Battery
Connector
Power Analog
Pins Pins
Arduino Mini – Smaller and lighter;
(more appropriate for some applications)
Digital Pins Serial Connectors
Analog Pins
Power Pins
(Solderless) Breadboard (Ref. 2)
Breadboard Innards (Ref. 2)
Insert 22-gauge solid wire jumpers and component leads into breadboard clips to make
electrical connections without soldering. Use the edge “rails” for power (5V) and ground.
Introduction to Software
•Arduino microcontrollers are programmed using the
Arduino IDE (Integrated Development Environment)
–Can be downloaded for free from
http://arduino.cc/en/Main/Software
•Arduino programs, called “sketches”, are written in a
programming language similar to C and C++
•Every sketch must have a setup() function
(executed just once) followed by a loop() function
(potentially executed many times); add “comments” to
code to make it easier to read (technically optional, but
actually required (by me))
•Many sensors and other hardware devices come with
prewritten software – look on-line for sample code,
libraries (of functions), and tutorials
Parts of the IDE main screen
Name of current sketch
Main menus
Action buttons/icons
Verify (AKA compile)
Text area for Upload (send to Arduino)
writing/editing
sketches. Start a new sketch
Open a sketch (from a file)
Save current sketch (to a file)
Open Serial Monitor window
Note that the servo has a plug attached to its ribbon cable. This is so that we
can more easily extend the cable using plugs and more ribbon cable. It also
allows it to plug into specific plugs built into some shields. Several companies
make a few different Motor Shields, which are shields specifically designed to
drive servos, motors, and stepper motors. These usually support 2 to 4 motors,
although Adafruit has one that will control 16. They generally have plugs built
into the shield for the motors and often drive them through some sort of a serial
connection (I2C or SPI is common).
5V 5V (Power) 5V pin
Look for pin conflicts. Hopefully there won’t be any (but always look).
Plug in the Arduino Uno and Altitude_Pressure_plusTemp_Sensor
Study the code (it might be long!); run it (open serial monitor); test, discuss
Activity 8 – 2 digital temp sensors, SD card
With the Arduino Uno unplugged, add one “Dallas one-wire” digital temperature sensor
on the breadboard and a second one at the end of a 3-wire cable (if not provided then
just make your own with jumper wires), as shown on the following slide. Notice that both
sensors need ground and power (5 volts) and that they are polled through a single digital
pin (D2). Also notice that a 4.7 kΩ “pull-up” resistor is required between pin D2 and the 5
volt line so that it stays HIGH when not in use.
Place OneWire and DallasTemperature into your Arduino library. This activity also
uses Wire and SD (already in your library).
Put an SD card into your SD card shield. Note – if you are using a SparkFun shield with
a microSD card reader it may not have a RTC (the code will still run – it just won’t have
real time clock data) and be sure the code uses the SparkFun value of “8” rather than the
Adafruit value of “10” for the “chip select” variable.
Plug in the Arduino Uno and load the sketch SD_RTC_2_Digital_Temp which will
determine the sensor names, poll them, write the results to both the screen and to the
SD card (after opening a file), then repeat.
Study the code (it might be long!); run it (open the serial monitor – confirm baud rate);
test it (including touching the sensors one at a time to change their temperature - also try
removing the SD card and reading the data directly on your computer). Discuss the
utility of saving data this way; discuss the utility of having “off-board” sensors. Note:
cable length can impact analog sensor data readings so always minimize cable lengths
and use digital sensors when off-board (if possible).
Wiring for 2 digital temperature sensors
(Not shown – the tiny breadboard may actually be mounted on a protoshield on
top of the Arduino Uno; optional: if the shield doesn’t have a RTC you could add
your own (perhaps put that on the upper left side of the breadboard).)
Use this wiring color convention: red for power, black for ground, green for data.
Activity 9 – GPS, external power
• With the Arduino unplugged, add the GPS module (to the upper right hand
corner of your breadboard) using the table on the next slide.
• Place TinyGPS into your Arduino library. This activity also uses SD, SPI, and
SoftwareSerial (already in your library).
• Plug in the USB cable and load the sketch GPS_on_SD. Upload the sketch to
the Arduino Uno (watch out for chip select). Open the serial monitor (confirm
baud rate) and watch it run. The GPS probably won’t get a lock so the data will
probably be uninteresting.
• Unplug the USB cable (AKA the programming cable). Power the Arduino Uno
using a 9-volt battery through the power jack instead. You can now run
sketches independently from the laptop (but no more serial monitoring!). This
mode of operating is critical for applications like quadcopters, ballooning, and
rocketry.
• The LED on the GPS gives its lock status. Fast blink means “not locked”; slow
blink means locked. You are unlikely to get it to lock indoors so take the
package outside until it gets a lock then walk around a bit to collect some
interesting data. Come back in and look at the GPS data that was logged to the
micro-SD card.
Adafruit Ultimate GPS Breakout
Pin Function Attached To
FIX Output at same time as fix LED Not connected (May want to
connect depending on your project)
TX Transmit D5
RX Receive D6
VIN 5V Power 5V