epiaigualada.catepiaigualada.cat/.../uploads/2017/01/lesson-plan-arduino-robot…  · web viewin...

15
ESCOLA PIA Igualada CONTROL TECHNOLOGY AND ROBOTICS

Upload: others

Post on 19-Oct-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

(CONTROL TECHNOLOGY AND ROBOTICS) (ESCOLA PIAIgualada)

INTRODUCTION

As we know, there are systems that work in automatic way: cars, traffic lights, TV, elevators… All of them follow instructions that they were programmed before.

On the other hand, robotics helps us at home to do some easy homework like cleaning the floor or cutting the grass. Furthermore, it is very important for industry to do dangerous or precision works.

In this workshop, we are going to use Arduino Uno device which helps us to understand how to program in an easy way and it could be an introduction to learn basic aspects of control and robotics.

ARDUINO: WHAT IT IS AND PROGRAMMING

1.1. HARDWARE

ArduinoUno is a device which could be programmed to interact in real world and to obtain information from several sensors.

We can use different software languages to program Arduino. In our case, we are going to use open source: IDE (integrated development environment).

14 input and output digital pins:from 0 to 13. To connect digital sensors andactuators.TX and RX allow connecting communication elements (Wifi, Bluetooth...).

Reset:To reboot microcontroller.

USB:To connect computer and Arduino.

3V3, 5V, GND, Vin:To supply energy for components

1.2. SOFTWARE

We need software to program Arduino Uno that we run in a computer (in our caseArduino IDE). We can download from www.arduino.cc

Verify:Checks your sketch for errors compiling it.

Upload:Upload the program to Arduino through the configured Port.

Serial monitor: Opens the serial monitor window and initiates the exchange of data with any connected board on the currently selected Port.

The structure of any Arduino IDE programhastwoinstruction blocks (void):

Void setup (): It runs only once at the beginning of the program.

Void loop (): It runs time after time, if the device is connected.

We have to be aware that each instruction must be finished with “;” and a code block is included into “()”. Writing “//”, we can add comments.

1.3. HOW TO CONFIGURE ARDUINO AND FIRST PROGRAMME

First of all, we set up Arduino IDEsoftware.

After that, we should load IDE connecting Arduino device to the computer. We should also confirm the port where it is connected.

It is important to check that the device has a port in order to confirm that Arduino will work properly.

Our first programme. We should click on menuFile/basics/blink

You will see some instructions. Click on the upload button. If it works properly, you will see a green led flickering on the board.

Let’s understand and modify blink:

DigitalWrite order makes that the green led on the board stays on (high) or off (low) during a second (delay(1000)).

Try to modify how long the led is on or off.

1.4. DIGITAL OUTPUTS

Let’s use leds for this workshop. We have to take into account that leds have polarity. Anode (+) is the longest pin and ends as an arrow. On the other hand, cathode (-) is the shortest one.

To build our circuits, we will use breadboard.

In this board:

The holes in the superior and inferior row are connected horizontal. We use them to connect positive and negative to power.

In the middle, there is a space which separates rows from the positive and negative holes and is connected vertical.

To build the first circuit, look at the image. We use a 220Ω resistor. We will connect led anode on 13 Arduino pin and cathode to Arduino ground (GND)

We will create a new program and we should write the following sentences:

Pin Mode indicates the pin number and what kind of actuator is. In our case, it is pin number 13 and it is an OUTPUT actuator. In (void loop), digital Write instruction indicates that pin 13 should be on (HIGH) oroff (LOW). Delay instruction Works in milliseconds.

Try to modify to turn on the led faster o slower.

ELECTRONIC CIRCUITS CONTROL

1.5. TO TURN ON TWO LEDS ALTERNATIVELY

Connect two leds on breadboard with a 220Ω each. Cathode of each led should be connected on negative hole of the board. And both of them should be connected in Arduino GND. The anode of one led should be connected on pin 2 and the other anode should be connected on pin 7.

After you finish the circuit, you should write the following IDE program:

Upload the program on Arduino device and check if it works properly.

1.6. HOW TO PROGRAM A TRAFFIC LIGHT

We need three leds: Green, yellow and red. We should reproduce the following image:

Introducing #define instruction: It allows defining constants related to each pin. What out: don’t write “;” at the end: #defineGREENPIN 7 (when Arduino reads GREENPIN, it means that is related to pin number 7)

After finishing the circuit, you should write the following IDE program:

Upload the program to Arduino device and check if it works properly.

Improving.What do you do if you want to control two traffic lights in a crossroad?