background image

 

                                                     

 

 

 

 

 

Summary of Contents for Basic starter kit

Page 1: ...1 ...

Page 2: ...ive buzzer 26 Project 8 Passive buzzer 30 Project 9 RGB LED 33 Project 10 Photo resistor 36 Project 11 Flame sensor 39 Project 12 LM35 temperature sensor 44 Project 13 Tilt switch 47 Project 14 IR remote control 50 Project 15 Analog value reading 59 Project 16 74HC595 63 Project 17 1 digit LED segment display 67 Project 18 4 digit LED segment display 74 Project 19 8 8 LED matrix 83 Project 20 1602...

Page 3: ...rduino You will have a set of Arduino s most common and useful electronic components What s more We will offer you a detailed tutorials including project introduction and their source codes You may learn about Arduino through using these basic projects This kit will help you control the physical world with sensors ...

Page 4: ...zzer active 1x Buzzer active 1x Buzzer passive 1x Buzzer passive 1x Buzzer passive 1x Flame sensor 1x Flame sensor 1x Flame sensor 1x IR receiver 1x IR receiver 1x IR receiver 1x IR remote control 1x IR remote control 1x IR remote control 1x LM35 Temp Sensor 1x LM35 Temp Sensor 1x LM35 Temp Sensor 2x Ball tilt sensor 2x Ball tilt sensor 2x Ball tilt sensor 3x Photo Resistor 3x Photo Resistor 3x Ph...

Page 5: ...ntrolled LED 7 Active buzzer 8 Passive buzzer 9 RGB LED 10 Photo resistor 11 Flame sensor 12 LM35 temperature sensor 13 Tilt switch 14 IR remote control 15 Analog value reading 16 74HC595 17 1 digit LED segment display 18 4 digit LED segment display 19 8 8 LED matrix 20 1602 LCD 21 9g servo control ...

Page 6: ... without instruction A simple If statement will do the instruction trick With the onboard LED connected to pin 13 we can instruct the LED to blink first when Arduino gets an instruction and then print Hello World int val define variable val int ledpin 13 define digital interface 13 void setup Serial begin 9600 set the baud rate at 9600 to match the software set up When connected to a specific devi...

Page 7: ...keyestudio www keyestudio cc 5 digitalWrite ledpin LOW set the LED on digital pin 13 off delay 500 Serial println Hello World display Hello World string Result Screenshot ...

Page 8: ...studio www keyestudio cc 6 Click serial port monitor Input R LED 13 will blink once PC will receive information from Arduino Hello World After you choose the right port the experiment should be easy for you ...

Page 9: ...tal pins rather than using LED13 which is soldered to the board Except an Arduino and an USB cable we will need extra parts as below Hardware required 1 Red M5 LED 1 2 220Ω resistor 1 3 Breadboard 1 4 Breadboard jumper wires several We follow below diagram from the experimental schematic link Here we use digital pin 10 We connect LED to a 220 ohm resistor to avoid high current damaging the LED Con...

Page 10: ...keyestudio www keyestudio cc 8 Connection for 2560 R3 ...

Page 11: ... digitalWrite ledPin HIGH set the LED on delay 1000 wait for a second digitalWrite ledPin LOW set the LED off delay 1000 wait for a second Result After downloading this program in the experiment you will see the LED connected to pin 10 turning on and off with an interval approximately one second The blinking LED experiment is now completed Thank you Project 3 PWM ...

Page 12: ... or 0V OFF The voltage or current is fed to the analog load the device that uses the power by repeated pulse sequence being ON or OFF Being on the current is fed to the load being off it s not With adequate bandwidth any analog value can be encoded using PWM The output voltage value is calculated via the on and off time Output voltage turn on time pulse time maximum voltage value PWM has many appl...

Page 13: ...ol digital pin also one about potentiometer This time we will use a potentiometer to control the brightness of the LED Hardware required 1 Potentiometer module 1 2 Red M5 LED 1 3 220Ω resistor 4 Breadboard 1 5 Breadboard jumper wires several The input of potentiometer is analog so we connect it to analog port and LED to PWM port Different PWM signal can regulate the brightness of the LED Connectio...

Page 14: ...rt will be displaying the analog value on the screen You can consider this as the analog value reading project adding the PWM analog value assigning part Below is a sample program for your reference int potpin 0 initialize analog pin 0 int ledpin 11 initialize digital pin 11 PWM output int val 0 Temporarily store variables value from the sensor void setup pinMode ledpin OUTPUT define digital pin 1...

Page 15: ...ntln val display value of val analogWrite ledpin val 4 turn on LED and set up brightness maximum output of PWM is 255 delay 10 wait for 0 01 second Result After downloading the program when we rotate the potentiometer knob we can see changes of the displaying value also obvious change of the LED brightness on the breadboard ...

Page 16: ...s and do a bit more complicated experiment traffic lights Actually these two experiments are similar While in this traffic lights experiment we use 3 LEDs with different color other than 1 LED Hardware required 1 Arduino board 1 2 USB cable 1 3 Red M5 LED 1 4 Yellow M5 LED 1 5 Green M5 LED 1 6 220Ω resistor 3 7 Breadboard 1 8 Breadboard jumper wires several Connection for R3 ...

Page 17: ...keyestudio www keyestudio cc 15 Connection for 2560 R3 ...

Page 18: ...y time which is much simpler than C language int redled 10 initialize digital pin 8 int yellowled 7 initialize digital pin 7 int greenled 4 initialize digital pin 4 void setup pinMode redled OUTPUT set the pin with red LED as output pinMode yellowled OUTPUT set the pin with yellow LED as output pinMode greenled OUTPUT set the pin with green LED as output void loop digitalWrite greenled HIGH turn o...

Page 19: ...digitalWrite redled HIGH turn on red LED delay 5000 wait 5 second digitalWrite redled LOW turn off red LED Result When the uploading process is completed we can see traffic lights of our own design Note this circuit design is very similar with the one in LED chase effect The green light will be on for 5 seconds and then off followed by the yellow light blinking for 3 times and then the red light o...

Page 20: ...duction We often see billboards composed of colorful LEDs They are constantly changing to form various effects In this experiment we compile a program to simulate chase effect Hardware required 1 Led x6 2 220Ω resistor x6 3 Colorful breadboard wires Connection for R3 ...

Page 21: ...keyestudio www keyestudio cc 19 Connection for 2560 R3 ...

Page 22: ...keyestudio www keyestudio cc 20 Sample program int BASE 2 the I O pin for the first LED int NUM 6 number of LEDs void setup for int i BASE i BASE NUM i pinMode i OUTPUT set I O pins as output ...

Page 23: ... BASE i BASE NUM i digitalWrite i LOW set I O pins as low turn off LEDs one by one delay 200 delay for int i BASE i BASE NUM i digitalWrite i HIGH set I O pins as high turn on LEDs one by one delay 200 delay Result You can see the LEDs blink by sequence ...

Page 24: ... the output value of device connecting to it We use 1 button and 1 LED using both input and output to give you a better understanding of the I O function Button switches familiar to most of us are a switch value digital value component When it s pressed the circuit is in closed conducting state Hardware required 1 Button switch 1 2 Red M5 LED 1 3 220Ω resistor 1 4 10KΩ resistor 1 5 Breadboard 1 6 ...

Page 25: ...keyestudio www keyestudio cc 23 Connection for 2560 R3 ...

Page 26: ... language so statements of C language such as while switch etc can certainly be used for Arduino program When we press the button pin 7 will output high level We can program pin 11 to output high level and turn on the LED When pin 7 outputs low level pin 11 also outputs low level and the LED remains off int ledpin 11 initialize pin 11 int inpin 7 initialize pin 7 int val define val void setup pinM...

Page 27: ...gitalWrite ledpin HIGH Result When the button is pressed LED is on otherwise LED remains off After the above process the button controlled LED experiment is completed The simple principle of this experiment is widely used in a variety of circuit and electric appliances You can easily come across it in your every day life One typical example is when you press a certain key of your phone the backlig...

Page 28: ...he sound experiment is usually done with a buzzer or a speaker while buzzer is simpler and easier to use The buzzer we introduced here is a passive buzzer It cannot be actuated by itself but by external pulse frequencies Different frequencies produce different sounds We can use Arduino to code the melody of a song which is actually fun and simple Hardware required 1 Buzzer 1 2 Key 1 3 Breadboard 1...

Page 29: ...keyestudio www keyestudio cc 27 Connection for 2560 R3 ...

Page 30: ...n see there are red and black lines When the circuit is finished you can begin programming Sample program Program is simple You control the buzzer by outputting high low level int buzzer 8 initialize digital IO pin that controls the buzzer void setup pinMode buzzer OUTPUT set pin mode as output void loop digitalWrite buzzer HIGH produce sound ...

Page 31: ...keyestudio www keyestudio cc 29 Result After downloading the program the buzzer experiment is completed You can see the buzzer is ringing ...

Page 32: ...n produce sound Normally the experiment is done with a buzzer or a speaker while buzzer is simpler and easier to use The buzzer we introduced here is a passive buzzer It cannot be actuated by itself but by external pulse frequencies Different frequencies produce different sounds We can use Arduino to code the melody of a song which is actually quite fun and simple Hardware required 1 Passive buzze...

Page 33: ... int buzzer 8 select digital IO pin for the buzzer void setup pinMode buzzer OUTPUT set digital IO pin pattern OUTPUT to be output void loop unsigned char i j define variable while 1 for i 0 i 80 i output a frequency sound digitalWrite buzzer HIGH sound delay 1 delay1ms ...

Page 34: ...digitalWrite buzzer LOW not sound delay 1 ms delay for i 0 i 100 i output a frequency sound digitalWrite buzzer HIGH sound digitalWrite buzzer LOW not sound delay 2 2ms delay After downloading the program buzzer experiment is finished ...

Page 35: ...LED Introduction Tricolor principle to display various colors PWM controlling ports to display full color Can be driven directly by Arduino PWM interfaces Hardware Required Arduino controller 1 USB cable 1 Full color LED module 1 Connection for R3 ...

Page 36: ...560 R3 Sample program int redpin 11 select the pin for the red LED int bluepin 10 select the pin for the blue LED int greenpin 9 select the pin for the green LED int val void setup pinMode redpin OUTPUT pinMode bluepin OUTPUT pinMode greenpin OUTPUT ...

Page 37: ... 11 val analogWrite 10 255 val analogWrite 9 128 val delay 1 for val 0 val 255 val analogWrite 11 val analogWrite 10 255 val analogWrite 9 128 val delay 1 Serial println val DEC Result Directly copy the above code into arduino IDE and click upload wait a few seconds you can see a full color LED ...

Page 38: ...stor is commonly applied in the measurement of light light control and photovoltaic conversion convert the change of light into the change of electricity Photo resistor is also being widely applied to various light control circuit such as light control and adjustment optical switches etc We will start with a relatively simple experiment regarding photovaristor application Photovaristor is an eleme...

Page 39: ...keyestudio www keyestudio cc 37 Connection for 2560 R3 ...

Page 40: ...ristor int ledpin 11 initialize digital pin 11 output regulating the brightness of LED int val 0 initialize variable va void setup pinMode ledpin OUTPUT set digital pin 11 as output Serial begin 9600 set baud rate at 9600 void loop val analogRead potpin read the analog value of the sensor and assign it to val Serial println val display the value of val analogWrite ledpin val turn on the LED and se...

Page 41: ...fire source This sensor is of high sensitivity to flame Below is a photo of it Working principle Flame sensor is made based on the principle that infrared ray is highly sensitive to flame It has a specially designed infrared receiving tube to detect fire and then convert the flame brightness to fluctuating level signal The signals are then input into the central processor and be dealt with accordi...

Page 42: ...er 1 3 10K resistor x1 4 Breadboard jumper wires several Experiment connection 1 Connecting buzzer Connect the controller board prototype board breadboard and USB cable according to the Arduino tutorial Connect the buzzer to digital pin 8 2 Connecting flame sensor The negative of infrared receiving triode Connect to analog pin The positive of infrared receiving triode Flame sensor ...

Page 43: ...keyestudio www keyestudio cc 41 Connect the sensor to analog pin 0 Connection for R3 Connection for 2560 R3 ...

Page 44: ...s around 0 3V when there is fire approaching the voltage it reads is around 1 0V tthe nearer the fire the higher the voltage So in the beginning of the program you can initialize voltage value i no fire value Then continuously read the analog voltage value j and obtain difference value k j i compare k with 0 6V 123 in binary to determine whether or not there is a fire approaching if yes the buzzer...

Page 45: ... Serial begin 9600 set baud rate at 9600 void loop val analogRead flame read the analog value of the sensor Serial println val output and display the analog value if val 600 when the analog value is larger than 600 the buzzer will buzz digitalWrite Beep HIGH else digitalWrite Beep LOW delay 500 Result This program can simulate an alarm when there is a fire Everything is normal when there is no fir...

Page 46: ...emperature sensor It does not require other hardware You just need an analog port to make it work The difficulty lies in compiling the code to convert the analog value it reads to celsius temperature Hardware required 1 LM35 1 2 Breadboard 1 3 Breadboard jumper wires several Connection for R3 Connection for 2560 R3 ...

Page 47: ...0 void loop int val define variable int dat define variable val analogRead 0 read the analog value of the sensor and assign it to val dat 125 val 8 temperature calculation formula Serial print Tep output and display characters beginning with Tep Serial print dat output and display value of dat Serial println C display C characters delay 500 wait for 0 5 second ...

Page 48: ...keyestudio www keyestudio cc 46 Result After downloading the program you can open the monitoring window to see current temperature ...

Page 49: ...io cc 47 Project 13 Tilt switch Introduction Tilt switch controlling the ON and OFF of LED Hardware required 1 Ball switch 1 2 Led 1 3 220Ω resistor 1 4 Breadboard jumper wires several Connection for R3 Connection for 2560 R3 ...

Page 50: ...is on The voltage of the analog port is about 5V 1023 in binary The LED will be on When the other end of the switch is below horizontal position the switch is off The voltage of the analog port is about 0V 0 in binary The LED will be off In the program we determine whether the switch is on or off according to the voltage value of the analog port whether it s above 2 5V 512 in binary or not Sample ...

Page 51: ... if larger that 512 2 5V digitalWrite 8 LOW turn on LED else otherwise digitalWrite 8 HIGH turn off LED Result Hold the breadboard with your hand Tilt it to a certain extent the LED will be on If there is no tilt the LED will be off The principle of this experiment can be applied to relay control Experiment completed Thank you ...

Page 52: ...ulation Working principal The built in receiver converts the light signal it received from the sender into feeble electrical signal The signal will be amplified by the IC amplifier After automatic gain control band pass filtering demodulation wave shaping it returns to the original code The code is then input to the code identification circuit by the receiver s signal output pin The pin and the co...

Page 53: ...n First connect the controller board then connect the infrared receiver as the above mentioned connect VOUT to digital pin 11 connect the LEDs with resistors and connect the resisters to pin 2 3 4 5 6 7 Connection for R3 Connection for 2560 R3 ...

Page 54: ...oding method we use here is NEC protocol Below is a brief introduction NEC protocol Features 1 8 bit address and 8 bit command length 2 address and command are transmitted twice for reliability 3 pulse distance modulation 4 carrier frequency of 38 KHZ 5 bit time of 1 125ms or 2 25ms Protocol is as below Definition of logical 0 and 1 is as below ...

Page 55: ...ransmitted twice The second time all bits are inverted and can be used for verification of the received message The total transmission time is constant because every bit is repeated with its inverted length If you are not interested in this reliability you can ignore the inverted values or you can expend the Address and Command to 16 bits each Pulse transmitted when button is pressed and released ...

Page 56: ...ou see Sample program include IRremote h int RECV_PIN 11 int LED1 2 int LED2 3 int LED3 4 int LED4 5 int LED5 6 int LED6 7 long on1 0x00FFA25D long off1 0x00FFE01F long on2 0x00FF629D long off2 0x00FFA857 long on3 0x00FFE21D long off3 0x00FF906F long on4 0x00FF22DD long off4 0x00FF6897 long on5 0x00FF02FD long off5 0x00FF9867 long on6 0x00FFC23D long off6 0x00FFB047 IRrecv irrecv RECV_PIN decode_r...

Page 57: ...ial print Decoded RC5 else if results decode_type RC6 Serial print Decoded RC6 Serial print results value HEX Serial print Serial print results bits DEC Serial println bits Serial print Raw Serial print count DEC Serial print for int i 0 i count i if i 2 1 Serial print results rawbuf i USECPERTICK DEC else Serial print int results rawbuf i USECPERTICK DEC Serial print Serial println ...

Page 58: ...RIn Start the receiver int on 0 unsigned long last millis void loop if irrecv decode results If it s been at least 1 4 second since the last IR received toggle the relay if millis last 250 on on digitalWrite 8 on HIGH LOW digitalWrite 13 on HIGH LOW dump results if results value on1 digitalWrite LED1 HIGH if results value off1 digitalWrite LED1 LOW if results value on2 digitalWrite LED2 HIGH if re...

Page 59: ...rite LED5 HIGH if results value off5 digitalWrite LED5 LOW if results value on6 digitalWrite LED6 HIGH if results value off6 digitalWrite LED6 LOW last millis irrecv resume Receive the next value Program function Decode the coded pulse signal emitted by the remote controller execute corresponding action according to the results of the decoding In this way you will be able to control your device wi...

Page 60: ...keyestudio www keyestudio cc 58 Note add IRremote folder into installation directory Arduino compiler libraries or you will not be able to compile For example C Program Files Arduino libraries ...

Page 61: ...14 19 After a brief introduction let s begin our project Potentiometer used here is a typical output component of analog value that is familiar to us Hardware required Potentiometer 1 Breadboard 1 Breadboard jumper wires several Connection In this experiment we will convert the resistance value of the potentiometer to analog ones and display it on the screen This is an application we need to maste...

Page 62: ...keyestudio www keyestudio cc 60 Connection for 2560 R3 ...

Page 63: ...ication between Arduino and PC so the baud rate of the Arduino should match the the one in the PC s software set up Otherwise the display will be messy codes or no display at all In the lower right corner of the Arduino software monitor window there is a button for baud rate set up The set up here needs to match the one in the program The statement in the program is Serial begin enclosed is the ba...

Page 64: ...og pin 0 and assign it to val Serial println val display val s value Result The sample program uses the built in LED connected to pin 13 Each time the device reads a value the LED blinks Below is the analog value it reads When you rotate the potentiometer knob you can see the displayed value changes The reading of analog value is a very common function since most sensors output analog value After ...

Page 65: ...out how many I O it takes for an Arduino to control 8 LEDs Yes 8 For an Arduino 168 it has only 20 I O including analog ports So to save port resources we use 74HC595 to reduce the number of ports it needs Using 74HC595 enables us to use 3 digital I O port to control 8 LEDs Hardware required 74HC595 chip 1 Red M5 LED 4 Green M5 LED 4 220Ω resistor 8 Breadboard 1 Breadboard jumper wires several Not...

Page 66: ...keyestudio www keyestudio cc 64 Connection for 2560 R3 ...

Page 67: ...t easy Sample program int data 2 set pin 14 of 74HC595as data input pin SI int clock 5 set pin 11 of 74hc595 as clock pin SCK int latch 4 set pin 12 of 74hc595 as output latch RCK int ledState 0 const int ON HIGH const int OFF LOW void setup pinMode data OUTPUT pinMode clock OUTPUT pinMode latch OUTPUT void loop ...

Page 68: ...ateLEDs i delay 500 void updateLEDs int value digitalWrite latch LOW shiftOut data clock MSBFIRST value serial data output high level first digitalWrite latch HIGH latch Result After downloading the program you can see 8 LEDs displaying 8 bit binary number ...

Page 69: ...display refers to the one that combine all the anodes of LED units into one common anode COM For the common anode display connect the common anode COM to 5V When the cathode level of a certain segment is low the segment is on when the cathode level of a certain segment is high the segment is off For the common cathode display connect the common cathode COM to GND When the anode level of a certain ...

Page 70: ...keyestudio www keyestudio cc 68 Breadboard 1 Breadboard jumper wires several Connection Refer to below connection diagram for circuit connection Connection for R3 Connection for 2560 R3 ...

Page 71: ... display one number every 2 seconds cycling display number 0 9 The displaying time for each number is subject to the delay time the longer the delay time the longer the displaying time set the IO pin for each segment int a 7 set digital pin 7 for segment a int b 6 set digital pin 6 for segment b int c 5 set digital pin 5 for segment c int d 10 set digital pin 10 for segment d int e 11 set digital ...

Page 72: ... level as high for pin 5 turn on segment c digitalWrite b HIGH turn on segment b for j 7 j 11 j turn off other segments digitalWrite j LOW digitalWrite dp LOW turn off segment dp void digital_2 void display number 2 unsigned char j digitalWrite b HIGH digitalWrite a HIGH for j 9 j 11 j digitalWrite j HIGH digitalWrite dp LOW digitalWrite c LOW digitalWrite f LOW void digital_3 void display number ...

Page 73: ...rite d LOW void digital_5 void display number 5 unsigned char j digitalWrite a HIGH digitalWrite b LOW digitalWrite c HIGH digitalWrite d HIGH digitalWrite e LOW digitalWrite f HIGH digitalWrite g HIGH digitalWrite dp LOW void digital_6 void display number 6 unsigned char j for j 7 j 11 j digitalWrite j HIGH digitalWrite c HIGH digitalWrite dp LOW digitalWrite b LOW void digital_7 void display num...

Page 74: ...har j digitalWrite a HIGH digitalWrite b HIGH digitalWrite c HIGH digitalWrite d HIGH digitalWrite e LOW digitalWrite f HIGH digitalWrite g HIGH digitalWrite dp LOW void setup int i set variable for i 4 i 11 i pinMode i OUTPUT set pin 4 11as output void loop while 1 digital_0 display number 0 delay 1000 wait for 1s digital_1 display number 1 delay 1000 wait for 1s digital_2 display number 2 delay ...

Page 75: ... 1s digital_5 display number 5 delay 1000 wait for 1s digital_6 display number 6 delay 1000 wait for 1s digital_7 display number 7 delay 1000 wait for 1s digital_8 display number 8 delay 1000 wait for 1s digital_9 display number 9 delay 1000 wait for 1s Result LED segment display displays number 0 to 9 ...

Page 76: ...method is that it requires fewer resistors only 4 But it cannot maintain consistent brightness 1 the brightest 8 the least bright Another method is to connect one resistor to each pin It guarantees consistent brightness but requires more resistors In this experiment we use 8 220Ω resistors we use 220Ω resistors because no 100Ω resistor available If you use 100Ω the displaying will be brighter Conn...

Page 77: ...keyestudio www keyestudio cc 75 Manual for LED segment display ...

Page 78: ...keyestudio www keyestudio cc 76 Connection for R3 Connection for 2560 R3 ...

Page 79: ...am display 1234 select pin for cathode int a 1 int b 2 int c 3 int d 4 int e 5 int f 6 int g 7 int dp 8 select pin for anode int d4 9 int d3 10 int d2 11 int d1 12 set variable long n 1230 int x 100 int del 55 fine adjustment for clock void setup ...

Page 80: ...d OUTPUT pinMode e OUTPUT pinMode f OUTPUT pinMode g OUTPUT pinMode dp OUTPUT void loop Display 1 1 Display 2 2 Display 3 3 Display 4 4 void WeiXuan unsigned char n switch n case 1 digitalWrite d1 LOW digitalWrite d2 HIGH digitalWrite d3 HIGH digitalWrite d4 HIGH break case 2 digitalWrite d1 HIGH digitalWrite d2 LOW digitalWrite d3 HIGH digitalWrite d4 HIGH break ...

Page 81: ...break default digitalWrite d1 HIGH digitalWrite d2 HIGH digitalWrite d3 HIGH digitalWrite d4 HIGH break void Num_0 digitalWrite a HIGH digitalWrite b HIGH digitalWrite c HIGH digitalWrite d HIGH digitalWrite e HIGH digitalWrite f HIGH digitalWrite g LOW digitalWrite dp LOW void Num_1 digitalWrite a LOW digitalWrite b HIGH digitalWrite c HIGH digitalWrite d LOW digitalWrite e LOW digitalWrite f LOW...

Page 82: ... dp LOW void Num_3 digitalWrite a HIGH digitalWrite b HIGH digitalWrite c HIGH digitalWrite d HIGH digitalWrite e LOW digitalWrite f LOW digitalWrite g HIGH digitalWrite dp LOW void Num_4 digitalWrite a LOW digitalWrite b HIGH digitalWrite c HIGH digitalWrite d LOW digitalWrite e LOW digitalWrite f HIGH digitalWrite g HIGH digitalWrite dp LOW void Num_5 digitalWrite a HIGH digitalWrite b LOW digit...

Page 83: ...italWrite e HIGH digitalWrite f HIGH digitalWrite g HIGH digitalWrite dp LOW void Num_7 digitalWrite a HIGH digitalWrite b HIGH digitalWrite c HIGH digitalWrite d LOW digitalWrite e LOW digitalWrite f LOW digitalWrite g LOW digitalWrite dp LOW void Num_8 digitalWrite a HIGH digitalWrite b HIGH digitalWrite c HIGH digitalWrite d HIGH digitalWrite e HIGH digitalWrite f HIGH digitalWrite g HIGH digit...

Page 84: ...p LOW void Clear clear the screen digitalWrite a LOW digitalWrite b LOW digitalWrite c LOW digitalWrite d LOW digitalWrite e LOW digitalWrite f LOW digitalWrite g LOW digitalWrite dp LOW void pickNumber unsigned char n select number switch n case 0 Num_0 break case 1 Num_1 break case 2 Num_2 break case 3 Num_3 break case 4 Num_4 break case 5 Num_5 break case 6 Num_6 break case 7 Num_7 ...

Page 85: ... screen Result Download the above code to the controller board and see the result The experiment result displays 1234 on the display Note if it s not displaying correctly check the wiring Thank you Project 19 8 8 LED matrix Introduction LED matrix is very common and useful in our life It s used in advertising LED display elevator floor display displays in bus station and so on Let s begin the lear...

Page 86: ...g as the corresponding X Y axes of an LED are in forward bias voltage the LED will be turned on For example if you want to turn on the upper left LED Y0 1 X0 0 will do the trick When used you can connect the current limit resistor on either X axis or Y axis 8 8 LED matrix scanning mode Pins on 8X8 LED matrix welding surface Picture of 8X8 LED matrix and pin layout ...

Page 87: ... if you want to turn on the first row set pin 9 with high level and pin 13 3 4 10 6 11 15 16 with low level if you want to turn on the first column set pin 13 with low level and pin 9 14 8 12 1 7 2 5 with high level Generally the LED matrix we used for displaying Chinese characters in Song typeface is 16 16 LED matrix Each Chinese character is displayed within this 16 16 area which means you need ...

Page 88: ...ogram for displaying 0 set an array to store character of 0 unsigned char Text 0x00 0x1c 0x22 0x22 0x22 0x22 0x22 0x1c void Draw_point unsigned char x unsigned char y point drawing function clear_ digitalWrite x 2 HIGH digitalWrite y 10 LOW delay 1 void show_num void display function call point drawing function unsigned char i j data for i 0 i 8 i data Text i for j 0 j 8 j if data 0x01 Draw_point ...

Page 89: ...www keyestudio cc 87 for i 2 i 18 i pinMode i OUTPUT clear_ void loop show_num void clear_ void clear screen for int i 2 i 10 i digitalWrite i LOW for int i 0 i 8 i digitalWrite i 10 HIGH Result Connection for R3 ...

Page 90: ...keyestudio www keyestudio cc 88 Connection for 2560 R3 ...

Page 91: ...0 3 1 row selection 1 4 2 row selection 2 5 3 row selection 3 6 4 row selection 4 7 5 row selection 5 8 6 row selection 6 9 7 row selection 7 Arduino 8x8 LED matrix 10 A column selection A 11 B column selection B 12 C column selection C 13 D column selection D 14 E column selection E 15 F column selection F 16 G column selection G 17 H column selection H Picture of 8X8 LED matrix and pin layout Pi...

Page 92: ...gnal 11 D4 Date I O 4 RS Select data command V L 12 D5 Date I O 5 R W Select read write H L 13 D6 Date I O 6 E Enable signal 14 D7 Date I O 7 D0 Date I O 15 BLA Back light power positive 8 D1 Date I O 16 BLK Back light power negative Interface description 1 two power sources one for module power another one for back light generally use 5V In this project we use 3 3V for back light 2 VL is the pin ...

Page 93: ...7 is 8 bit bidirectional parallel bus used for command and data transmission 7 BLA is anode for back light BLK cathode for back light 4 basic operations of 1602LCD Read status input RS L R W H E H output D0 D7 status word Write command input RS L R W H D0 D7 command code E high pulse output none Read data input RS H R W H E H output D0 D7 data Write data input RS H R W L D0 D7 data E high pulse ou...

Page 94: ...keyestudio www keyestudio cc 92 ...

Page 95: ...keyestudio www keyestudio cc 93 Connection for R3 Connection for 2560 R3 ...

Page 96: ... for signal identification here it s used for signal inversion value 1 digitalWrite Enable LOW delayMicroseconds 1 digitalWrite Enable HIGH delayMicroseconds 1 wait for 1ms digitalWrite Enable LOW delayMicroseconds 1 wait for 1ms void LcdDataWrite int value initialize all pins int i 0 digitalWrite DI HIGH digitalWrite RW LOW for i DB 0 i DB 7 i digitalWrite i value 01 value 1 digitalWrite Enable L...

Page 97: ...ect as 8 bit interface 2 line display 5x7 character size delay 20 LcdCommandWrite 0x06 set input mode auto increment no display of shifting delay 20 LcdCommandWrite 0x0E display setup turn on the monitor cursor on no flickering delay 20 LcdCommandWrite 0x01 clear the scree cursor position returns to 0 delay 100 LcdCommandWrite 0x80 display setup turn on the monitor cursor on no flickering delay 20...

Page 98: ...LcdDataWrite LcdDataWrite w LcdDataWrite o LcdDataWrite r LcdDataWrite k LcdDataWrite s LcdDataWrite h LcdDataWrite o LcdDataWrite p delay 5000 LcdCommandWrite 0x01 clear the screen cursor returns to 0 delay 10 LcdDataWrite I LcdDataWrite LcdDataWrite a LcdDataWrite m LcdDataWrite LcdDataWrite h LcdDataWrite o LcdDataWrite n LcdDataWrite g LcdDataWrite y LcdDataWrite i delay 3000 LcdCommandWrite 0...

Page 99: ...t LcdDataWrite h LcdDataWrite e LcdDataWrite LcdDataWrite a LcdDataWrite d LcdDataWrite m LcdDataWrite i LcdDataWrite n delay 5000 4 bit connection method When using this module 8 bit connection uses all the digital pins of the Arduino leaving no pin for sensors What then We can use 4 bit connection Connection circuit Connection for R3 ...

Page 100: ...t LCD1602_RS 12 int LCD1602_RW 11 int LCD1602_EN 10 int DB 6 7 8 9 char str1 Welcome to char str2 geek workshop char str3 this is the char str4 4 bit interface void LCD_Command_Write int command int i temp digitalWrite LCD1602_RS LOW digitalWrite LCD1602_RW LOW digitalWrite LCD1602_EN LOW temp command 0xf0 for i DB 0 i 9 i digitalWrite i temp 0x80 temp 1 ...

Page 101: ...te LCD1602_EN HIGH delayMicroseconds 1 digitalWrite LCD1602_EN LOW void LCD_Data_Write int dat int i 0 temp digitalWrite LCD1602_RS HIGH digitalWrite LCD1602_RW LOW digitalWrite LCD1602_EN LOW temp dat 0xf0 for i DB 0 i 9 i digitalWrite i temp 0x80 temp 1 digitalWrite LCD1602_EN HIGH delayMicroseconds 1 digitalWrite LCD1602_EN LOW temp dat 0x0f 4 for i DB 0 i 10 i digitalWrite i temp 0x80 ...

Page 102: ...t y int address if y 0 address 0x80 x else address 0xC0 x LCD_Command_Write address void LCD_Write_Char int x int y int dat LCD_SET_XY x y LCD_Data_Write dat void LCD_Write_String int X int Y char s LCD_SET_XY X Y address setup while s write character string LCD_Data_Write s s void setup void int i 0 for i 6 i 12 i pinMode i OUTPUT delay 100 ...

Page 103: ..._Command_Write 0x80 delay 50 LCD_Command_Write 0x01 delay 50 void loop void LCD_Command_Write 0x01 delay 50 LCD_Write_String 3 0 str1 line 1 start at the fourth address delay 50 LCD_Write_String 1 1 str2 line 2 start at the second address delay 5000 LCD_Command_Write 0x01 delay 50 LCD_Write_String 0 0 str3 delay 50 LCD_Write_String 0 1 str4 delay 5000 ...

Page 104: ...rotate direction accordingly and drive the core less motor The gear then pass the force to the shaft The sensor will determine if it has reached the commanded position according to the feedback signal Servomotors are used in control systems that requires to have and maintain different angles When the motor speed is definite the gear will cause the potentiometer to rotate When the voltage differenc...

Page 105: ... angle After some basic knowledge let s learn how to control a servomotor For this experiment you only need a servomotor and several jumper wires Hardware required RB 412 servomotor 1 Breadboard jumper wire several Connection sample program There are two ways to control a servomotor with Arduino One is to use a common digital sensor port of Arduino to produce square wave with different duty cycle ...

Page 106: ...tact motor because for the servo function only digital pin 9 ang 10 can be used The Arduino drive capacity is limited So if you need to control more than one motor you will need external power Method 1 Connection for R3 Connection for 2560 R3 ...

Page 107: ...servomotor signal line int myangle initialize angle variable int pulsewidth initialize width variable int val void servopulse int servopin int myangle define a servo pulse function pulsewidth myangle 11 500 convert angle to 500 2480 pulse width digitalWrite servopin HIGH set the level of servo pin as high delayMicroseconds pulsewidth delay microsecond of pulse width digitalWrite servopin LOW set t...

Page 108: ...o commanded position servopulse servopin val use the pulse function Method 2 Let s first take a look at the Arduino built in servo function and some of its common statements 1 attach interface select pin for servo can only use pin 9 or 10 2 write angle used to control the rotate angle of the servo can set the angle among 0 degree to 180 degree 3 read used to read the angle of the servo consider it...

Page 109: ...rtlibrary Servo or input include Servo h Make sure there is a space between include and Servo h Otherwise it will cause compile error Servo myservo define servo variable name void setup myservo attach 9 select servo pin 9 or 10 void loop myservo write 90 set rotate angle of the motor Above are the two methods to control the servo You can choose either one according to your liking or actual need ...

Reviews: