Search for question
Question

WORKSHOP ONE EMBEDDED SYSTEM DESING ENG 5 ESD Workshop One Introduction to Arduino Arduino Projects Tools and Parts Needed Download the Software Connect Your Arduino Uno.... Exercise 1: Blink an LED Required Parts. Connect The Parts...... Upload The Blink Sketch... Change The Code Exercise 2: LED w/ Switch... Required Parts. Connect The Parts........ Upload The Switch Sketch Troubleshooting. Resources. 2 2 .2 3. 5 6 Error! Bookmark not defined. .7 7 9 11 Error! Bookmark not defined. 11 12 14 14 WORKSHOP ONE EMBEDDED SYSTEM DESING ENG 5 ESD Introduction to Arduino Uno IOREF RESET 3V3 5V GND GND VIN AO AL A2 ANALOG IN RESET ICSP2 AREF GND 13 12 ~11 O UNO DIGITAL (PUM=~) Arduino ION ICSP TXO 1 RXO 0 10 A&COE FGHIJ In the introduction part of this workshop, we're going to show you the steps how to create few simple Arduino projects. These basic projects will help you understand how to set up the Arduino software and then connect the components to perform a specific action. If you have some experiences of Arduino programming, you can jump to exercise one. Tools and Parts Needed In order to complete the projects in this workshop, you'll need to make sure you have the following items. Arduino or Elegoo Uno Board Breadboard - half size Jumper Wires USB Cable LED (5mm) Push button switch WORKSHOP ONE EMBEDDED SYSTEM DESING ENG 5 ESD 10k Ohm Resistor 220 Ohm Resistor Download the Software At this point, we're ready to download the free software known as the IDE. The Arduino IDE is the interface where you will write the sketches that tell the board what to do. (notes: all the PCs in T 719 has the Arduino IDE installed, If you want to try it back you home, you can follow the instruction below, otherwise, you can jump to next section.) You can find the latest version of this software on the Arduino IDE download page. ARDUINO The open-source Arduino Software (IDE) makes it easy to write code and upload it to the board. It runs on Windows, Mac OS X, and Linux. The environment is written in java and based on Processing and other open- source software. This software can be used with any Arduino board. Refer to the Getting Started page for Installation instructions. Windows Installer Windows ZIP file for non admin install Windows app Get Mac OS X 10.7 Lion or newer Linux 32 bits Linux 64 bits Linux ARM Release Notes Source Code Checksums (sha512) To install the software, you will need to click on the link that corresponds with your computer's operating system. Arduino IDE Once the software has been installed on your computer, go ahead and open it up. This is the Arduino IDE and is the place where all the programming will happen. Take some time to look around and get comfortable with it. WORKSHOP ONE EMBEDDED SYSTEM DESING ENG 5 ESD Makerspaces_com | Arduino 1.8.1 1 File Edit Sketch Tools Help 2 Makerspaces_com 3 4 6 5 7 void setup() { } // put your setup code here, to run once: | 9 void loop() { } // put your main code here, to run repeatedly: Done Saving. 10 11 11 8 Arduino/Genuino Uno on COM4 1. Menu Bar: Gives you access to the tools needed for creating and saving Arduino sketches. 2. Verify Button: Compiles your code and checks for errors in spelling or syntax. 3. Upload Button: Sends the code to the board that's connected such as Arduino Uno in this case. Lights on the board will blink rapidly when uploading. 4. New Sketch: Opens up a new window containing a blank sketch. 12 WORKSHOP ONE EMBEDDED SYSTEM DESING ENG 5 ESD 5. Sketch Name: When the sketch is saved, the name of the sketch is displayed here. 6. Open Existing Sketch: Allows you to open a saved sketch or one from the stored examples. 7. Save Sketch: This saves the sketch you currently have open. 8. Serial Monitor: When the board is connected, this will display the serial information of your Arduino 9. Code Area: This area is where you compose the code of the sketch that tells the board what to do. 10. Message Area: This area tells you the status on saving, code compiling, errors and more. 11. Text Console: Shows the details of an error messages, size of the program that was compiled and additional info. 12. Board and Serial Port: Tells you what board is being used and what serial port it's connected to. Connect Your Arduino Uno At this point you are ready to connect your Arduino to your computer. Plug one end of the USB cable to the Arduino Uno and then the other end of the USB to your computer's USB port. Once the board is connected, you will need to go to Tools then Board then finally select Arduino Uno. Makerspaces_com | Arduino 1.8.1 File Edit Sketch Tools Help Х Auto Format Ctrl+T Archive Sketch Makerspaces_ Fix Encoding & Reload Serial Monitor Ctrl+Shift+M // This is th Serial Plotter Ctrl+Shift+L void setup() } // put your void loop() { } // put your WiFi101 Firmware Updater Board: "Arduino/Genuino Uno" Port Get Board Info Programmer: "AVRISP mkII" Burn Bootloader Boards Manager... Arduino AVR Boards Arduino Yún Arduino/Genuino Uno Arduino Duemilanove or Diecimila Arduino Nano Arduino/Genuino Mega or Mega 2560 Arduino Mega ADK Arduino Leonardo. Arduino Leonardo ETH Arduino/Genuino Micro O/n WORKSHOP 02 BUILD YOUR OWN MINI ARDUINOIGATION ENG_5_ESD T719 The main aim of this workshop is to build your own minimum number of components Arduino. The figure 1 shows the schematic drawing of the Arduino UNO R3: UIN +50 GND CMP C1 Leen +303 U5A LMV358IDGKR _SCK U5B LMU358 DGKR x1 POWERSUPPLY DC2100 PURIN PC1 47u +50 U2 GND GND TVT +5U OUT 5+3U3 ON/OFF +50 GND NC/FB 4 LP2985-33DBUR RESET +303 GND GND Arduino(TM) UNO Rev3 ICSP1 MISO2 SCK2 RESET2 3x2 M B GND RESET-N UIN GND 8x1F-H8.5 NCP1117ST50T3G +50 UIN IN OUT BU = PC2C2 474188 GND GND GND +50 GREEN RN40 12/ RN4C 1K GND GND +50 fcsp C4 100n 10x1F-H8.5 ADS/S110 SCL AD4/SDA SDA 3x2 M GND AREF GND SCK MISO RESET2 USB-B TH X2 XUSB B USBUCC MF-MSMF858-2 500mA 228 RN3 RN30RD (PCINT6)PB620 PB6 (PCINT7/OC0A/OC1C)PB7 RESET(PC1/DW) 19 PB5 18 PB4 (T1/PCINT4)P4 17 MISO2 (PDO/MISC/PCINT3)PB3 XTAL2(PCO) (PDIMOSVPCINT2)PB2 21 PBZ ZU4 RESE 19 RESET 16 MOS12 15 SCK2 GND XTAL1 (SCLK/PCINT1)PB1 (SS/PCINTO)PBO 14 +50 AVCC (INT4/CP1/CLK0JPC7 EXTAL2 = KTAL1 CSTCE16M8V53-RØ 16MHZ (SCK)PB5 (MISO)PB4 (MOSI)PB3 XTAL2 (SS)PB2 SS 109 XTAL1 (OCT)PB1 (ICP)PBO SF-H8.5 VCC GND GROUND GND GND TP UUCA 27 UCAP USHIELD USBUCC UVCC RD- 30 108n C2= RO UGND 33 PAD (AINGINT1)PD1 (OCOBAINTOPDO ATMEGA16U2-MU<R> LIGND (OC1A/PCINT8)PC6 (PCINT9/OC1BPCS (PCINT10)PC4 (AIN2/PCINT11)PC2 (CTS/HWB/AIN6/TONT7)PD7 (RTS/AINS/INT6PD6 DICKIAINAIPCINT12PD5 (INTS/AIN3)PD4 (TXD1ANT3)PD3 (RXD1/AIN1ANT2)PD2 AREF 21 ADS/SCL AREF (ADC5)PC5 AVCC ADCLIP CA AD4/SDA AGND (ADC3)PC3 +50 AD2 ^ (ADC2)PC2 VCC (ADC1)PC1 AD1 C6 (ADCO)PCO) ADO 12 100 11 TXLED 102 BX1F-H8.5 10 RXLED +50 (AIN1)PD7 106 MBRXD (AINO)PD6 16 RN2C 105 (T1)PD5 GND 104 (TO)PD4 103 (INT1)PD3 YELLOW (INTO)PD2 102 101 (TXD)PD1 RN28 (RXDIP DO IO ATMEGA328P-PU 1K RX YELLOW MARXD 1K RN1B M8TXD 1 RN4A RN3B 22R 2213 You can Figure 1 Arduino Uno R3 Schematic find it at https://www.arduino.cc/en/uploads/Main/Arduino Uno Rev3- schematic.pdf if you want a good quality drawing of this controller. If you look closely at the Arduino Uno board above, you'll notice that aside from the ATmega328 there really are not very many components. Most of the "extra" parts have to do with either the USB to serial interface or with the internal 5-volt and 3.3-volt regulators. The ATmega328 is a single-chip microcontroller with the following features: 8-bit RISC (Reduced Instruction Set Computer) processor core. Runs at clock speeds from 1MHz to 20MHz. 32Kb Flash Memory. 2Kb SRAM (Static Random Access Memory). 1Kb EEPROM (Electrically Erasable Read Only Memory). 23 GPIO (General Purpose Input-Output) lines. 32 general purpose registers. 12C, SPI, and Serial interfaces. 10-bit Analog to Digital converters - 6 in DIP package, 8 in surface-mount package. WORKSHOP 02 BUILD YOUR OWN MINI ARDUINOIGATION Internal and External Interrupts. ENG_5_ESD T719 With the ATMega 328 and few components, you can build a very simple Arduino which can fulfil all the function of Arduino UNO. In this workshop, we will build such a simple version Arduino and repeat all the experiment we have done in the workshop one. Component Required: ■ A 16MHz crystal. A ATmega328p A 10K resistor. ■ Two 22pf capacitors ■ " A 10uf capacitor A USB to TTL RS232 Converter A LED 220 Ohm resistor 2x push button switch Jumper wires A breadboard A USB A to mini B cable Exercise 1, Build the simple Arduino Build your circuit based on the following figure 2 on a breadboard +5V 22pF 10ΚΩ 10 uF ELECTRONICS HUB 28 +5V 2 3 27 +5V 5 6 7 8 9 10 11 12 ATmega328P +5V 26 25 24 23 22 21 20 19 18 17 13 16 33092 22pF 14 15 16MHz Figure 2 Minimum Component Arduino Circuit USB to TTL Converter DTR RXD TXD VCC CTS GND WORKSHOP 02 BUILD YOUR OWN MINI ARDUINOIGATION ENG_5_ESD T719 When you finish building the circuit, connect it to your PC with the USB A to mini port cable. By default, the LED will flash. If not, press the push button. Otherwise, talk to the lab instructor to help you out. Exercise 2 Repeat exercise 1 of workshop one. Exercise 3 Repeat exercise 2 of workshop one. Please refer to figure one when you map the Arduino Uno pin number with the ATmega 328 pin number./n WORKSHOP TWO SUPPLEMENT DOCUMENT If your ATmega part number is 328 instead of 328p, you need to go through the following step to upload your code to the MCU. 1. Installing Mini-core The 'MiniCore' package from MCUDude is a hardware package which adds support for a range of ATmega devices in the arduino IDE, namely: • ATmega8 ATmega48 • ATmega88 • ATmega168 . ATmega328 • ATmega328PB Step 1 - Open up the Arduino IDE and navigate to the preferences (or press ctrl+,). At the bottom of the page is an empty field next to 'Additional Boards Manager URLs'. You want to copy the following URL in here: https://mcudude.github.io/MiniCore/package_MCUdude_MiniCore_index.jso Preferences Settings Network Sketchbook location: C:\Users Maayan \Documents\Arduino Editor language: System Default Editor font size: 12 Interface scale: Automatic 100 % (requires restart of Arduino) Show verbose output during: compilation upload Compiler warnings: None Display line numbers Browse (requires restart of Arduino) Enable Code Folding Verify code after upload Use external editor Aggressively cache compiled core Check for updates on startup Update sketch files to new extension on save (.pde -> .ino) Save when verifying or uploading Additional Boards Manager URLS: https://mcudude.github.io/MiniCore/package MCUdude_MiniCore_index.json More preferences can be edited directly in the file C:\Users Maayan \AppData\Local\Arduino 15 preferences.txt (edit only when Arduino is not running) HO OK Cancel WORKSHOP TWO SUPPLEMENT DOCUMENT Step 2 - Navigate to the boards manager, which is under Tools>Board>Boards Manager. Here, you'll find a list of boards your Arduino is capable of talking to. ArduinolSP | Arduino 1.8.5 File Edit Sketch Tools Help Auto Format Ctrl+T Archive Sketch ArduinolSP Fix Encoding & Reload // ArduinoISP // Copyright Serial Monitor Ctrl+Shift+M Serial Plotter Ctrl+Shift+L // If you req // http://www // WiFi101 Firmware Updater // This sketc // Board: "Arduino/Genuino Uno" Boards Manager... Port: "COM10 (Arduino/Genuino Uno)" // Pin 10 is // Get Board Info // By default // with the t Programmer: "AVR ISP" // on the ICS Burn Bootloader // 1/ // MISO SCK // .5V (!) Avoid this pin on Due, Zer . . MOSI GND // // On some Arduinos (Uno,...), pins MOSI, MISO and SCK are t // digital pin 11, 12 and 13, respectively. That is why many // you to hook up the target to these pins. If you find this // practical, have a define USE_OLD_STYLE_WIRING. This will // using an Uno. (On an Uno this is not needed). // // Alternatively you can use any other digital pin by config // software ('BitBanged') SPI and having appropriate defines // PIN_MISO and PIN_SCK. 11 Done compiling. Invalid library found in C:\Users\Maayan\Documents\Arduino\li Invalid library found in C:\Users\Maayan\Documents\Arduino\li Invalid library found in C:\Users\Maayan\Documents\Arduino\li < 1 Arduino AVR Boards Arduino Yún Arduino/Genuino Uno Arduino Duemilanove or Diecimila Arduino Nano Arduino/Genuino Mega or Mega 2560 Arduino Mega ADK Arduino Leonardo Arduino Leonardo ETH Arduino/Genuino Micro Arduino Esplora Arduino Mini Arduino Ethernet Arduino Fio Arduino BT LilyPad Arduino USB LilyPad Arduino Arduino Pro or Pro Mini Arduino NG or older Arduino Robot Control Arduino Robot Motor cuments\Ardu cuments\Ardu cuments\Arduv no Uno on COM Step 3 - Type 'minicore' into the search bar and the relevant entry will appear. You'll be able to choose from a list of previous versions, but unless you have a specific goal in mind it's best to opt for the latest. Click 'install' and wait for it to complete. Then close the boards manager window. Boards Manager Type All MiniCore by MCUdude minicore Boards included in this package: ATmega328/P/PA/A/PB, ATmega168/P/PA/A/PB, ATmega88/P/PA/A/PB, ATmega48/P/PA/A/PB, ATmega8. Online help More info 2.0.1 Install Close WORKSHOP TWO SUPPLEMENT DOCUMENT 2. Select your device under the Tools>Board> ATmega328 (instead of Arduino Uno). Make sure the Variant is "328/328A" and the correct port number. Blink | Arduino 1.8.5 File Edit Sketch Tools Help Auto Format Ctrl+T Archive Sketch Blink Fix Encoding & Reload Serial Monitor Ctrl+Shift+M Blink Serial Plotter Ctrl+Shift+L Turns an LE WiFi 101 Firmware Updater cond, repeatedly. Most Arduin it is attac the correct If you want model, chec https://www modified 8 by Scott Fi modified 2 by Arturo G modified 8 by Colby Ne BOD: "BOD 2.7V" Board: "ATmega328" On the UNO, MEGA and ZERO EEPROM: "EEPROM retained" > 6. LED_BUILTIN is set to ed. Variant: "328/ 328A" > nected to on your Arduino Bootloader: "Yes (UARTO)" > > Clock: "External 16 MHz" > Compiler LTO: "LTO disabled" Port > > Get Board Info Programmer: "ArduinolSP" Burn Bootloader This exampl You should be able to upload the code the way as the first workshop./n WORKSHOP 03 CONCURRENCY INVESTIGATION ENG_5_ESD T719 In this workshop, we explore the basic concepts of how to make a microcontroller unit (MCU) perform multiple software activities apparently simultaneously, providing the illusion of concurrent execution. we will consider a system with an MCU, two switches, and an RGB (red, green, blue) LED . . When switch 1 is not pressed, the system displays a repeating sequence of colors (red, then green, then blue). When switch 1 is pressed, the system makes the LED flash white (all LEDs on) and off (all LEDs off) until the switch is released. As long as switch 2 is pressed, faster timing is used for the flashing and RGB sequences. The time delay between the user pressing the switch and seeing the LED flash white is the system's response time for switch 1. A shorter response time is better. How we share the processor's time among the tasks is one of the main factors determining the system's responsiveness. Component Required: (1) x Arduino or Elegoo Uno R3 (1) x Breadboard (4) x M-M wires (Male to Male jumper wires) (1) x RGB LED (3) x 220 ohm resistors (2)x10k ohm resistors (2)x push button switches Component Introduction RGB: At first glance, RGB (Red, Green and Blue) LEDs look just like regular LEDs. However, inside the usual LED package, there are actually three LEDs, one red, one green and yes, one blue. By controlling the brightness of each of the individual LEDs you can mix pretty much any color you want. The RGB LED has four leads. There is one lead going to the positive connection of each of the single LEDs within the package and a single lead that is connected to all three negative sides of the LEDs. Here on the photographs you can see 4 electrode LED. Every separate pin for Green or Blue or Red color is called Anode. You will always connect “+” to it. Cathode goes to “-“(ground). If you connect it other way round the LED will not light. The common negative connection of the LED package is the second pin from the flat side. It is also the longest of the four leads and will be connected to the ground. WORKSHOP 03 CONCURRENCY INVESTIGATION ENG_5_ESD T719 Each LED inside the package requires its own 2200 resistor to prevent too much current flowing through it. The three positive leads of the LEDs (one red, one green and one blue) are connected to UNO output pins using these resistors. RESET BLUE SGREEN CATHODE 3V3 5V NIA DO/RX D1/TX RESET2 AREF IOREF Arduino D2 ww D3 PWM ᎠᏎ D5 PWM D6 PWM D7 AO A1 A2 A3 A4/SDA Uno (Rev3) ICSP D8 D9 PWM A5/SCL D10 PWM/SS 2200 ww D11 PWM/MOSI D12/MISO D13/SCK N/C ICSP2 MISO ICSP2 SCK ICSP2 MOSI Connection Schematic Δ WORKSHOP 03 CONCURRENCY INVESTIGATION ENG_5_ESD T719 Exercise 1 H ELEGOO UNO UNO R3|| TX--1 RX-O Wiring diagram 000 Adding two push button switches to the connection schematic. If you don't know how to do it, read the exercise 2 of workshop one. Build your circuit based on the schematic. You may want to program the Arduino and test if you can light up the RGB LED. It can begin with the modification of the workshop code. Take a photo of your circuit and attach it to your logbook Exercise 2 Download the zip file lab03.zip from the VLE and expand the codes into a folder you created on the desktop. Open the Concurrency_1 folder and sketch files. There are some lines of the code in the setup function need you type in yourself. You can refer to last week's code to get the hint if you don't know how to do it. Or ask the lab instructor. Verify your code and upload to the Arduino if the verifying is successful. Observe the color change of the LED. Press down the button switch one, hold and then release. Write down your observation WORKSHOP 03 CONCURRENCY INVESTIGATION ENG_5_ESD T719 Press button switch two, hold and release, and write down your observations Press both button switches and write down your observations. Exercise 3 Run Concurrency_2, 3, and 4 and repeat the operations of exercise 3 and write down your observations. You might need to change the pin numbers in the circuit for the last three sketches. www 2200 www ww DGND E.CO ELEGOO UNO R3 3: +SV H SW1 Pull Down +5V H SW2 Pull Down You can use this figure to workout connection before you start to build your circuit./n Workshop 04 Digital, analogue input digital and PWM output exercises In workshop 3, we will do three exercises to learn how the Arduino can get the analogue input signals and output the analogue signals. By the end of the workshop, please explain the command we use in this workshop. It will be very helpful for you to the following workshops and even your mini project. Parts Needed (1) Arduino Uno (1) USB A-to-B Cable (1) Breadboard (1) LED 5mm (1) LDR (1) 220 2 Resistor (2) 10k Resistor (1) Active buzzer Jumper Wires Exercise 1 Light Dependent Resistor control the frequency of LED blink In the first exercise, the sketch is based on the LED blinking code from the previous workshop, but instead of using a fixed delay, the rate is determined by a light-sensitive sensor called a light dependent resistor or LDR. Wire the LDR as shown in Figure Lab4- 1 8 DIGITAL 76543250 爻爻 R 22052 Arduino ANALOG 072345 00 00 00 10k vvv www LDR Figure Lab4-1. Arduino with light dependent resistor The following sketch reads the light level of an LDR connected to analog pin 0. The light level striking the LDR will change the blink rate of the the LED connected to pin you choose. const int ledPin = ; // LED connected to digital pin your choose. const int sensorPin = 0; // connect sensor to analog input 0 void setup() pinMode(ledPin, OUTPUT); // enable output on the led pin { } void loop() { } int rate = = analogRead(sensorPin); digitalWrite(ledPin, HIGH); delay(rate); digitalWrite(ledPin, LOW); delay(rate); // read the analog input // set the LED on // wait duration dependent on light level // set the LED off You could add print command in your Arduino code to monitor the value the program reads from the AO port. Add a serial monitor through the Tools menu as shows in the following figure. At same time add two extra line of codes in your program ex1 | Arduino 1.8.19 (Windows Store 1.8.57.0) 3 File Edit Sketch Tools Help 圖 Auto Format Ctrl+T Archive Sketch ex1 Fix Encoding & Reload Manage Libraries... Ctrl+Shift+I Serial Monitor Ctrl+Shift+M const int led Serial Plotter Ctrl+Shift+L const int sen choose. t0 void setup() const int ledPin = 9; // LED connected to digital pin your const int sensorPin = 0; // connect sensor to analog inp void setup() { } Serial.begin(9600); // open the serial port at 9600 bps: pinMode (ledPin, OUTPUT); // enable output on the led pin void loop() { int rate = analogRead(sensorPin); Serial.println(rate); // read the analog in WiFi 101 / WiFiNINA Firmware Updater void setup() Board: "Arduino Uno" Serial.begi pinMode(led Port: "COM7 (Arduino Uno)" > > digitalWrite(ledPin, HIGH); delay(rate); } Get Board Info void loop() // set the LED on // wait duration dependent on light 1 digitalWrite(ledPin, LOW); // set the LED off Programmer: "AVRISP mkll" int rate = put delay(rate); Burn Bootloader } Serial.printantaneey. Figure Lab4-2. Open the Serial Monitor, and add two extra line of codes. Discussion The value of the 10K resistor is not critical. Anything from 1K to 10K can be used. The light level on the LDR will change the voltage level on analog pin 0. The analogRead command provides a value that ranges from around 200 when the LDR is dark to 800 or so when it is very bright. This value determines the duration of the LED on and off times, so the blink time increases with light intensity. Exercise 2 LDR control the frequency of speaker The last exercise is using digital output to switch on and off the light to display the analogue imputes change. In many applications, we need an analogue output to send the control signal to the system. The Arduino using PWM technique for controlling the analogue output. Pulse Width Modulation (PWM) is a technique for controlling power. We can use it here to control the brightness of each of the LEDs. The diagram below shows the signal from one of the PWM pins on the UNO. 5V OV 5V αν 30 5V 1/500 second 1/20 (5%) 10/20 (50%) OV 18/20 (90%) Roughly every 1/500 of a second, the PWM output will produce a pulse. The length of this pulse is controlled by the 'analogWrite' function. So analogWrite(0)' will not produce any pulse at all and 'analogWrite(255)' will produce a pulse that lasts all the way until the next pulse is due, so that the output is actually on all the time. If we specify a value in the analogWrite that is somewhere in between 0 and 255, then we will produce a pulse. If the output pulse is only high for 5% of the time, then whatever we are driving will only receive 5% of fullpower The sketch of exercise 2 is based on the LED blinking code from the exercise 1,but instead of using a delay for LED blinking to sense the change of LDR, here we use an active buzzer sound to demonstrate the LDR resistance change. The wire of the circuit is shown in Figure Lab4-3 DIGITAL Arduino 1654325 ANALOG 072345 10k www www Figure Lab4-3. Connections for a speaker with the LDR circuit const int buzzer = 9; // LED connected to digital pin your choose. const int sensorPin = 0; // connect sensor to analog input 0 void setup() void setup() { } Serial.begin(9600); // open the serial port at 9600 bps: pinMode(buzzer, OUTPUT); // enable output on the led pin void loop() { int rate = analogRead(sensorPin); // read the analog input rate } = rate /4; Serial.println(rate); analogWrite(buzzer, rate); Exercise 3 FADE AN LED WITH PWM By using a PWM pin on the Arduino, you will be able to increase and decrease the intensity of brightness of an LED. Project Diagram Speaker or Piezo Transducer Light Dependent Resistor ZUREY RESET 3v3 5/9 GND GND VIN 40 ANALOG IN RESET ICSP2 AREP DIGITAL (PUM O UNO Arduino ICSP RO 40 ABCD FGHI Project Code 1. Connect the Arduino board to your computer using the USB cable. 2. Open project code 3. Select the board and serial port as outlined in earlier section. 4. Click upload button to send sketch to the Arduino./n WORKSHOP 05 DISTANCE AND TEMPERATURE SENSOR ENG_5_ESD T719 Week 05 Working on Ultrasonic Sensor Module and Temperature Sensor Overview Ultrasonic sensor is great for all kind of projects that need distance measurements, avoiding obstacles as examples. The HC-SR04 is inexpensive and easy to use since we will be using a Library specifically designed for these sensor. DHT11 Temperature and Humidity Sensor. It's accurate enough for most projects that need to keep track of humidity and temperature readings. Again we will be using a Library specifically designed for these sensors that will make our code short and easy to write. This week we will investigate HC-SR04 ultrasonic sensor and DHT11 Temperature and humidity sensor. Exercise 1: Ultrasonic Sensor Module Component Required: (1) x Elegoo Uno R3 (1) x Ultrasonic sensor module (4) x F-M wires (Female to Male DuPontwires) Component Introduction O T HC-SRO4 Ultrasonic sensor Ultrasonic sensor module HC-SR04 provides 2cm-400cm non-contact measurement function, the ranging accuracy can reach to 3mm. The modules includes ultrasonic transmitters, receiver and control circuit. The basic principle of work: (1) Using IO trigger for at least 10us high level signal, (2) The Module automatically sends eight 40 kHz and detect whether there is a pulse signal back. (3) IF the signal back, through high level, time of high output IO duration is the time from sending ultrasonic tore turning. Test distance= (high level time x velocity of sound (340m/s)/2 R WORKSHOP 05 DISTANCE AND TEMPERATURE SENSOR ENG_5_ESD T719 The Timing diagram is shown below. You only need to supply a short 10us pulse to the trigger input to start the ranging, and then the module will send out an 8 cycle burst of ultrasound at 40 kHz and raise its echo. The Echo is a distance object that is pulse width and the range in proportion .You can calculate the range through the time interval between sending trigger signal and receiving echo signal. Formula: us / 58 = centimeters or us / 148 =inch; or: the range = high level time velocity (340M/S) / 2; we suggest to use over 60ms measurement cycle, in order to prevent trigger signal to the echosignal. * 10uS TTL Timing Diagram Trigger Input to Module 8 Cycle Sonic Burst Sonic Burst from Module Echo Pulse Output to User Timeing Circuit Connection Schematic RESET RESET2 AREF 3V3 5V NIA DO/RX D1/TX Input TTL lever signal with a range in proportion D2 ioref D3 PWM ᎠᏎ VCC AO D5 PWM A1 D6 PWM Arduino A2 A3 Uno (Rev3) D7 Trig D8 A4/SDA D9 PWM Echo A5/SCL D10 PWM/SS D11 PWM/MOSI D12/MISO D13/SCK GND HC-SR04 WORKSHOP 05 DISTANCE AND TEMPERATURE SENSOR ENG_5_ESD T719 Code Using a Library designed for these sensors will make our code short and simple. We include the library at the beginning of our code, and then by using simple commands we can control the behavior of the sensor. After wiring, please download the code from VLE and open the program in the code folder and click UPLOAD to upload the program. Open the Serial monitor and record your observation. Test with your hand or other object to see if the sensor can detect the distance correctly or not. Comment on your observation. Exercise 2 DHT11 Temperature and Humidity Sensor Component Required: (1) x Elegoo Uno R3 (1) x DHT11 Temperature and Humiditymodule (3) x F-M wires (Female to Male DuPontwires) Component Introduction Temp and humidity sensor: DHT11 pins 1 VCC 2 DATA 3 NC 4 GND 1 2 3 DHT11 digital temperature and humidity sensor is a composite Sensor which contains a calibrated digital signal output of the temperature and humidity. The dedicated digital modules collection technology and the temperature and humidity sensing technology are applied to ensure that the product has high reliability and WORKSHOP 05 DISTANCE AND TEMPERATURE SENSOR ENG_5_ESD T719 excellent long-term stability. The sensor includes a resistive sense of wet components and a NTC temperature measurement devices, and connects with a high-performance 8-bit microcontroller. Applications: HVAC, dehumidifier, testing and inspection equipment, consumer goods, automotive, automatic control, data loggers, weather stations, home appliances, humidity regulator, medical and other humidity measurement and control. Product parameters Relative humidity: Resolution: 16Bit Repeatability: ±1% RH Accuracy: At 25°C ±5% RH Interchangeability: fully interchangeable Response time: 1/e (63%) of 25°C 6s 1m/s air 6s Hysteresis: <± 0.3% RH Long-term stability: <± 0.5% RH / yr in Temperature: Resolution: 16Bit Repeatability: ±0.2°C Range: At 25°C ±2°C Response time: 1/e (63%) 10S Electrical Characteristics Power supply: DC3.5~5.5V Supply Current: measurement 0.3mA standby 60μА Sampling period: more than 2 seconds Pin Description: 1. the VDD power supply 3.5~5.5V DC 2. DATA serial data, a single bus 3. NC, empty pin 4. GND ground, the negative power N/C RESET RESET2 AREF ioref 3V3 WORKSHOP 05 DISTANCE AND TEMPERATURE SENSOR 5V Connection Schematic VIN DO/RX D1/TX D2 D3 PWM D4 D5 PWM DATA VCC AO A1 D6 PWM A2 A3 Arduino Uno (Rev3) D7 D8 A4/SDA D9 PWM A5/SCL D10 PWM/SS GND D11 PWM/MOSI D12/MISO D13/SCK As you can see we only need 3 connections to the sensor, since one of the pin is not used. The connections are: Voltage, Ground and Signal which can be connected to any Pin on our UNO. GND Code After wiring, please open the program in the code folder ex2 and click UPLOAD to upload the program. If the Upload is successful, the program then open the monitor, we can see the data as below: (It shows the temperature of the environment, we can see it is the degree of lab T719). You may need to install the ENG_5_ESD T719 DHT11/n Workshop 06 DC Motors Controller Overview In this workshop, you will learn how to control a small DC motor using an UNO R3 and a transistor. Component Required: (1) x Elegoo Uno R3 (1) x 830 tie-pointsbreadboard (1) x L293D IC (1) x Fan blade and 3-6v motor (5) x M-M wires (Male to Male jumperwires) (1) x Power Supply Module (1) x 9V1A adapter (1) 9V battery with snap on connector (1) x Potential Meter Component Introduction Breadboard Power Supply The small DC motor is likely to use more power than an UNO R3 board digital output can handle directly. If we tried to connect the motor straight to an UNO R3 board pin, there is a good chance that it could damage the UNO R3 board. So we use a power supply module provides power supply 545043 ZELEGO NE OS GND 00 FOOD 3.30 50 εε 110 ng M DC-1n Product Specifications: . Locking On/Off Switch • LED Power Indicator Input voltage: 6.5-9v (DC) via 5.5mm x 2.1mm plug • Output voltage: 3.3V/5v • Maximum output current: 700 mA • Independent control rail output. Ov, 3.3v, 5v to breadboard Output header pins for convenient external use Size: 2.1 in x 1.4 in USB device connector onboard to power external device Setting up outputvoltage: DC-1n 50 OFF 3.3 3.30 ng GND ID 545043 ZELEGO 5V OFF 3.3 5V 3.3V The left and right voltage output can be configured independently. To select the output voltage, move jumper to the corresponding pins. Note: power indicator LED and the breadboard power rails will not power on if both jumpers are in the "OFF" position. 50 25 GND Th h 545013 38 BELEGO 20 00 00 00 3.30 50 GND DC-10 515013 BELEGO Important note: Make sure that you align the module correctly on the breadboard. The negative pin(-) on module lines up with the blue line(-) on breadboard and that the positive pin(+) lines up with the red line(+). Failure to do so could result in you accidently reversing the power to your project L293D This is a very useful chip. can actually control two motors independently. We are just using half the chip in this lesson, most of the pins on the right hand side of the chip are for controlling a second motor. 0862 Product Specifications: • Featuring Unitrode L293 and L293D Products Now From Texas Instruments • Wide Supply-Voltage Range: 4.5 V to 36 V • Separate Input-Logic Supply • Internal ESD Protection • Thermal Shutdown • • High-Noise-Immunity Inputs Functionally Similar to SGS L293 and SGS L293D • Output Current 1 A Per Channel (600 mA for L293D) • Peak Output Current 2 A Per Channel (1.2 A for L293D) • Output Clamp Diodes for Inductive T ransient Suppression (L293D) Enable 1 In 1 16 +V 15 In 4 3 14 Out 1 (Controlled by Enable 1) Out 4 (Controlled by Enable 2). 13 OV L293D OV 5 12 OV OV 6 11 Out 2 (Controlled by Enable 1) Out 3 (Controlled by Enable 2). 7 10 In 2 +Vmotor In 3 Enable 2 9 Description/ordering information The L293 and L293D are quadruple high-current half-H drivers. The L293 is designed to provide bidirectional drive currents of up to 1 A at voltages from 4.5 V to 36 V. The L293D is designed to provide bidirectional drive currents of up to 600-mA at voltages from 4.5 V to 36 V. Both devices are designed to drive inductive loads such as relays, solenoids, dc and bipolar stepping motors, as well as other high-current/high-voltage loads in positive-supply applications. All inputs are TTL compatible. Each output is a complete totem-pole drive circuit, with a Darlington transistor sink and a pseudo-Darlington source. Drivers are enabled in pairs, with drivers 1 and 2 enabled by 1,2EN and drivers 3 and 4 enabled by 3,4EN. When an enable input is high, the associated drivers are enabled, and their outputs are active and in phase with their inputs. When the enable input is low, those drivers are disabled, and their outputs are off and in the high-impedance state. With the proper data inputs, each pair of drivers forms a full-H (or bridge) reversible drive suitable for solenoid or motor applications. Block diagram Q1 Vcc H 14 Q2 Z M -Q4 Q1 Q3 Q2 Vcc VCC1 M 本 Q4 Q3 Fig. 4.1 H-bridge and the direction of motor Vcc2 There are 3 wires connected to the Arduino, 2 wires connected to the motor, and 1 wire connected to a battery. Note: Pin 16 must be supplied with current, the L293D can work normally. L293D M1 PWM-1 16 Battery +ve M1 direction 0/1 2 15 M2 direction 0/1 M1 +ve 3 14 M2 +ve GND 4 13 GND GND 5 12 GND M1 -ve 6 11 M2 -ve M1 direction 1/0-7 10 M2 direction 1/0 Battery +ve 8 9 M2 PWM Motor 1 Motor 2 To use this pinout: The left hand side deals with the first motor, the right hand side deals with a second motor. Yes, you can run it with only one motor connected. Arduino Connections M1 PWM - connect this to a PWM pin on the Arduino. They're labelled on the Uno, pin 5 is an example. Output any integer between 0 and 255, where 0 will be off, 128 is half speed and 255 is max speed. M1 direction 0/1 and M1 direction 1/0 - Connect these two to two digital Arduino pins. Output one pin as HIGH and the other pin as LOW, and the motor will spin in one direction. Reverse the outputs to LOW and HIGH, and the motor will spin in the other direction./n Workshop 06 LCD1602 Screen & Servo Motor Control Exercise 1 Use LCD 1602 screen. An LCD is a liquid crystal display that is able to display text on its screen. In this project, you should see the words "Hello, Testing" displayed on the screen. The potentiometer is used to adjust the contrast of the display. Parts Needed (1) Arduino Uno (1) USB A-to-B Cable (1) Breadboard - Half Size (1) LCD Screen (1) Potentiometer (16) Jumper Wires Project Diagram 5 VDC GND LCD1602 Display 1 GND Bright RW RS EN Anode 2 5 VDC Cathode 3 Bright 4 RS Data 5 RW 6 EN 7 DO 8 D1 9 D2 10 D3 11 D4 12 D5 13 D6 14 D7 15 Anode 16 Cathode https://dronebotworkshop.com 1. GND – This is the Ground pin. On some modules it is labeled VSS. 2. 5 VDC - This is the 5 volt power connection. On some modules it is labeled VDD. 3. Brightness – This is the input for the brightness control voltage, which varies between 0 and 5 volts to control the display brightness. On some modules this pin is labeled V0. 4. RS - This is the Register Select pin. It controls whether the input data is meant to be displayed on the LCD or used as control characters. 5. RW - Puts the LCD in either Read or Write mode. In most cases you'll be using Read mode so this pin can be tied permanently to ground. 6. EN - The Enable pin. When High it reads the data applied to the data pins. When low it executes the commands or displays the data. 7. DO- Data input 0. 8. D1 - Data input 1. 9. D2 Data input 2. 10. D3 - Data input 3. 11. D4 – Data input 4. 12. D5 - Data input 5. 13. D6 – Data input 6. 14. D7 - Data input 7. 15. A - The Anode (positive voltage) connection to the backlight LED. 16. K – The Cathode (ground or negative voltage) connection to the backlight LCD. Wire Mode Because the LCD module uses a parallel data input it requires 8 connections to the host microcontroller for the data alone. Add that to the other control pins and it consumes a lot of connections. On an Arduino Uno half of the I/O pins would be taken up by the display, which can be problematic if you want to use the I/O pins for other input or output devices. One way of reducing the number of connections required is to use 4-wire mode, and most projects that make use of this display do exactly that. In 4-wire mode the data is sent a half a byte at a time, thus requiring only 4 data connections. The upper half of the data input (D4 to D7) is used while the other pins are not connected to anything. ZUREY RESET 313 SV GND AND 3 VIN ANALOG IN RESET ARCY DIGITAL O UNO Arduino ICSP */ LCD § This sketch will show you how to connect an LCD to your Arduino and display any data you wish. // Load the LiquidCrystal library, which will give us // commands to interface to the LCD: #include <LiquidCrystal.h> // Initialize the library with the pins we're using. // (Note that you can use different pins if needed.) // See http://arduino.cc/en/Reference/Liquid Crystal // for more information: Liquid Crystal lcd (12, 11, 5, 4, 3, 2); void setup() { lcd.begin(16, 2); // Initialize the 16x2 LCD lcd.clear(); //Clear any old data displayed on the LCD lcd.print "Hello, Testing"); // Display a message on the LCD! } void loop() { } lcd.setCursor(0, 1); // Set the (invisible) cursor to column 0, // row 1. lcd.print (millis() 10); //Print the number of 10 ms //since the Arduino last reset. How to change the code to count "seconds"? Exercise 2: Servo motor control In this project, you will be able to sweep a servo back and forth through its full range of motion. Parts Needed (1) Arduino Uno (1) USB A-to-B Cable (1) Breadboard - Half Size (1) Continuous rotation servo motor (6) Jumper Wires Project Continuous Rotation Servo Motor Timing In a continuous rotation servo motor the same PWM signals will cause the motor to perform differently. Servo Motors Continuous Rotation Servo 1.5 ms 1.0 ms 2.0 ms [20 ms Diagram not to scale Stop CCW CW https://dronebotworkshop.com ■ A pulse width of 1.5ms will cause the servo shaft stop spinning. ■ ■ A pulse width of 1ms will cause the servo shaft to spin at full speed counter-clockwise. A pulse width of 2ms will cause the servo shaft to spin at full speed clockwise. Varying the pulse width between 1ms and 1.5ms will make the motor spin counter clockwise with the shorter pulse widths causing the motor to spin faster. Varying the pulse width between 1.5ms and 2ms will cause the motor to rotate clockwise with the longer pulses resulting in a faster speed. Commercial continuous rotation servo motors will have an adjustment potentiometer that can be used to zero the speed when the motor is feed a 1.5ms pulse width. COREY RESET 343 VIN wwwww RESET ICSPR O UNO Arduino ICSP SERVO Servo-simple #include <Servo.h> Servo servoMain; void setup() { } servoMain.attach (9); void loop() { servoMain.write(180); // full speed anti-clockwise rotation delay(1000); servoMain.write(0); // full speed clockwise rotation delay(1000); servoMain.write(95); //stop delay(1000); servoMain.write(80); // low speed clockwise rotation delay(1000); servoMain.write(105); // low speed anti-clockwise rotation delay(1000); } Control servo by a potentiometer/nWORKSHOP MANUAL I have also uploaded a file that introduces an Arduino simulator you can use for your workshop exercises. You need to maintain a logbook for your workshop. It could be a physical one or an electronic one. Make sure that your comments on each line of the codes in the first four weeks at least.