[Diao Ye learns programming] Arduino hands-on (212) --- 9-in-1 expansion board to complete Arduino's 10 types of experiments, infrared sensor D6 experiment

insert image description here

The reference to 37 sensors and modules has been widely circulated on the Internet. In fact, there must be more than 37 sensor modules compatible with Arduino. In view of the fact that I have accumulated some sensors and modules on hand, according to the concept of practice (hands-on try), for the purpose of learning and communication, I am going to do experiments one by one here, and will record them regardless of whether they are successful or not. It is a difficult problem, and I hope to be able to throw bricks and spark jade.

[Arduino] 168 kinds of sensor module series experiment (data code + simulation programming + graphics programming)
experiment 212: 9 in 1 multi-function expansion board DHT1 device temperature and humidity LM3 temperature 5 buzzer 1 compatible with UNO

insert image description here

Take the combination of "Arduino program code" + "Mind + graphics programming" + "Linkboy simulation programming"

Complement each other, lay a solid foundation, and promote understanding

insert image description here

Experiment catalog (Arduino hands-on)
1. LED experiment
01 Blink: D13 blue LED blinks
02 Blink2: D12, D13 red and blue LEDs blink alternately
03 Blink3: Simulate flashing alarm light
04 Breath_LED: D9 full-color LED simulates red breathing light
2. Button experiment
05 Button: D2 button controls D13 blue LED
06 Button_Lock: D3 button controls D13 blue LED self-locking experiment
3. Potentiometer experiment
07 RS232_AD: serial port reads A0 potentiometer to collect value (rotation angle 270° output 0 -3.3V/5V voltage signal potentiometer resistance value 10K)
08 Rotation_LED: A0 potentiometer controls D11 full-color LED blue terminal brightness
09 RC_Motor: A0 potentiometer controls the steering gear at the output port of D7 to control its rotation angle (the steering gear needs to be automatically Arduino needs external power supply)
4. RGB full-color LED experiment
10 LED_RGB_Text: full-color LED basic color change
11 LED_RGB: full-color LED rainbow change
5. Infrared sensor D6 experiment (infrared remote control needs to be prepared by yourself)
12 IRrelay: press infrared remote control Any key of the device can control the D13 LED switch (control distance 1-8 meters, frequency 38KHz, compatible with most infrared remote controls on the market)
13 IRrecord: The serial port displays the read infrared remote control code
6. Temperature sensor experiment
14 LM35_RS232AD: The serial port
displays the temperature read by the LM35 temperature sensor on the A2 port (it can test the indoor and outdoor temperature, the range is -50-150°C, and the sensitivity is good).
Taken temperature and humidity data (temperature measurement range 0-50°C, humidity range 20%-90%PH)
8. Brightness sensor experiment
16 Light Sensor: serial port displays the value collected by the photoresistor of port A1
17 Light_LED: control of the photoresistor of port A1 D13 LED switch (sensitive to light, suitable for teaching experiments and civilian equipment)
9. Buzzer experiment
18 Buzzer: D5 port passive buzzer to simulate an ambulance siren (can make simple music sounds, music needs to be programmed)
10 , Extended experiment
19 Analog ultrasonic ranging sensor (detection type I, IIC/I2C interface)
20 Bus DS18B20 temperature sensor (numeric type, connected to the digital D7 interface of the expansion board)
21 TM1637 four-digit digital tube (digital tube and dot matrix type, connected to Expansion board digital D7/D8 interface)
22 GY-BMP280-3.3 Atmospheric pressure altimeter sensor module (numeric type, IIC/I2C interface)
23 GY-NEO-6MV2 new flight control GPS satellite signal receiving module (numeric type, TTL interface)
24 5V low-level trigger single-channel relay module (executive type, digital D7 interface)
25 4-wire sound sensor module with electret microphone (trigger type, digital D7 interface)
26 BH1750FVI digital light intensity module light sensor (numeric type, IIC/ I2C interface)
27 Open source DFPlayer Mini TF card MP3 player module (output actuator type D7/D8 digital interface)
28 LCD1602 LCD screen module (output display type, IIC/I2C interface)
29 Human body infrared pyroelectric motion sensor module (trigger type, digital D7 interface)
30 DS1307 clock module Tiny RTC I2C module (detection sensor type, IIC/I2C interface)
31 compatible HC-06 slave Bluetooth module (communication and storage type, TTL interface)

insert image description here

5. Infrared sensor D6 experiment (infrared remote control needs to be prepared by yourself)
12 IRrelay: Press any key on the infrared remote control to control the D13 LED switch (control distance 1-8 meters, frequency 38KHz, compatible with most infrared remote controls on the market)
13 IRrecord: The serial port displays the read infrared remote control code

12 Infrared control, receiving infrared commands to control the onboard LED light on and off
Arduino experiment open source code

/*
Eagler8实验程序列表
12 红外控制,接收红外命令控制板载LED灯亮灭(1号键灭,2号键亮,控制距离1-8米,兼容市面上大部分红外遥控器)
说明:开关按键可以自己定义
*/

#include <IRremote.h>

int RECV_PIN = 8;
int LED_PIN = 13;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
    
    
  Serial.begin(9600);
  irrecv.enableIRIn();
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, HIGH);
}

void loop() {
    
    
  if (irrecv.decode(&results)) {
    
    
    Serial.println(results.value, HEX);
    if (results.value == 0xFFA25D)
    {
    
    
      digitalWrite(LED_PIN, LOW);
    } else if (results.value == 0xFF629D)
    {
    
    
      digitalWrite(LED_PIN, HIGH);
    }
    irrecv.resume();
  }
  delay(100);
}

insert image description here

Any key can control

insert image description here

Experimental open source simulation programming (Linkboy V5.33)

insert image description here

13 IRrecord:
Arduino experimental open source code for infrared remote control code read by serial port display

/*
Eagler8实验程序列表
13 IRrecord:串口显示读取的红外遥控代码
*/

#include <IRremote.h>

int RECV_PIN = 8;
int BUTTON_PIN = 12;
int STATUS_PIN = 13;

IRrecv irrecv(RECV_PIN);
IRsend irsend;

decode_results results;

void setup()
{
    
    
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  pinMode(BUTTON_PIN, INPUT);
  pinMode(STATUS_PIN, OUTPUT);
}

// Storage for the recorded code
int codeType = -1; // The type of code
unsigned long codeValue; // The code value if not raw
unsigned int rawCodes[RAWBUF]; // The durations if raw
int codeLen; // The length of the code
int toggle = 0; // The RC5/6 toggle state

// Stores the code for later playback
// Most of this code is just logging
void storeCode(decode_results *results) {
    
    
  codeType = results->decode_type;
  int count = results->rawlen;
  if (codeType == UNKNOWN) {
    
    
    Serial.println("Received unknown code, saving as raw");
    codeLen = results->rawlen - 1;
    // To store raw codes:
    // Drop first value (gap)
    // Convert from ticks to microseconds
    // Tweak marks shorter, and spaces longer to cancel out IR receiver distortion
    for (int i = 1; i <= codeLen; i++) {
    
    
      if (i % 2) {
    
    
        // Mark
        rawCodes[i - 1] = results->rawbuf[i]*USECPERTICK - MARK_EXCESS;
        Serial.print(" m");
      }
      else {
    
    
        // Space
        rawCodes[i - 1] = results->rawbuf[i]*USECPERTICK + MARK_EXCESS;
        Serial.print(" s");
      }
      Serial.print(rawCodes[i - 1], DEC);
    }
    Serial.println("");
  }
  else {
    
    
    if (codeType == NEC) {
    
    
      Serial.print("Received NEC: ");
      if (results->value == REPEAT) {
    
    
        // Don't record a NEC repeat value as that's useless.
        Serial.println("repeat; ignoring.");
        return;
      }
    }
    else if (codeType == SONY) {
    
    
      Serial.print("Received SONY: ");
    }
    else if (codeType == RC5) {
    
    
      Serial.print("Received RC5: ");
    }
    else if (codeType == RC6) {
    
    
      Serial.print("Received RC6: ");
    }
    else {
    
    
      Serial.print("Unexpected codeType ");
      Serial.print(codeType, DEC);
      Serial.println("");
    }
    Serial.println(results->value, HEX);
    codeValue = results->value;
    codeLen = results->bits;
  }
}

void sendCode(int repeat) {
    
    
  if (codeType == NEC) {
    
    
    if (repeat) {
    
    
      irsend.sendNEC(REPEAT, codeLen);
      Serial.println("Sent NEC repeat");
    }
    else {
    
    
      irsend.sendNEC(codeValue, codeLen);
      Serial.print("Sent NEC ");
      Serial.println(codeValue, HEX);
    }
  }
  else if (codeType == SONY) {
    
    
    irsend.sendSony(codeValue, codeLen);
    Serial.print("Sent Sony ");
    Serial.println(codeValue, HEX);
  }
  else if (codeType == RC5 || codeType == RC6) {
    
    
    if (!repeat) {
    
    
      // Flip the toggle bit for a new button press
      toggle = 1 - toggle;
    }
    // Put the toggle bit into the code to send
    codeValue = codeValue & ~(1 << (codeLen - 1));
    codeValue = codeValue | (toggle << (codeLen - 1));
    if (codeType == RC5) {
    
    
      Serial.print("Sent RC5 ");
      Serial.println(codeValue, HEX);
      irsend.sendRC5(codeValue, codeLen);
    }
    else {
    
    
      irsend.sendRC6(codeValue, codeLen);
      Serial.print("Sent RC6 ");
      Serial.println(codeValue, HEX);
    }
  }
  else if (codeType == UNKNOWN /* i.e. raw */) {
    
    
    // Assume 38 KHz
    irsend.sendRaw(rawCodes, codeLen, 38);
    Serial.println("Sent raw");
  }
}

int lastButtonState;

void loop() {
    
    
  // If button pressed, send the code.
  int buttonState = digitalRead(BUTTON_PIN);
  if (lastButtonState == HIGH && buttonState == LOW) {
    
    
    Serial.println("Released");
    irrecv.enableIRIn(); // Re-enable receiver
  }

  if (buttonState) {
    
    
    Serial.println("Pressed, sending");
    digitalWrite(STATUS_PIN, HIGH);
    sendCode(lastButtonState == buttonState);
    digitalWrite(STATUS_PIN, LOW);
    delay(50); // Wait a bit between retransmissions
  }
  else if (irrecv.decode(&results)) {
    
    
    digitalWrite(STATUS_PIN, HIGH);
    storeCode(&results);
    irrecv.resume(); // resume receiver
    digitalWrite(STATUS_PIN, LOW);
  }
  lastButtonState = buttonState;
}

Experimental serial port return

insert image description here
Experimental open source simulation programming (Linkboy V5.33)
insert image description here
Experimental serial port return status
insert image description here
Mind+ can read the codes of each button of the infrared remote control with only a simple three-line program

insert image description here

Experimental serial port return

insert image description here
insert image description here

insert image description here

Guess you like

Origin blog.csdn.net/weixin_41659040/article/details/132457130