Catalog LED module......................................................................................1 RGB module.....................................................................................5 Button module...................................................................................8 Photoresistor module.......................................................................10 Active buzzer module.......................................................................14 Passive buzzer module..
LED module (Red/Yellow/Green/Blue/White) Module description: LED is the abbreviation of light-emitting diode. It is usually made of gallium arsenide, gallium phosphide semiconductor material. LED has two electrodes, one positive and one negative. When the positive current passes through, it will light up. It can be red, blue, green or yellow light, and the color of the light depends on the material it uses. Working voltage:3.3V~5V Output type:Digital signal.
Code int LEDpin = 12; // Pin 12 of LED void setup() { pinMode(LEDpin, OUTPUT); } // Define LED pin as output pin void loop() { digitalWrite(LEDpin, HIGH); delay(1000); // Write output value is high digitalWrite(LEDpin, LOW); delay(1000); // Write output value is low } Mixly graphic programming 2
Result: after pin 12 is plugged in the L E D light, the L E D light will turn on for one second and off for one second. Pulse Width Modulation or PWM is a king of technical and digital means to obtain simulation results. Digital control is used to generate a square wave, and a signal exchange is between on and off. These switch modes simulate voltage on 5V and off 0V between voltages. By changing the time part of the signal, the duration is compared with the signal stop time.
Code int ledPin = 10; // Pin 10 ofLED void setup() { pinMode(ledPin,OUTPUT); // Define LED pin as output pin } void loop(){ fadeOn(1000,5); fadeOff(1000,5); } // Define fuction, the analog output value of LED is increased one by one according to the custom increament void fadeOn(unsigned int time,int increament){ for (byte value = 0 ; value < 255; value+=increament) { analogWrite(ledPin, value); delay(time/(255/5)); } } // Define fuction, the analog output value of LED is decreased one by one according to
RGB module Product description: RGB LED consists of 3 leds. Each led has a red light, a green light and a blue light. These three colors leds can produce any color. The RGB LED has red, green and blue light transmitters and is usually connected to a common lead (anode or carthode) using three wires. The module is a commong cathode led. Working voltage: 3V~5V Input type: PWM. The value (0~255) is input into RDDB three interfaces as digitial value. The color of RGB LED is controled by PWM.
Code int redpin = 9; // Pin 9 of RGB Red LED int greenpin = 10; // Pin 10 of RGB Green LED int bluepin = 11; // Pin 11 of RGB Blue LED void setup() { pinMode(redpin,OUTPUT); // Define three color of LED pin as output pin pinMode(greenpin,OUTPUT); pinMode(bluepin,OUTPUT); } void loop() { color(255,0,0); delay(200); color(0,255,0); delay(200); color(0,0,255); delay(200); color(255,255,255); delay(200); } // Define fuction, define write output values separately void color(int red,int green ,int blue){ analog
Mixly graphic programming Result: Pin R of module connect to Pin 9, G connect to Pin 10, B connect to Pin 11. The RGB led blinks in cycles of red, green, blue and white.
Button module Product description: Buttons are common components used to control electronic devices. They are usually used as switches to connect or disconnect circuits. Under normal circumstances, the two contacts of the button are in the open state, and they only close when the button is pressed. Working voltage:3.3V to 5V Output type:Digital signal. Press the key, high level;Release the key, low level. Interface mode:PH2.0~3P Module size:35*26.3mm Module weight:49g.
Code int buttonpin = 8; // Pin 8 button module int LEDpin = 12; // Pin 12 of LED void setup() { pinMode(LEDpin, OUTPUT); pinMode(buttonpin,INPUT); } // Define LED pin as output pin // Define button pin as input pin void loop() { int state = digitalRead(buttonpin); // Read output value if(state == HIGH ){ // Check whether the input is high. Press button is high.
Photoresistor module Module description: Photoresistor is a kind of light controlled variable resistor.Photoresistors have photoconductivity and can be used in photodetectors. Photoresistors are made of high resistance semiconductors. In the dark, the resistance of photoresist can be as high as several megaohms (m Ω), while in sufficient light, the resistance of photoresist can be as low as several hundred ohms.
Code void setup() { pinMode(8, OUTPUT); pinMode(A0,INPUT); Serial.begin(9600); } // Pin 8 of LED as output pin // Pin A0 of photoresistor as input pin // Open 9600 serial port with baud rate void loop(){ int state = analogRead(A0); // Read the analog input value of photoresistor Serial.
Example 2 Connection diagram Code void setup() { pinMode(8, OUTPUT); // Pin 8 of LED as output pin pinMode(9,INPUT); // Pin 9 of photoresistor as input pin S erial.begin(9600); Open 9/6/00 serial port with baud rate } void loop(){ int state = digitalRead(9); // Read the digital input value of photoresistor Serial.
Mixly graphic programming Result: Digital port of photoresistor connect to Pin 9, LED connect to Pin 8. When the output digital sigal of pin 9 is 0, led is on. Otherwise, led is off.
Active buzzer module Module description: Buzzer is a kind of audio signal device. As an integrated electronic buzzer, it is powered by DC voltage and widely used in computers, printers, copiers, alarms,electronic toys, automotive electronic equipment, telephones, timers and other electronic product voice equipment. According to its driving mode, buzzer can be divided into activebuzzer and passive buzzer.
Code void setup() { pinMode(8,INPUT); // Define button of Pin 8 as input pin pinMode(9,OUTPUT); // Define active buzzer of Pin 9 as output pin } void loop() { int state = digitalRead(8); // Read the button input value if(state){ // Check whether input is high, Press button is high. digitalWrite(9,HIGH); } else{ digitalWrite(9,LOW); } // Buzzer sounds // Buzzer off } Mixly graphic program Result: button connect to pin 8, buzzer connect pin 9.
Passive buzzer module Module description: Buzzer is a kind of audio signal device. As an integrated electronic buzzer, it is powered by DC voltage and widely used in computers, printers, copiers, alarms,electronic toys, automotive electronic equipment, telephones, timers and other electronic product voice equipment. According to its driving mode, buzzer can be divided into active buzzer and passive buzzer. Is the input module, digital interface.
代码 float sinVal; int toneVal; void setup() { // put your setup code here, to run once: pinMode(8,OUTPUT); pinMode(10,OUTPUT); } void loop() { // put your main code here, to run repeatedly: for(int x =0;x<180;x++){ sinVal = (sin(x*(3.1412/180))); toneVal = 2000+(int(sinVal*1000)); tone(8,toneVal); analogWrite(10,map(toneVal,2000,3000,10,255)); delay(2); } } Mixly graphic program Result: Led connect to pin 10, buzzer connect to pin 8.
Example 2 Connection diagram Code #define NOTE_D0 -1 #define NOTE_D1 262 #define NOTE_D2 294 #define NOTE_D3 330 #define NOTE_D4 350 #define NOTE_D5 393 #define NOTE_D6 441 #define NOTE_D7 495 #define NOTE_DL1 131 #define NOTE_DL2 147 #define NOTE_DL3 165 #define NOTE_DL4 175 #define NOTE_DL5 196 #define NOTE_DL6 221 #define NOTE_DL7 248 #define NOTE_DH1 525 #define NOTE_DH2 589 #define NOTE_DH3 661 #define NOTE_DH4 700 #define NOTE_DH5 786 #define NOTE_DH6 882 #define NOTE_DH7 990 //The definition above i
NOTE_D1,NOTE_D5,NOTE_D1, NOTE_D1,NOTE_D5,NOTE_D1}; //This part is the note part of the whole piece, which is defined by a sequence as tune, integer float duration[]= { 1,1,1,1, 1,1,1,1, 1,1,1+1, 1,1,1+1, 0.5+0.5,0.25+0.5,0.5+0.5,0.25+0.5,1,1, 0.5+0.5,0.25+0.5,0.5+0.5,0.25+0.
Mixly graphic programming Result: buzzer connect to pin 9, buzzer sounds "two tiger" song. Expansion: use the buzzer to play a song you like! Step 1: get a list of the corresponding sounds (note frequency table) from the song's score and the buzzer. Here are two tigers.
Tone Note 1 . 2 . 3 . 4 5 . 6 . 7 .
Step 2: Look at the music score In the notation, the blue box shows the tune in C key, so we only need to look at the C line in the note frequency table (marked in red font). Because there is no high and low tone in the notation, this piece is only used for the C-key part (marked with yellow background) ofthe mid note in the note frequency table. So we get the note sequence of two tigers. Only notes are not enough. We need to add rhythm to notes.
Touch sensor module Module description: Touch module is a capacitive touch switch module based on touch detection. Normally, the module outputs low level;When touching the corresponding position with fingers, the module will output high level.The module can be installed on the surface of non-metallic materials such as plastic and glass.In addition, a thin piece of paper (non- metallic) can be covered on the surface of the module.
Code void setup() { pinMode(8,INPUT); pinMode(9,OUTPUT); } // Pin 8 of touch sensor as input pin // Pin 9 of LED as output pin void loop() { int state = digitalRead(8); //Read module level if(state){ //Judge the level of touch module digitalWrite(9,HIGH); //LED on } else{ digitalWrite(9,LOW); //LED off } } Mixly graphic programming Result: touch module connect to pin 8, led connect to pin 9. When touch the sensor of module, led is on.
Tracking moudle Module description: The tracking module is used to transmit light to the road by the infrared transmitting tube. When the infrared light encounters black, it is absorbed. The receiving tube does not receive the reflected light and outputs high level. When the red light meets other colors, the receiving tube receives the reflected light and outputs a low level. When using analog output, the module can be used as a gray-scale sensor.
Code int data[2]; void setup() { pinMode(9,INPUT);//LD pinMode(12,INPUT);//RD pinMode(A0,INPUT);//LA pinMode(A1,INPUT);//RA Serial.begin(9600); } void loop() { distanceonD(); } void distanceonD(){ data[0] = digitalRead(9); data[1] = digitalRead(12); if(data[0] && data[1]){ Serial.println("stop"); } if(!data[0] && !data[1]){ Serial.println("go"); } if(!data[0] && data[1]){ Serial.println("right"); } if(data[0] && !data[1]){ Serial.
Example 2 Code int data[2]; void setup() { pinMode(A0,INPUT);//LA pinMode(A1,INPUT);//RA Serial.begin(9600); } void loop() { distanceonA(); } void distanceonA(){ data[0] = analogRead(9); data[1] = analogRead(12); if(data[0]>500 && data[1]>500){ Serial.println("stop"); } if(data[0]<500 && data[1]<500 ){ Serial.println("go"); } if(data[0]<500 && data[1]>500 ){ Serial.println("right"); } if(data[0]>500 && data[1]<500 ){ Serial.
Fan module Module description: DC motor is a kind of motor that converts DC electric energy into mechanical energy. The most common type depends on the force produced by the magnetic field. Almost all types of DC motors have some internal mechanism, either electromechanical or electronic, to periodically change the current flow direction of some motors. Most types produce rotational motion; linear motors produce force and linear motion directly Working voltage: 5V.
Code const int IB = 6; const int IA = 5; int buttonpin = A1; boolean state = false; void setup() { Serial.
Mixly graphic programming Result: IB interface connect to pin 6, IA interface connect to pin 5. After motor rotates for 1 second, stop rotating for 1 second as periodic cycle movement.
Infrared receiving module Module description: The external receiving tube is an electronic device that receives infrared light. For example, our TV sets, air conditioners and other household appliances need infrared receivers. We all know that the remote control emits infrared light. It is necessary for the TV to have an infrared receiver to receive the infrared signal from the remote control. Working voltage: 3.3V~5V Output type:digital signal Interface mode: pH2.0~3P Module size: 35*26.
Code Before we start programming, we need to add the library "irremote. h" for infrared reception. Click "project" - > "load library" - > "manage library" - > "search" irremote ",and install the following irremote library. After installing the library, you can program it. We found irremote under "file" - >"example" - > under "third party library example", which provides some examples of the library using infrared reception. code #include
Microphone module (Sound sensor module) Module description: Output module, digital analog interface. It acts as a microphone. It is used to receive sound waves and display vibration images, but it can not measure the intensity of noise.
Code void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(8,INPUT); pinMode(A0,INPUT); pinMode(11, OUTPUT); } void loop() { int astate = analogRead(A0); int dstate = digitalRead(8); if(dstate==0){ Serial.print("Digital interface:"); Serial.println(dstate); Serial.print("Analog interface: "); Serial.
Potentiometer module Module description: Potentiometer is a kind of three terminal resistance element whose resistance can be changed according to certain rules. It usually consists of a resistance element and a movable brush. When the brush moves along the element, a resistance or voltage is generated at the terminal relative to its moving distance. Working voltage: 3.3V~5V Output type: Obtain the digital output of the potentiometer switch and the analog output of the potentiometer value (0-1023).
Code void setup() { pinMode(10,INPUT); pinMode(A0,INPUT); pinMode(11,OUTPUT); Serial.
Ultrasonic Module Module description: This module is used to measure the distance. By sending and receiving ultrasonic waves, it measures the time required for the sound to rebound from the object and return to the sensor. Using the time difference and sound propagation speed, it calculates the distance between the module and the obstacles in front. Working voltage: 3.
Arduino uno Example 1 Connection diagram Code void setup() { pinMode(13,OUTPUT); pinMode(12,INPUT); Serial.begin(9600); } // Pin 13 of send as output pin // Pin 12 of receiver as input pin // Open 9600 serial port with baud rate void loop() { digitalWrite(13,LOW); // Trigger ultrasonic ranging delayMicroseconds(2); digitalWrite(13,HIGH); delayMicroseconds(10); digitalWrite(13,LOW); int distance = pulseIn(12,HIGH)/58; // Calculate distance Serial.
Mixly graphic programming Result: Trig connect to pin 13, Echo connect to pin 12. Open serial port, the obstacles in front of the mobile ultrasonic ranging module and the data output to the serial port change. Explanation: the time returned by pulsein() is the time when the ultrasound is sent to the receiver, the unit is subtle, and the sound speed is 340m / s. because distance = speed *time, the distance (CM) = 340 * 100 / 1000000 * pulsein() / 2, that is, distance (CM) =pulsein() / 58.