background image

keyestudio

www.keyestudio.com

1

Super Learning Kit for Arduino

Summary of Contents for KS0077

Page 1: ...keyestudio www keyestudio com 1 Super Learning Kit for Arduino...

Page 2: ...ilt Switch 47 Project 14 IR Remote Control 49 Project 15 Analog Value Reading 58 Project 17 1 digit LED Segment Display 64 Project 18 4 digit LED Segment Display 71 Project 19 8 8 LED Matrix 79 Projec...

Page 3: ...ed tutorials starting from the basics to more complex projects Different from other kits it adds some functional modules such as RFID temperature and humidity module There is connection diagram and co...

Page 4: ...keyestudio www keyestudio com 4 5 220 Resistor 8 6 10K Resistor 5 7 1K resistor 5 8 10K Potentiometer 1 9 Buzzer Active 1 10 Buzzer Passive 1 11 Large Button Switch 4...

Page 5: ...ww keyestudio com 5 12 Ball Tilt Sensor 2 13 Photo Resistor 3 14 Flame Sensor 1 15 LM35 Temp Sensor 1 16 IC 74HC595N 16 pin DIP 1 17 7 seg LED Segment Display 1 18 7 seg LED Segment Display 1 19 8 8 L...

Page 6: ...keyestudio www keyestudio com 6 20 2x16 LCD display 1 21 IR Receiver 1 22 IR Remote Control 1 23 Servo Motor 1 24 Stepper Driver 1 25 Stepper Motor 1 26 Joystick Module 1...

Page 7: ...keyestudio www keyestudio com 7 27 Relay Module 1 28 PIR Motion Sensor 1 29 Analog Gas Sensor 1 30 ADXL345 Three Axis Acceleration Module 1 31 HC SR04 Ultrasonic Sensor 1 32 DS3231 Clock Module 1...

Page 8: ...keyestudio www keyestudio com 8 33 DHT11 Temperature and Humidity Sensor 1 34 Soil Humidity Sensor 1 35 RC522 RFID Module 1 36 RFID Card 1 37 Access Key 1 38 Pin Headers 40...

Page 9: ...Dupont Wire 10 41 Jumper Wire 30 42 6 cell AA Battery Case 1 43 USB Cable 1 3 Project List Project 1 Hello World Project 2 LED Blinking Project 3 PWM Project 4 Traffic Light Project 5 LED Chasing Eff...

Page 10: ...Analog Gas Sensor Project 25 ADXL345 Three Axis Acceleration Module Project 26 HC SR04 Ultrasonic Sensor Project 27 Joystick Module Project 28 5V Relay Module Project 29 DS3231 Clock Module Project 30...

Page 11: ...t 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 device e g bluetooth the baud rate needs to be...

Page 12: ...keyestudio com 12 Test Result Click to open the serial monitor input an R LED 13 will blink once PC will receive the information from Arduino Hello World After choosing the proper port the experiment...

Page 13: ...e of the digital pins rather than using LED13 soldered to the board Apart from an Arduino and a USB cable you will need extra parts as below Hardware Required Red M5 LED 1 220 Resistor 1 Breadboard 1...

Page 14: ...keyestudio www keyestudio com 14 Connection for UNO R3 Connection for 2560 R3...

Page 15: ...talWrite 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 uploading this program in the experiment you will see...

Page 16: ...y given moment fully on DC power supply is either 5V ON 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 th...

Page 17: ...ents we have done button controlled LED using digital signal to control digital pin also one about potentiometer This time we will use a potentiometer to control the brightness of the LED Hardware Req...

Page 18: ...he LED One final part will display 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 Code for your r...

Page 19: ...rial println 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 Test Result After uploading the program when...

Page 20: ...ime to up the stakes to do a bit more complicated experiment traffic light Actually these two experiments are similar While in this traffic light experiment we use three LEDs with different colors rat...

Page 21: ...keyestudio www keyestudio com 21 Circuit Connection Connection for UNO R3 Connection for 2560 R3...

Page 22: ...lWrite greenled HIGH turn on green LED delay 5000 wait 5 seconds digitalWrite greenled LOW turn off green LED for int i 0 i 3 i blinks for 3 times delay 500 wait 0 5 second digitalWrite yellowled HIGH...

Page 23: ...can see many 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 Red LED 6 220...

Page 24: ...de 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 void loop for int i BASE i BASE NUM i digitalWrite i...

