34
ARDUINO ROBOTICS The Arduino microcontroller Arduino is a company that develops microcontrollers and the software required to program them (www.arduino.cc ). During this unit you will be using Arduino software and a compatible microcontroller board to create your own control technology. Look at your microcontroller and discuss as a class the parts of the board and their functions. 1

The Arduino microcontroller€¦  · Web view2020. 1. 12. · ARDUINO ROBOTICS. The Arduino microcontroller. Arduino is a company that develops microcontrollers and the software

  • Upload
    others

  • View
    24

  • Download
    1

Embed Size (px)

Citation preview

Page 1: The Arduino microcontroller€¦  · Web view2020. 1. 12. · ARDUINO ROBOTICS. The Arduino microcontroller. Arduino is a company that develops microcontrollers and the software

ARDUINO ROBOTICS

The Arduino microcontrollerArduino is a company that develops microcontrollers and the software required to program them(www.arduino.cc). During this unit you will be using Arduino software and a compatible microcontroller board to create your own control technology.

Look at your microcontroller and discuss as a class the parts of the board and their functions.

1

Page 2: The Arduino microcontroller€¦  · Web view2020. 1. 12. · ARDUINO ROBOTICS. The Arduino microcontroller. Arduino is a company that develops microcontrollers and the software

Getting started with Arduino

Arduino IDE (Integrated Development Environment)The Arduino IDE is free

To program your Arduino, you have two options:

1. Download the Arduino IDEa. Use an installed Arduino IDE program on your local computer

i. This is the recommended option

2. Code online with the Arduino Web Editor

You can access the Arduino software links here: https://www.arduino.cc/en/Main/Software

Getting started guide

Utilise and read the following Arduino documentation https://www.arduino.cc/en/Guide/ArduinoUno

2

Page 3: The Arduino microcontroller€¦  · Web view2020. 1. 12. · ARDUINO ROBOTICS. The Arduino microcontroller. Arduino is a company that develops microcontrollers and the software

Program layout and structure for ArduinoArduino programs can be divided into three main parts: 'structure', 'values' (variables and constants), and 'functions'. A list of words used in Arduino language can be found in the Arduino Help menu or on the Arduino reference webpage.

Syntax - The spelling and grammar of codingWhen coding, the spelling and grammar (syntax) you use must be absolutely correct. If you have any aspect of the code incorrect the computer will not know what to do, or will do something you don't expect.

Camel case is used when words are joined together and use a capitalised letter to show separation. Commands in code are case sensitive.

Computers only do exactly what they have been told to do in the code!

Comments in Code and ProgramsWhen coding, programmers will often add comments next to the lines of code. These comments are not read by the computer and are only there to help people reading the code.

In the Arduino language, comments start with //. The software knows to ignore everything on the line after the //. Comments help you remember what each part of the program does, especially tricky bits and also are great if other programmers are helping you or adding to your code. Not every line needs a comment, however the examples in this unit have many comments to help explain what each line is doing. Good programmers write quite a few comments in their programs.

3

Page 4: The Arduino microcontroller€¦  · Web view2020. 1. 12. · ARDUINO ROBOTICS. The Arduino microcontroller. Arduino is a company that develops microcontrollers and the software

Learning Arduino Skills - Digital DiaryUse this diary to record the development and testing of each Arduino example inbuilt in the Arduino IDE software.

Basics

Bare Minimum

Code:

Evaluation:

This is the bare minimum of code needed to start an Arduino sketch.

The void setup() function will only run once and code placed here is designed to set up variables, inputs and outputs for the Arduino.

The void loop() function will contain the majority of the program code and will run repeatedly. The programs algorithms will be written here.

4

Page 5: The Arduino microcontroller€¦  · Web view2020. 1. 12. · ARDUINO ROBOTICS. The Arduino microcontroller. Arduino is a company that develops microcontrollers and the software

AnalogReadSerial

Photo of hardware setup:

Evaluation of operation:

This is a potentiometer connected to an arduino through a breadboard. Once connected, it is possible to measure the amount of resistance produced by the potentiometer. The range of voltage on this potentiometer was 0 to 1023.

5

Page 6: The Arduino microcontroller€¦  · Web view2020. 1. 12. · ARDUINO ROBOTICS. The Arduino microcontroller. Arduino is a company that develops microcontrollers and the software

Blink

Photo of hardware setup:

Evaluation of operation:

Task: Update the code to turn on the LED for 2.5 seconds and off for 0.5 seconds.

Task result description:

6

Page 7: The Arduino microcontroller€¦  · Web view2020. 1. 12. · ARDUINO ROBOTICS. The Arduino microcontroller. Arduino is a company that develops microcontrollers and the software

DigitalReadSerial

Photo of hardware setup:

Evaluation of operation:

Task: Slow down how frequently the serial monitor outputs the digital input state.

Task result description:

7

Page 8: The Arduino microcontroller€¦  · Web view2020. 1. 12. · ARDUINO ROBOTICS. The Arduino microcontroller. Arduino is a company that develops microcontrollers and the software

Fade

Photo of hardware setup:

Evaluation of operation:

Task: Speed up and slow down the rate at which the LED fades.

Task result description:

8

Page 9: The Arduino microcontroller€¦  · Web view2020. 1. 12. · ARDUINO ROBOTICS. The Arduino microcontroller. Arduino is a company that develops microcontrollers and the software

ReadAnalogVoltage

Photo of hardware setup:

Evaluation of operation:

Task: Read the input from the potentiometer on the digital line in pin 3. Problem-solve the code so a digital pin is set up to read an input.

Hints: The pinMode() and digitalRead() functions are required. The * (5.0 / 1023.0) calculation will need to be removed.

Task result description:

9

Page 10: The Arduino microcontroller€¦  · Web view2020. 1. 12. · ARDUINO ROBOTICS. The Arduino microcontroller. Arduino is a company that develops microcontrollers and the software

Summary Questions A

What is the purpose of the setup() routine?

What is the purpose of loop() routine?

What pin is the LED connected to on the Arduino Uno?

Explain the difference between an analog pin and a digital pin.

How does Pulse Width Modulation (PWM) work?

Outline a variable.

What is an ‘int’ datatype?

A Light Emitting Diode (LED) only allows current to flow in one direction. Identify the names of the two terminals and label whether the terminal is positive or negative. How can we recognise the positive or negative terminal?

Explain how a resistor works.

How does a potentiometer work?

10

Page 11: The Arduino microcontroller€¦  · Web view2020. 1. 12. · ARDUINO ROBOTICS. The Arduino microcontroller. Arduino is a company that develops microcontrollers and the software

Digital

BlinkWithoutDelay

Photo of hardware setup:

Evaluation of operation:

Why must we use the ‘unsigned long’ datatype?

Task: Change the blink interval to 2 seconds.

Task result description:

11

Page 12: The Arduino microcontroller€¦  · Web view2020. 1. 12. · ARDUINO ROBOTICS. The Arduino microcontroller. Arduino is a company that develops microcontrollers and the software

Button

Photo of hardware setup:

Evaluation of operation:

Task: Set up an external LED to turn on/off instead of the built-in LED on the Arduino.

Task result description:

12

Page 13: The Arduino microcontroller€¦  · Web view2020. 1. 12. · ARDUINO ROBOTICS. The Arduino microcontroller. Arduino is a company that develops microcontrollers and the software

Digital Input Pullup

Photo of hardware setup:

Evaluation of operation:

Important notes:

Explain why the pull-up means the pushbutton's logic is inverted.

13

Page 14: The Arduino microcontroller€¦  · Web view2020. 1. 12. · ARDUINO ROBOTICS. The Arduino microcontroller. Arduino is a company that develops microcontrollers and the software

Sensors and Transducers

Read: https://www.electronics-tutorials.ws/io/io_1.html

Simple Input/Output System using Sound Transducers

Common Sensors and Transducers

Quantity beingMeasured

Input Device(Sensor)

Output Device(Actuator)

Light Level Light Dependant Resistor (LDR)Photodiode

Photo-transistorSolar Cell

Lights & LampsLED’s & Displays

Fibre Optics

Temperature ThermocoupleThermistor

Resistive Temperature Detectors

HeaterFan

Force/Pressure Strain GaugePressure Switch

Load Cells

Lifts & JacksElectromagnet

Vibration

Position PotentiometerReflective/Slotted Opto-switch

MotorSolenoid

Speed Tacho-generatorReflective/Slotted Opto-coupler

Doppler Effect Sensors

AC and DC MotorsStepper Motor

Brake

Sound Carbon MicrophonePiezo-electric Crystal

BuzzerLoudspeaker

14

Page 15: The Arduino microcontroller€¦  · Web view2020. 1. 12. · ARDUINO ROBOTICS. The Arduino microcontroller. Arduino is a company that develops microcontrollers and the software

Sensors and Transducers Summary Notes:

Define Transducers:

Define Sensors:

Define Actuators:

Compare Digital and Analog Sensors:

15

Page 16: The Arduino microcontroller€¦  · Web view2020. 1. 12. · ARDUINO ROBOTICS. The Arduino microcontroller. Arduino is a company that develops microcontrollers and the software

Analog

AnalogInOutSerial

Photo of hardware setup:

Evaluation of operation:

Task: Turn the output LED brightness to half. Your LED brightness should continue to vary based on the potentiometer input.

Task result description:

16

Page 17: The Arduino microcontroller€¦  · Web view2020. 1. 12. · ARDUINO ROBOTICS. The Arduino microcontroller. Arduino is a company that develops microcontrollers and the software

AnalogInput

Photo of hardware setup:

Evaluation of operation:

Potentiometer:

Phototransistor:

Important notes:

17

Page 18: The Arduino microcontroller€¦  · Web view2020. 1. 12. · ARDUINO ROBOTICS. The Arduino microcontroller. Arduino is a company that develops microcontrollers and the software

Fading

Photo of hardware setup:

Evaluation of operation:

Task: Change the speed of fade in and fade out.

Task result description:

18

Page 19: The Arduino microcontroller€¦  · Web view2020. 1. 12. · ARDUINO ROBOTICS. The Arduino microcontroller. Arduino is a company that develops microcontrollers and the software

Sensors

Knock

Photo of hardware setup:

Evaluation of operation:

Task: Change the sensitivity of the knock sensor to sense very fine or rough knocks. What applications would suit a knock sensor with very fine sensitivity?

Task result description:

19

Page 20: The Arduino microcontroller€¦  · Web view2020. 1. 12. · ARDUINO ROBOTICS. The Arduino microcontroller. Arduino is a company that develops microcontrollers and the software

Control

IfStatementConditional

Photo of hardware setup:

Evaluation of operation:

Important notes:

Summary Questions B

20

Page 21: The Arduino microcontroller€¦  · Web view2020. 1. 12. · ARDUINO ROBOTICS. The Arduino microcontroller. Arduino is a company that develops microcontrollers and the software

What is the name of the positive (long leg) of the LED?

What is the name of the negative (short leg) of the LED?

In which circumstances should Digital outputs be used?

In which circumstances should Analog outputs be used?

Why are if conditional statements so important in programming?

21

Page 22: The Arduino microcontroller€¦  · Web view2020. 1. 12. · ARDUINO ROBOTICS. The Arduino microcontroller. Arduino is a company that develops microcontrollers and the software

Challenges

Bar Graph

Using a potentiometer, you can control a series of LEDs in a row. Turning the potentiometer

knob will turn on or off more of the LEDs.

Parts Needed● (1) Potentiometer – Rotary

● (10) LED 5mm

● (10) 220 Ω Resistor

● (11) Jumper Wires

Project Diagram

22

Page 23: The Arduino microcontroller€¦  · Web view2020. 1. 12. · ARDUINO ROBOTICS. The Arduino microcontroller. Arduino is a company that develops microcontrollers and the software

Seven-Segment Display

If your Arduino application only needs to display numbers, consider using a seven-segment display. The seven-segment display has seven LEDs arranged in the shape of number eight. They are easy to use and cost effective. The picture below shows a typical seven-segment display.

In a common cathode seven-segment display (the one we used in the experiments), all seven LEDs plus a dot LED have the cathodes connected to pins 3 and pin 8. To use this display, we need to connect GROUND to pin 3 and pin 8 and, and connect +5V to the other pins to make the individual segments light up.

Complete: Experiment 1 & Experiment 2https://www.allaboutcircuits.com/projects/interface-a-seven-segment-display-to-an-arduino/

Experiment 1

Photo of hardware setup:

23

Page 24: The Arduino microcontroller€¦  · Web view2020. 1. 12. · ARDUINO ROBOTICS. The Arduino microcontroller. Arduino is a company that develops microcontrollers and the software

Evaluation of operation:

Experiment 2

Photo of hardware setup:

Evaluation of operation:

Show side panel

24

Page 25: The Arduino microcontroller€¦  · Web view2020. 1. 12. · ARDUINO ROBOTICS. The Arduino microcontroller. Arduino is a company that develops microcontrollers and the software

Data Types Glossary

Datatype RAM usage Description

boolean 1 byte

char 1 byte

unsigned char 1 byte

int 2 bytes

unsigned int 2 bytes

word 2 bytes

long 4 bytes

unsigned long 4 bytes

float 4 bytes

double 4 bytes

string 4 bytes

array 4 bytes

25