ebook img

Have fun And Learn Electronics using ArduinoTM PDF

118 Pages·4.085 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Have fun And Learn Electronics using ArduinoTM

Preface This book is intended for those who are hobbyists and want to learn about electronics and have fun at the same time. Each project explains the theory of the sensor or device and a schematic (wiring diagram) and breadboard view are given for each project. The code for each project is included, which can be copied and pasted onto your PC/MAC. There are 19 projects and the last one is a practical application of several of the projects in the book. Once you learn how to use this device, the sky’s the limit to what you can build. At the end of the book an appendix of all of the Arduino™ commands used in the book. Acknowledgements This book makes extensive use of the Arduino™ IDE and refers to Arduino products and code created with the Arduino™ software. These files are licensed under a Creative Commons Attribution Share-Alike license. Many thanks to the Arduino Trademark team for their help. Also many thanks to my wife for her support whilst writing this book. Introduction Welcome to the world of microcontrollers. Basically that’s what the Arduino™ and its rival Raspberry Pi are. Firstly we will look at the versions that are on the market at the moment. There are over 16 versions of the Adruino, which most of them are listed below: UNO Galileo YUN BT Mega 2560 MEGA ADK Due Nano Ethernet Esplora Leonardo Pro Mini Micro Mini Pro Fio Of all of these boards the UNO is the most popular board and is the one that most manufacturers sell with starter kits that are on the market. The board is reasonably small having dimensions 68.6 x 53.4 mm. It can be powered either by the USB port or with a regulated DC power supply (centre positive) between 7 – 20v, but it is not recommended that you use over 12v as it will overheat the voltage regulator, which will cause early failure of the board. A battery pack may also be used connected to the Vin header pin and Grd header pin. USB Connector External PSU connector Alternative PSU connector The USB cable which is usually supplied with the board is a standard A – B cable like you would use to connect to a printer. Now we have sorted out how we are going to supply the board, we need to explain how to program it. Before you can do this you will need to download some software onto your PC or Mac. This can be downloaded from the Arduino™ site: (http://www.Arduino™ .cc/en/Main/Software) Once the software has been installed, which may take a few minutes, click on the icon on your desktop that looks like an infinity sign (number 8 on its side). You will get the following screen on your computer. In Arduino™ speak; a program is called a Sketch. It has three main sections: 1. Library file includes 2. void setup() { } 3. void loop() { } Don’t worry about the programming language at this stage as there are plenty of public domain programs written that you will be able to use. There are a few things you may need before tackling the Projects in this book: Obviously you will need to purchase the Arduino™ UNO board. Some companies sell kits which include most of the parts you require when using this book. You will also need: Sets of jumper wires of different lengths (Male to Male) also a few jumper wires (Male to Female) Red LEDs Green LEDs Yellow LEDs 220R Resistors 10K Resistors 100k Potentiometer 1602 Liquid Crystal Display A couple of lengths of header strip (40Pin 2.54mm Male PCB Single Row Straight Header Strip) RGB LED L293D IC 5 -6v DC Motor 7 Segment Display 74HC595 IC NE555 Timer Tilt switch The following sensors: Temperature sensor: LM35 Temperature/Humidity Sensor: DHT11 Barometric Pressure Sensor BMP085 Photocell Relay Module Servo Accelerometer ADXL33 This book will be laid out in the following format: Title Parts Theory Schematic Breadboard view Code Code explanation Learning Outcomes All code will in a coloured font; blue for complete code, red for snippets in explanations. We will start with a very simple example: How to make an LED blink. Project 1 Blink an LED Parts Arduino™ UNO Breadboard LED (any colour) 220R resistor Connecting wire Theory A Light Emitting Diode (LED) is a semiconductor which when current is passed through it emits light. Most LED’s have a maximum voltage of approximately 1.7v and a maximum current of 30mA. We will only run the LED at half its power, so we will use a current of 15mA. Using Ohms Law: 𝑉 𝑅 = 𝐼 5−1.7 𝑅 = 0.015 3.3 𝑅 = 0.015 𝑅 = 220Ω Therefore we need to put a 220 ohms resistor in the circuit to minimise the current on the LED. What we need to do is switch the LED on for 1 second and off for 1 second. This will be done in the code by putting a delay of 1000mS. This is not theory but you need to get to grips with another piece of software that will help you design your projects. This software is called Fritzing and it is free to download. You will find it at the following site: http://fritzing.org/download/ With this software you can design the schematic diagram (circuit diagram) and design the layout on a breadboard as well as writing the code for the project. Schematic Breadboard View Code /* Blink Turns on an LED on for one second, then off for one second, repeatedly. Most Arduino™ s have an on-board LED you can control. On the Uno and Leonardo, it is attached to digital pin 13. If you're unsure what pin the on-board LED is connected to on your Arduino™ model, check the documentation at http://Arduino™ .cc This example code is in the public domain. modified 8 May 2014 by Scott Fitzgerald */ // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin 13 as an output. pinMode(13, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(13, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second } Code explanation Now let us look at this code in more detail. As we found out previously the code is split into 3 sections. As this is a very simple Project it does not require running a Library file to make it work. We will talk about these later on. In the setup code we have the following: void setup() { // initialize digital pin 13 as an output. pinMode(13, OUTPUT); } The // denotes that what follows on that line is a comment. The next line is the important one! It tells the processor that pin 13 is outputting a voltage signal using the function pinMode. void loop() { digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(13, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second } The second part of the code is the part that does the business. As the LED is connected to pin 13, the line: digitalWrite(13, HIGH); makes the output go high (5v). It then delays for 1000mS (1 sec) and then the command: digitalWrite(13, LOW); turns it off again for 1 sec. As it is in a loop it returns to the first command in the loop and switches it on again and off after 1 sec. It will keep doing this for ever, as long as the board is powered. Now we know how it works we will upload it onto the UNO board. With the circuit connected as in the Breadboard view we will now connect it to our computer. With the USB A type connector connected to your computer, connect the other end to the UNO board. All being well the small ON LED on the board will light up The first thing we need to do is check that the code is error free. At the top of the window under File there is a Tick icon, the Verify button. When you click on this button it will start verifying. It will say in the area under the code that it is Compiling Sketch and there will be activity in the black area underneath. This process may take a few minutes depending on the complexity of the code and the speed of your computer. When it has finished the following screen is displayed and Done Compiling is written in the area below the code.

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.