Page 25: ...s interface for INPUT and OUTPUT Up to now we have only used the OUTPUT function In this experiment we will try to use the INPUT function which is to read the output value of device connecting to it W...

Page 26: ...tudio www keyestudio com 26 Hardware Required Button switch 1 Red M5 LED 1 220 Resistor 1 10K Resistor 1 Breadboard 1 Breadboard Jumper Wires Circuit Connection Connection for UNO R3 Connection for 25...

Page 27: ...uage 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...

Page 28: ...led 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 daily life One typical exam...

Page 29: ...keyestudio www keyestudio com 29 Hardware Required Buzzer 1 Key 1 Breadboard 1 Breadboard Jumper Wires Circuit Connection Connection for UNO R3 Connection for 2560 R3...

Page 30: ...is finished you can begin the programming Sample Code 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 p...

Page 31: ...uce sound Normally the experiment is done with a buzzer but not a speaker while buzzer is more simpler and easier to use The buzzer we introduced here is a passive buzzer It cannot be actuated by itse...

Page 32: ...keyestudio www keyestudio com 32 Connection for 2560 R3...

Page 33: ...j define variable while 1 for i 0 i 80 i output a frequency sound digitalWrite buzzer HIGH sound delay 1 delay1ms digitalWrite buzzer LOW not sound delay 1 ms delay for i 0 i 100 i output a frequency...

Page 34: ...m 34 Project 9 RGB LED Introduction Tricolor principle to display various colors PWM controlling ports to display full color Can be driven directly by Arduino PWM interface Hardware Required Arduino B...

Page 35: ...keyestudio www keyestudio com 35 Circuit Connection Connection for UNO R3 Connection for 2560 R3...

Page 36: ...OUTPUT pinMode bluepin OUTPUT pinMode greenpin OUTPUT Serial begin 9600 void loop for val 255 val 0 val analogWrite 11 val analogWrite 10 255 val analogWrite 9 128 val delay 1 for val 0 val 255 val an...

Page 37: ...ces if the incident light is weak the resistance increases Photovaristor is commonly applied in the measurement of light light control and photovoltaic conversion convert the change of light into the...

Page 38: ...keyestudio www keyestudio com 38 Hardware Required Photo Resistor 1 Red M5 LED 1 10K Resistor 1 220 Resistor 1 Breadboard 1 Breadboard Jumper Wires Circuit Connection Connection for UNO R3...

Page 39: ...ith photovaristor 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...

Page 40: ...high sensitivity to flame Working Principle Flame sensor is based on the principle that infrared ray is highly sensitive to flame It has an infrared receiving tube specially designed to detect fire an...

Page 41: ...1 Breadboard Jumper Wires Circuit Connection 1 Connecting buzzer Connect the controller board prototype board breadboard and USB Cable according to the Arduino tutorial Connect the buzzer to digital p...

Page 42: ...keyestudio www keyestudio com 42 Connection for MEGA 2560...

Page 43: ...determine whether there is a fire approaching or not if yes the buzzer will buzz Sample Code int flame 0 select analog pin 0 for the sensor int Beep 9 select digital pin 9 for the buzzer int val 0 ini...

Page 44: ...nd easy to use temperature 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 into Ce...

Page 45: ...keyestudio www keyestudio com 45 Connection for UNO R3 Connection for 2560 R3...

Page 46: ...al 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 da...

Page 47: ...tudio com 47 Project 13 Tilt Switch Introduction Tilt switch controlling the LED on and off Hardware Required Ball switch 1 Led 1 220 Resistor 1 10K resistor 1 Breadboard Jumper Wires Circuit Connecti...

Page 48: ...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 ab...

Page 49: ...e 8 LOW turn on LED else otherwise digitalWrite 8 HIGH turn off LED Test 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 of...

Page 50: ...ceive signals at that specific frequency and to modulate it back to binary pulse code known as demodulation Working Principle The built in receiver converts the light signal it received from the sende...

Page 51: ...r 1 LED 6 220 Resistor 6 Multi color Breadboard Wires Circuit Connection First connect the controller board then connect the infrared receiver as the above mentioned connect VOUT to digital pin 11 con...

Page 52: ...t s coded The coding 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 rel...

Page 53: ...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 after a period of time A command is tran...

Page 54: ...long on5 0x00FF5AA5 long off5 0x00FF42BD long on6 0x00FF4AB5 long off6 0x00FF52AD IRrecv irrecv RECV_PIN decode_results results Dumps out the decode_results structure Call this after IRrecv decode vo...

Page 55: ...int 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...

Page 56: ...mp results if results value on1 digitalWrite LED1 HIGH if results value off1 digitalWrite LED1 LOW if results value on2 digitalWrite LED2 HIGH if results value off2 digitalWrite LED2 LOW if results va...

Page 57: ...ail to compile it Infrared remote library https github com shirriff Arduino IRremote Program Function Decode the coded pulse signal emitted by the remote controller then execute corresponding action a...

Page 58: ...al ones numbered as 14 19 Next 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 Bread...

Page 59: ...keyestudio www keyestudio com 59 Connection for 2560 R3...

Page 60: ...e value followed by statement for displaying You can either use Serial print or Serial println statement int potpin 0 initialize analog pin 0 int ledpin 13 initialize digital pin 13 int val 0 define v...

Page 61: ...register memorizer and equipped with tri state output Here we use it to control 8 LEDs You may wonder why use a 74HC595 to control LED Well think about how many I O it takes for an Arduino to control...

Page 62: ...com 62 Hardware Required 74HC595 chip 1 Red M5 LED 4 Green M5 LED 4 220 Resistor 8 Breadboard 1 Breadboard Jumper Wires Circuit Connection Connection for UNO R3 Note for pin 13 OE port of 74HC595 it s...

Page 63: ...l find it more easier Sample Code 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 ledS...

Page 64: ...bit binary number Project 17 1 digit LED Segment Display Introduction LED segment displays are common for displaying numerical information It s widely applied on displays of electromagnetic oven full...

Page 65: ...segment is off For the common cathode display connect the common cathode COM to GND When the anode level of a certain segment is high the segment is on when the anode level of a certain segment is low...

Page 66: ...keyestudio www keyestudio com 66 Connection for 2560 R3...

Page 67: ...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 pin 11 for segment e int f 8 set digital pin 8 for segment f i...

Page 68: ...H digitalWrite dp LOW digitalWrite f LOW digitalWrite e LOW void digital_4 void display number 4 digitalWrite c HIGH digitalWrite b HIGH digitalWrite f HIGH digitalWrite g HIGH digitalWrite dp LOW dig...

Page 69: ...for j 8 j 11 j digitalWrite j LOW void digital_8 void display number 8 unsigned char j for j 5 j 11 j digitalWrite j HIGH digitalWrite dp LOW void digital_9 void display number 5 unsigned char j digi...

Page 70: ...splay number 3 delay 1000 wait for 1s digital_4 display number 4 delay 1000 wait for 1s digital_5 display number 5 delay 1000 wait for 1s digital_6 display number 6 delay 1000 wait for 1s digital_7 di...

Page 71: ...or this 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 guara...

Page 72: ...keyestudio www keyestudio com 72 Manual for LED Segment Display Connection for UNO R3...

Page 73: ...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 set...

Page 74: ...splay 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 digitalW...

Page 75: ...gitalWrite 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...

Page 76: ...igitalWrite 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...

Page 77: ...italWrite 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 digitalWrite dp LOW void Num_9 d...

Page 78: ...ber 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 break case 8 Num_8 break case 9 Num_9 bre...

Page 79: ...dot matrix has some advantages such as power saving long service life low cost high brightness wide angle of view long visual range waterproof and numerous specifications LED dot matrix display can m...

Page 80: ...hten If you want to light the LED on the first dot you should set pin 9 to high level and pin 13 to low level If you want to light LEDs on the first row you should set pin 9 to high level and pins 13...

Page 81: ...for 2560 R3 Sample Code 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 f...

Page 82: ...i 8 i data Text i for j 0 j 8 j if data 0x01 Draw_point j i data 1 void setup int i 0 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 digita...

Page 83: ...characters Chip operating voltage 4 5 5 5V Working current 2 0mA 5 0V Optimum working voltage of the module is 5 0V Character size 2 95 4 35 W H mm Pin description of 1602 LCD No Mark Pin description...

Page 84: ...ad operation when it s in low level it s in write operation 5 E pin is also very common in LCD Usually when the signal in the bus is stabilized it sends out a positive pulse requiring read operation W...

Page 85: ...keyestudio www keyestudio com 85 8 bit Connection Method Connection for UNO R3...

Page 86: ...l pins int i 0 for i DB 0 i DI i assign value for bus digitalWrite i value 01 for 1602 LCD it uses D7 D0 not D0 D7 for signal identification here it s used for signal inversion value 1 digitalWrite En...

Page 87: ...mmandWrite 0x38 select as 8 bit interface 2 line display 5x7 character size delay 64 LcdCommandWrite 0x38 select as 8 bit interface 2 line display 5x7 character size delay 50 LcdCommandWrite 0x38 sele...

Page 88: ...e LcdDataWrite t LcdDataWrite o delay 10 LcdCommandWrite 0xc0 1 set cursor position at second line second position delay 10 LcdDataWrite g LcdDataWrite e LcdDataWrite e LcdDataWrite k LcdDataWrite Lcd...

Page 89: ...LcdCommandWrite 0x80 5 set cursor position at first line sixth position delay 10 LcdDataWrite t LcdDataWrite h LcdDataWrite e LcdDataWrite LcdDataWrite a LcdDataWrite d LcdDataWrite m LcdDataWrite i...

Page 90: ...all LCD displays that are compatible with the Hitachi HD44780 driver There are many of them out there and you can usually tell them by the 16 pin interface This sketch prints Hello World to the LCD an...

Page 91: ...he public domain http www arduino cc en Tutorial LiquidCrystal include the library code include LiquidCrystal h initialize the library with the numbers of the interface pins LiquidCrystal lcd 12 11 9...

Page 92: ...rotate direction accordingly and drive the core less motor The gear then pass the force to the shaft The sensor will determine whether it has reached the commanded position according to the feedback...

Page 93: ...otor and several jumper wires Hardware Required 9G Servo Motor 1 Breadboard Jumper Wire several Connection Sample Code There are two ways to control a servomotor with Arduino One is to use a common di...

Page 94: ...keyestudio www keyestudio com 94 Connection for 2560 R3 Connect the motor to digital pin 9...

Page 95: ...delay microsecond of pulse width digitalWrite servopin LOW set the level of servo pin as low delay 20 pulsewidth 1000 void setup pinMode servopin OUTPUT set servo pin as output Serial begin 9600 conne...

Page 96: ...digital pin 9 or 10 can be used for PWM port Note the written form of the above statements are servo variable name specific statement e g myservo Attach 9 Still connect the servo to pin 9 Sample Code...

Page 97: ...pen loop system Open loop control means no feedback information about position is needed This type of control eliminates the need for expensive sensing and feedback devices such as optical encoders Yo...

Page 98: ...Ratio 1 64 Stride Angle 5 625 64 Frequency 100Hz DC Resistance 50 7 25 Idle In traction Frequency 600Hz Idle Out traction Frequency 1000Hz In traction Torque 34 3mN m 120Hz Self positioning Torque 34...

Page 99: ...com 99 Connection for 2560 R3 Sample Code include Stepper h define STEPS 100 Stepper stepper STEPS 8 9 10 11 int previous 0 void setup stepper setSpeed 90 void loop int val analogRead 0 stepper step...

Page 100: ...complex circuit and lower reliability Now we launch this new pyroelectric infrared motion sensor which is specially designed for Arduino It uses an integrated digital body pyroelectric infrared senso...

Page 101: ...studio www keyestudio com 101 Connection for UNO R3 Connection for MEGA 2560 R3 Sample Code byte sensorPin 3 byte indicator 13 void setup pinMode sensorPin INPUT pinMode indicator OUTPUT Serial begin...

Page 102: ...his analog gas sensor MQ2 is used in gas leakage detecting equipment in consumer electronics and industrial markets This sensor is suitable for LPG I butane propane methane alcohol Hydrogen and smoke...

Page 103: ...w keyestudio com 103 Stable and long lifespan Size 49 7 20mm Weight 8g Circuit Connection Connection for UNO R3 Connection for MEGA 2560 R3 Sample Code void setup Serial begin 9600 Set serial baud rat...

Page 104: ...formatted as 16 bit twos complement and is accessible through either a SPI 3 or 4 wire or I2C digital interface The ADXL345 is well suited to measure the static acceleration of gravity in tilt sensin...

Page 105: ...keyestudio www keyestudio com 105 Circuit Connection Connection for UNO R3 Connection for MEGA 2560 R3...

Page 106: ...d because this only tells the cip to send data to its output register writes data to the slave s buffer void i2c_write int address byte reg byte data Send output register address Wire beginTransmissio...

Page 107: ...45_ADDRESS 0x31 0x0B 13 bit mode _ 16g i2c_write ADXL345_ADDRESS 0x2D 0x08 Power register i2c_write ADXL345_ADDRESS 0x1E 0x00 x i2c_write ADXL345_ADDRESS 0x1F 0x00 Y i2c_write ADXL345_ADDRESS 0x20 0x0...

Page 108: ...i accelerometer_data i 0 init_adxl345 void loop read_adxl345 Serial print ACCEL Serial print float accelerometer_data 0 3 9 1000 3 9mg LSB scale factor in 13 bit mode Serial print t Serial print floa...

Page 109: ...It has also been used in turret applications water level sensing and even as a parking sensor This simple project will use the HC SR04 sensor with an Arduino and a Processing sketch to provide a more...

Page 110: ...3 Sample Code VCC to arduino 5v GND to arduino GND Echo to Arduino pin 7 Trig to Arduino pin 8 define echoPin 7 Echo Pin define trigPin 8 Trigger Pin define LEDPin 13 Onboard LED int maximumRange 200...

Page 111: ...Pin LOW delayMicroseconds 2 digitalWrite trigPin HIGH delayMicroseconds 10 digitalWrite trigPin LOW duration pulseIn echoPin HIGH Calculate the distance in cm based on the speed of sound distance dura...

Page 112: ...o two analog inputs the robot is at your commands with X Y control It also has a switch that is connected to a digital pin This joystick module can be easily connected to Arduino by IO Shield This mod...

Page 113: ...int JoyStick_Y 1 y int JoyStick_Z 3 key void setup pinMode JoyStick_Z INPUT Serial begin 9600 9600 bps void loop int x y z x analogRead JoyStick_X y analogRead JoyStick_Y z digitalRead JoyStick_Z Ser...

Page 114: ...not included The Relay output is by a light emitting diode It can be controlled through digital IO port such as solenoid valves lamps motors and other high current or high voltage devices Specificati...

Page 115: ...keyestudio www keyestudio com 115 Connection for UNO R3 Connection for MEGA 2560 R3 Sample Code int Relay 8 void setup pinMode 13 OUTPUT Set Pin13 as output digitalWrite 13 HIGH Set Pin13 High...

Page 116: ...effective I2C real time clock with high precision The device carries a battery input so even if you disconnect the main power supply it can still maintain accurate timing The integrated oscillator en...

Page 117: ...nd year timing and provides leap year compensation until 2100 Two calendar clock Output 1Hz and 32 768kHz Reset output and Input Debounce of Pushbutton High speed 400kHz I2C serial bus Supply voltage...

Page 118: ...mal operation of the RTC Take care of week day also DateTime dt 2011 11 10 15 18 0 5 open the series port and you can check time here or make a change to the time as needed void setup Serial begin 576...

Page 119: ...t now second DEC Serial println Serial print weekDay now dayOfWeek Serial println delay 1000 Before compiling the code you d better put DS3231 library under file into Arduino catalogue Test Result Don...

Page 120: ...ity and high cost performance Each DHT11 sensor features extremely accurate calibration data of humidity calibration chamber The calibration coefficients stored in the OTP program memory internal sens...

Page 121: ...onnection for MEGA 2560 R3 Sample Code Please download the DHT11Lib firstly Or see the website include dht11 h dht11 DHT define DHT11_PIN 4 void setup Serial begin 9600 Serial println DHT TEST PROGRAM...

Page 122: ...DHT11_PIN READ DATA switch chk case DHTLIB_OK Serial print OK t break case DHTLIB_ERROR_CHECKSUM Serial print Checksum error t break case DHTLIB_ERROR_TIMEOUT Serial print Time out error t break defa...

Page 123: ...through the soil the sensor will get resistance value by reading the current changes between the two probes and convert such resistance value into moisture content The higher the moisture less resist...

Page 124: ...keyestudio www keyestudio com 124 Circuit Connection Connection for UNO R3 Connection for MEGA 2560 R3 Sample Code 0 300 dry soil 300 700 humid soil 700 950 in water void setup...

Page 125: ...development of advanced applications the need for the user of RF card terminal design production It can be loaded directly into a variety of readers molds Module uses voltage of 3 3V through the SPI i...

Page 126: ...S50 mifare1 S70 mifare UltraLight mifare Pro mifare Desfire 7 Dimension 40mm 60mm 8 Environmental Operating Temperature 20 80 degrees Celsius 9 Environment Storage Temperature 40 85 degrees Celsius 10...

Page 127: ...THENT 0x0E verify key define PCD_RECEIVE 0x08 receive data define PCD_TRANSMIT 0x04 send data define PCD_TRANSCEIVE 0x0C receive and send data define PCD_RESETPHASE 0x0F reset define PCD_CALCCRC 0x03...

Page 128: ...ster Page 0 Command and Status define Reserved00 0x00 define CommandReg 0x01 define CommIEnReg 0x02 define DivlEnReg 0x03 define CommIrqReg 0x04 define DivIrqReg 0x05 define ErrorReg 0x06 define Statu...

Page 129: ...Reg 0x27 define CWGsPReg 0x28 define ModGsPReg 0x29 define TModeReg 0x2A define TPrescalerReg 0x2B define TReloadRegH 0x2C define TReloadRegL 0x2D define TCounterValueRegH 0x2E define TCounterValueReg...

Page 130: ...0xFF 0xFF 0xFF 0xFF void setup Serial begin 9600 RFID reader SOUT pin connected to Serial RX pin at 2400bps start the SPI library SPI begin pinMode chipSelectPin OUTPUT Set digital pin 10 as OUTPUT t...

Page 131: ...turn card capacity RC_size MFRC522_SelectTag serNum if RC_size 0 write data card blockAddr 7 data block 7 status MFRC522_Auth PICC_AUTHENT1A blockAddr sectorKeyA blockAddr 4 serNum authentication if s...

Page 132: ...blockAddr str if status MI_OK Serial println Read from the card the data is for i 0 i 16 i Serial print str i Serial println Serial println MFRC522_Halt command card to enter standby mode void Write_...

Page 133: ...eg uchar mask uchar tmp tmp Read_MFRC522 reg Write_MFRC522 reg tmp mask set bit mask void ClearBitMask uchar reg uchar mask uchar tmp tmp Read_MFRC522 reg Write_MFRC522 reg tmp mask clear bit mask voi...

Page 134: ...0x3E TModeReg 3 0 TPrescalerReg Write_MFRC522 TReloadRegL 30 Write_MFRC522 TReloadRegH 0 Write_MFRC522 TxAutoReg 0x40 100 ASK Write_MFRC522 ModeReg 0x3D CRC initial value AntennaOn open antenna uchar...

Page 135: ...ion irqEn 0x12 waitIRq 0x10 break case PCD_TRANSCEIVE send data in FIFO irqEn 0x77 waitIRq 0x30 break default break Write_MFRC522 CommIEnReg irqEn 0x80 Allow interrupt request ClearBitMask CommIrqReg...

Page 136: ...of operating M1 is 25ms do CommIrqReg 7 0 Set1 TxIRq RxIRq IdleIRq HiAlerIRq LoAlertIRq ErrIRq TimerIRq n Read_MFRC522 CommIrqReg i while i 0 n 0x01 n waitIRq ClearBitMask BitFramingReg 0x80 StartSen...

Page 137: ...se status MI_ERR SetBitMask ControlReg 0x80 timer stops Write_MFRC522 CommandReg PCD_IDLE return status uchar MFRC522_Anticoll uchar serNum uchar status uchar i uchar serNumCheck 0 uint unLen Write_MF...

Page 138: ...us void CalulateCRC uchar pIndata uchar len uchar pOutData uchar i n ClearBitMask DivIrqReg 0x04 CRCIrq 0 SetBitMask FIFOLevelReg 0x80 clear FIFO pointer Write_MFRC522 CommandReg PCD_IDLE write data i...

Page 139: ...recvBits uchar buffer 9 ClearBitMask Status2Reg 0x08 MFCrypto1On 0 buffer 0 PICC_SElECTTAG buffer 1 0x70 for i 0 i 5 i buffer i 2 serNum i CalulateCRC buffer 7 buffer 7 status MFRC522_ToCard PCD_TRANS...

Page 140: ..._ToCard PCD_AUTHENT buff 12 buff recvBits if status MI_OK Read_MFRC522 Status2Reg 0x08 status MI_ERR return status uchar MFRC522_Read uchar blockAddr uchar recvData uchar status uint unLen recvData 0...

Page 141: ...f recvBits if status MI_OK recvBits 4 buff 0 0x0F 0x0A status MI_ERR if status MI_OK for i 0 i 16 i write 16Byte data into FIFO buff i writeData i CalulateCRC buff 16 buff 16 status MFRC522_ToCard PCD...

Page 142: ...A 2560 R3 please in the code change const int chipSelectPin 10 if the controller is UNO 328 168 into const int chipSelectPin 53 if the controller is UNO 328 168 Test Result In this experiment when the...

Reviews: