├── .gitignore ├── README.md └── materials ├── 008激光头传感器 ├── sketch_jun08g │ └── jiguang.pde └── 激光头.txt ├── 1027震动马达模块 ├── 1027震动马达模块.doc └── _1027zhendong │ └── _1027zhendong.ino ├── 1602资料(1).rar ├── 2A大电流双路直流电机驱动扩展板 ├── 2A大电流双路直流电机驱动扩展板.doc └── dianliushuanglu │ └── dianliushuanglu.ino ├── 5050 RGB LED模块 ├── 5050 RGB LED模块.doc └── _5050_rgb_LED │ └── _5050_rgb_LED.ino ├── 8mm LED发光模块 ├── 8mm LED发光模块.doc └── _8MM_LED │ └── _8MM_LED.ino ├── DHT11温湿度传感器模块 ├── DHT11温湿度传感器模块.doc └── wenshiduchuanganqi │ └── wenshiduchuanganqi.ino ├── ESP8266学习导航.txt ├── L298N接线示意图.jpg ├── LM35 温度传感器模块 ├── LM35 温度传感器模块.doc └── LM35wendu │ └── LM35wendu.ino ├── PS2摇杆模块 ├── PS2yaogan │ └── PS2yaogan.ino └── PS2摇杆模块.doc ├── RGB全彩LED模块 ├── RGBquancai │ └── RGBquancai.ino └── RGB全彩LED模块.doc ├── dianliushuanglu └── dianliushuanglu.ino ├── 人体热释电运动传感器模块 ├── rentireshi │ └── rentireshi.ino └── 人体热释电运动传感器模块.doc ├── 人体红外热释电模块 ├── rentihongwai │ └── rentihongwai.ino └── 人体红外热释电模块.doc ├── 倾斜角度传感器模块 ├── qingxiejiaodu │ └── qingxiejiaodu.ino └── 倾斜角度传感器模块.doc ├── 压力传感器 ├── yalichuanganqi │ └── yalichuanganqi.ino └── 压力传感器.doc ├── 四位数码管模块 ├── siweishumaguan │ └── siweishumaguan.ino └── 四位数码管模块.doc ├── 土壤传感器模块 ├── turangchuanganq │ └── turangchuanganq.ino └── 土壤传感器模块.doc ├── 声音传感器模块 ├── shengychuanganqi │ └── shengychuanganqi.ino └── 声音传感器模块.doc ├── 摇杆模块 ├── yaoganmokuai │ └── yaoganmokuai.ino └── 摇杆模块.doc ├── 有源蜂鸣器传感器模块 ├── youyuanfengmingqi │ └── youyuanfengmingqi.ino └── 有源蜂鸣器传感器模块.doc ├── 模拟灰度传感器 ├── monihuidu │ └── monihuidu.ino └── 模拟灰度传感器.doc ├── 步进电机驱动板模块 ├── bujindianji │ └── bujindianji.ino └── 步进电机驱动板模块.doc ├── 水位传感器 ├── shuiwei1 │ └── shuiwei1.ino ├── shuiwei2 │ └── shuiwei2.ino └── 水位传感器.doc ├── 流水灯 ├── 1BBA36C7-9725-47c4-82F9-555342DC247C.png ├── SI2302.pdf └── breath_LED │ └── breath_LED.pde ├── 温度传感器模块 ├── wenduchengxu1 │ └── wenduchengxu1.ino ├── wenduchengxu2 │ └── wenduchengxu2.ino └── 温度传感器模块.doc ├── 火焰传感器模块.zip ├── 火焰传感器模块 ├── huoyanchuanganmokuai │ └── huoyanchuanganmokuai.ino └── 火焰传感器模块.doc ├── 碰撞传感器模块 ├── pengzhuang │ └── pengzhuang.ino └── 碰撞传感器模块.doc ├── 磁力传感器模块 ├── cilichuanganmokuai │ └── cilichuangan │ │ └── cilichuangan.ino └── 磁力传感器模块.doc ├── 红外发射传感器模块 ├── hongwaifas │ ├── fasheduan │ │ └── fasheduan.ino │ ├── hongwaifas.ino │ └── jieshou │ │ └── jieshou.ino └── 红外发射传感器模块.doc ├── 红外接收传感器模块 ├── hongwaijieshou │ ├── hongwai │ │ └── hongwai.ino │ └── hongwaijieshou.ino └── 红外接收传感器模块.doc ├── 红色按键模块 ├── hongseanj │ └── hongseanj.ino └── 红色按键模块.doc ├── 继电器模块 ├── jidianqi │ └── jidianqi.ino └── 继电器模块.doc ├── 触摸传感器模块 ├── chumchuanganqi │ └── chumchuanganqi.ino └── 触摸传感器模块.doc ├── 超声波传感器模块 ├── chaoshengbchuanganqidanxian │ └── chaoshengbchuanganqi.ino └── chaoshengboshuangxian │ └── chaoshengboshuangxian.ino ├── 陶瓷震动传感器模块 ├── taocizhendong │ └── taocizhendong.ino └── 陶瓷震动传感器模块.doc ├── 震动传感器模块 ├── zhendong │ └── zhendong.ino └── 震动传感器模块.doc └── 霍尔传感器 ├── huoer └── huoer.ino └── 霍尔传感器.doc /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | 106 | 107 | *.swp 108 | *.swo 109 | *.un* 110 | *~ 111 | *.pyc 112 | *.pyo 113 | *.o 114 | *.lo 115 | *.la 116 | *.al 117 | *.so 118 | *.so.[0-9]* 119 | *.mo 120 | *.rej 121 | *.rdb 122 | *DS_Store 123 | bin/ 124 | build/ 125 | *.sqlite 126 | *installed.cfg 127 | venv 128 | venvs 129 | indexdir/ 130 | *.sqlite3 131 | *.db 132 | *.swn 133 | t/ 134 | .cache/ 135 | pysrc/collie/uploaded_files/ 136 | 137 | .qiniu_pythonsdk_hostscache.json 138 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # learn-sensors 2 | 使用micropython和esp32芯片驱动传感器的学习,适合儿童学习python编程 3 | -------------------------------------------------------------------------------- /materials/008激光头传感器/sketch_jun08g/jiguang.pde: -------------------------------------------------------------------------------- 1 | void setup() { 2 | pinMode(13, OUTPUT); // 定义13脚为数字输出接口 3 | } 4 | 5 | void loop() { 6 | digitalWrite(13, HIGH); // 打开激光头 7 | delay(1000); // 延时一秒 8 | digitalWrite(13, LOW); // 关闭激光头 9 | delay(1000); // 延时一秒 10 | } 11 | -------------------------------------------------------------------------------- /materials/008激光头传感器/激光头.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/008激光头传感器/激光头.txt -------------------------------------------------------------------------------- /materials/1027震动马达模块/1027震动马达模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/1027震动马达模块/1027震动马达模块.doc -------------------------------------------------------------------------------- /materials/1027震动马达模块/_1027zhendong/_1027zhendong.ino: -------------------------------------------------------------------------------- 1 | int zhendong = 3; 2 | int led = 2; 3 | int zhen = A0; 4 | void setup() 5 | { 6 | pinMode(2,OUTPUT); 7 | pinMode(3,OUTPUT); 8 | pinMode(A0,INPUT); 9 | Serial.begin(9600); 10 | } 11 | void loop() 12 | { 13 | int val = analogRead(A0); 14 | Serial.print("zhendong = "); 15 | Serial.println(val); 16 | digitalWrite(3,HIGH); 17 | if(val > 30) 18 | { 19 | digitalWrite(2,HIGH); 20 | delay(1000); 21 | } 22 | else 23 | digitalWrite(2,LOW); 24 | } 25 | -------------------------------------------------------------------------------- /materials/1602资料(1).rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/1602资料(1).rar -------------------------------------------------------------------------------- /materials/2A大电流双路直流电机驱动扩展板/2A大电流双路直流电机驱动扩展板.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/2A大电流双路直流电机驱动扩展板/2A大电流双路直流电机驱动扩展板.doc -------------------------------------------------------------------------------- /materials/2A大电流双路直流电机驱动扩展板/dianliushuanglu/dianliushuanglu.ino: -------------------------------------------------------------------------------- 1 | int E1 = 5; 2 | int M1 = 4; 3 | int E2 = 6; 4 | int M2 = 7; 5 | void setup() 6 | { 7 | pinMode(M1, OUTPUT); 8 | pinMode(M2, OUTPUT); 9 | } 10 | void loop() 11 | { 12 | int value; 13 | for(value = 0 ; value <= 255; value+=5) 14 | { 15 | digitalWrite(M1,HIGH); 16 | digitalWrite(M2, HIGH); 17 | analogWrite(E1, value); //PWM调速 18 | analogWrite(E2, value); //PWM调速 19 | delay(30); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /materials/5050 RGB LED模块/5050 RGB LED模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/5050 RGB LED模块/5050 RGB LED模块.doc -------------------------------------------------------------------------------- /materials/5050 RGB LED模块/_5050_rgb_LED/_5050_rgb_LED.ino: -------------------------------------------------------------------------------- 1 | #include "Makeblock.h" 2 | #include 3 | #include 4 | MeRGBLed led(PORT_3); 5 | int ledCount = 4; 6 | float j,f,k; 7 | void setup() 8 | { 9 | led.setNumber(ledCount); 10 | } 11 | void loop(){ 12 | color_loop(); 13 | } 14 | void color_loop() 15 | { 16 | for (uint8_t t = 0; t < ledCount; t++) 17 | { 18 | uint8_t red = 64*(1+sin(t/2.0 + j/4.0 )); 19 | uint8_t green = 64*(1+sin(t/1.0 + f/9.0 + 2.1)); 20 | uint8_t blue = 64*(1+sin(t/3.0 + k/14.0 + 4.2)); 21 | led.setColorAt(t, red,green,blue); 22 | } 23 | led.show(); 24 | j+=random(1,6)/6.0; 25 | f+=random(1,6)/6.0; 26 | k+=random(1,6)/6.0; 27 | } 28 | -------------------------------------------------------------------------------- /materials/8mm LED发光模块/8mm LED发光模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/8mm LED发光模块/8mm LED发光模块.doc -------------------------------------------------------------------------------- /materials/8mm LED发光模块/_8MM_LED/_8MM_LED.ino: -------------------------------------------------------------------------------- 1 | int led =13; //定义13号引脚链接LED发光模块 2 | void setup() 3 | { 4 | pinMode(led,OUTPUT); //定义引脚为输出模式 5 | } 6 | void loop() 7 | { 8 | digitalWrite(led, HIGH); //点亮LED 9 | delay(1000); //延时等待1秒 10 | digitalWrite(led, LOW); //熄灭LED 11 | delay(1000); //延时等待1秒 12 | } 13 | -------------------------------------------------------------------------------- /materials/DHT11温湿度传感器模块/DHT11温湿度传感器模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/DHT11温湿度传感器模块/DHT11温湿度传感器模块.doc -------------------------------------------------------------------------------- /materials/DHT11温湿度传感器模块/wenshiduchuanganqi/wenshiduchuanganqi.ino: -------------------------------------------------------------------------------- 1 | #define DHT11_PIN 0 2 | byte read_dht11_dat() 3 | { 4 | byte i = 0; 5 | byte result=0; 6 | for(i=0; i< 8; i++){ 7 | while(!(PINC & _BV(DHT11_PIN))); // wait for 50us 8 | delayMicroseconds(30); 9 | if(PINC & _BV(DHT11_PIN)) 10 | result |=(1<<(7-i)); 11 | while((PINC & _BV(DHT11_PIN))); // wait '1' finish 12 | } 13 | return result; 14 | } 15 | void setup() 16 | { 17 | DDRC |= _BV(DHT11_PIN); 18 | PORTC |= _BV(DHT11_PIN); 19 | Serial.begin(19200); 20 | Serial.println("Ready"); 21 | } 22 | 23 | void loop() 24 | { 25 | byte dht11_dat[5]; 26 | byte dht11_in; 27 | byte i; 28 | // start condition 29 | // 1. pull-down i/o pin from 18ms 30 | PORTC &= ~_BV(DHT11_PIN); 31 | delay(18); 32 | PORTC |= _BV(DHT11_PIN); 33 | delayMicroseconds(40); 34 | DDRC &= ~_BV(DHT11_PIN); 35 | delayMicroseconds(40); 36 | dht11_in = PINC & _BV(DHT11_PIN); 37 | if(dht11_in){ 38 | Serial.println("dht11 start condition 1 not met"); 39 | return; 40 | } 41 | delayMicroseconds(80); 42 | dht11_in = PINC & _BV(DHT11_PIN); 43 | if(!dht11_in){ 44 | Serial.println("dht11 start condition 2 not met"); 45 | return; 46 | } 47 | delayMicroseconds(80); 48 | // now ready for data reception 49 | for (i=0; i<5; i++) 50 | dht11_dat[i] = read_dht11_dat(); 51 | DDRC |= _BV(DHT11_PIN); 52 | PORTC |= _BV(DHT11_PIN); 53 | byte dht11_check_sum = dht11_dat[0]+dht11_dat[1]+dht11_dat[2]+dht11_dat[3]; 54 | // check check_sum 55 | if(dht11_dat[4]!= dht11_check_sum) 56 | { 57 | Serial.println("DHT11 checksum error"); 58 | } 59 | Serial.print("Current humdity = "); 60 | Serial.print(dht11_dat[0], DEC); 61 | Serial.print("."); 62 | Serial.print(dht11_dat[1], DEC); 63 | Serial.print("% "); 64 | Serial.print("temperature = "); 65 | Serial.print(dht11_dat[2], DEC); 66 | Serial.print("."); 67 | Serial.print(dht11_dat[3], DEC); 68 | Serial.println("C "); 69 | delay(2000); 70 | } 71 | -------------------------------------------------------------------------------- /materials/ESP8266学习导航.txt: -------------------------------------------------------------------------------- 1 | http://www.arduino.cn/thread-17895-1-1.html -------------------------------------------------------------------------------- /materials/L298N接线示意图.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/L298N接线示意图.jpg -------------------------------------------------------------------------------- /materials/LM35 温度传感器模块/LM35 温度传感器模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/LM35 温度传感器模块/LM35 温度传感器模块.doc -------------------------------------------------------------------------------- /materials/LM35 温度传感器模块/LM35wendu/LM35wendu.ino: -------------------------------------------------------------------------------- 1 | int pin = 0; //模拟口0 2 | int tempc = 0;//温度变量 3 | int samples[8]; 4 | int maxi = -100,mini = 100; 5 | int i; 6 | void setup(){ 7 | Serial.begin(9600); // 设置波特率为9600 8 | } 9 | void loop(){ 10 | for(i = 0;i<=7;i++) 11 | { 12 | samples[i] = ( 5.0 * analogRead(pin) * 100.0) / 1024.0; 13 | tempc = tempc + samples[i]; 14 | delay(100); 15 | } 16 | tempc = tempc/8.0; 17 | if(tempc > maxi) {maxi = tempc;} 18 | if(tempc < mini) {mini = tempc;} 19 | Serial.print(tempc,DEC); //打印温度值 20 | Serial.print(" Celsius, "); 21 | Serial.print(maxi,DEC); 22 | Serial.print(" Max, "); 23 | Serial.print(mini,DEC); 24 | Serial.println(" Min"); 25 | tempc = 0; 26 | delay(100); 27 | } 28 | -------------------------------------------------------------------------------- /materials/PS2摇杆模块/PS2yaogan/PS2yaogan.ino: -------------------------------------------------------------------------------- 1 | int X; 2 | int Y; 3 | int B; 4 | void setup() { 5 | Serial.begin(9600); 6 | } 7 | void loop() { 8 | X = analogRead(A0); //读取A0口模拟值 9 | Y = analogRead(A1); //读取A1口模拟值 10 | B = analogRead(A2); //读取A2口模拟值 11 | Serial.println(X); 12 | Serial.println(Y); 13 | Serial.println(B); 14 | delay(1000); 15 | } 16 | -------------------------------------------------------------------------------- /materials/PS2摇杆模块/PS2摇杆模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/PS2摇杆模块/PS2摇杆模块.doc -------------------------------------------------------------------------------- /materials/RGB全彩LED模块/RGBquancai/RGBquancai.ino: -------------------------------------------------------------------------------- 1 | #include "Makeblock.h" 2 | #include 3 | #include 4 | MeRGBLed led(PORT_3); 5 | int ledCount = 4; 6 | float j,f,k; 7 | void setup() 8 | { 9 | led.setNumber(ledCount); 10 | } 11 | void loop(){ 12 | color_loop(); 13 | } 14 | void color_loop() 15 | { 16 | for (uint8_t t = 0; t < ledCount; t++) 17 | { 18 | uint8_t red = 64*(1+sin(t/2.0 + j/4.0 )); 19 | uint8_t green = 64*(1+sin(t/1.0 + f/9.0 + 2.1)); 20 | uint8_t blue = 64*(1+sin(t/3.0 + k/14.0 + 4.2)); 21 | led.setColorAt(t, red,green,blue); 22 | } 23 | led.show(); 24 | j+=random(1,6)/6.0; 25 | f+=random(1,6)/6.0; 26 | k+=random(1,6)/6.0; 27 | } 28 | -------------------------------------------------------------------------------- /materials/RGB全彩LED模块/RGB全彩LED模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/RGB全彩LED模块/RGB全彩LED模块.doc -------------------------------------------------------------------------------- /materials/dianliushuanglu/dianliushuanglu.ino: -------------------------------------------------------------------------------- 1 | int E1 = 5; 2 | int M1 = 4; 3 | int E2 = 6; 4 | int M2 = 7; 5 | void setup() 6 | { 7 | pinMode(M1, OUTPUT); 8 | pinMode(M2, OUTPUT); 9 | } 10 | void loop() 11 | { 12 | int value; 13 | for(value = 0 ; value <= 255; value+=5) 14 | { 15 | digitalWrite(M1,HIGH); 16 | digitalWrite(M2, HIGH); 17 | analogWrite(E1, value); //PWM调速 18 | analogWrite(E2, value); //PWM调速 19 | delay(30); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /materials/人体热释电运动传感器模块/rentireshi/rentireshi.ino: -------------------------------------------------------------------------------- 1 | byte sensorPin = 2; 2 | byte indicator = 13; 3 | void setup() 4 | { 5 | pinMode(sensorPin,INPUT); 6 | pinMode(indicator,OUTPUT); 7 | Serial.begin(9600); 8 | } 9 | void loop() 10 | { 11 | byte state = digitalRead(sensorPin); 12 | digitalWrite(indicator,state); 13 | if(state == 1)Serial.println("Somebody is in this area!"); 14 | else if(state == 0)Serial.println("No one!"); 15 | delay(500); 16 | } 17 | -------------------------------------------------------------------------------- /materials/人体热释电运动传感器模块/人体热释电运动传感器模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/人体热释电运动传感器模块/人体热释电运动传感器模块.doc -------------------------------------------------------------------------------- /materials/人体红外热释电模块/rentihongwai/rentihongwai.ino: -------------------------------------------------------------------------------- 1 | byte sensorPin = 2; //设置传感器引脚为数字接口2 2 | byte indicator = 13; //设置指示器引脚为数字接口13 3 | void setup() 4 | { 5 | pinMode(sensorPin,INPUT); //设置传感器引脚为输入模式 6 | pinMode(indicator,OUTPUT);//设置指示器引脚为输出模式 7 | Serial.begin(9600); 8 | } 9 | void loop() 10 | { 11 | byte state = digitalRead(sensorPin); //读取传感器的状态 12 | digitalWrite(indicator,state); //输出指示器的状态 13 | if(state == 1) 14 | Serial.println("Somebody is in this area!"); //通过串口输出当前状态 15 | else if(state == 0) 16 | Serial.println("No one!"); 17 | delay(500); //延时500ms 18 | } 19 | -------------------------------------------------------------------------------- /materials/人体红外热释电模块/人体红外热释电模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/人体红外热释电模块/人体红外热释电模块.doc -------------------------------------------------------------------------------- /materials/倾斜角度传感器模块/qingxiejiaodu/qingxiejiaodu.ino: -------------------------------------------------------------------------------- 1 | int qingjiaoPin = 2; //定义倾角开关信号引脚数字2 2 | int ledPin = 13; //定义板载LED引脚 3 | int qingjiaoState = 0; //定义倾角状态 4 | void setup() 5 | { 6 | pinMode(ledPin, OUTPUT); //定义LED引脚为输出 7 | pinMode(qingjiaoPin, INPUT); //定义倾角开关引脚为输入 8 | Serial.begin(9600); 9 | } 10 | 11 | void loop() 12 | { 13 | qingjiaoState = digitalRead(qingjiaoPin); //读取倾角开关引脚的值 14 | if (qingjiaoState == LOW) { //判断倾角开关的状态值是否为低电平 15 | digitalWrite(ledPin, HIGH); //向LED引脚置高电平 16 | Serial.print("qing jiao State = "); 17 | Serial.println(qingjiaoState); 18 | } 19 | else { 20 | digitalWrite(ledPin, LOW); //向LED引脚置低电平 21 | Serial.print("qing jiao State = "); 22 | Serial.println(qingjiaoState); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /materials/倾斜角度传感器模块/倾斜角度传感器模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/倾斜角度传感器模块/倾斜角度传感器模块.doc -------------------------------------------------------------------------------- /materials/压力传感器/yalichuanganqi/yalichuanganqi.ino: -------------------------------------------------------------------------------- 1 | #define FORCE 0 2 | float value = 0;float resistance = 0; 3 | void setup() 4 | { 5 | Serial.begin(9600); 6 | Serial.println("0.5\" Force Sensitive Resistor Test"); 7 | } 8 | void loop() 9 | { 10 | value = analogRead(FORCE); 11 | resistance = ((26.4 * value)/(1-(value/1023.0))); 12 | Serial.println(resistance,DEC); 13 | delay(200); 14 | } 15 | -------------------------------------------------------------------------------- /materials/压力传感器/压力传感器.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/压力传感器/压力传感器.doc -------------------------------------------------------------------------------- /materials/四位数码管模块/siweishumaguan/siweishumaguan.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "TM1637.h" 3 | #define ON 1 4 | #define OFF 0 5 | int8_t TimeDisp[] = {0x00,0x00,0x00,0x00}; 6 | unsigned char ClockPoint = 1; 7 | unsigned char Update; 8 | unsigned char halfsecond = 0; 9 | unsigned char second; 10 | unsigned char minute = 0; 11 | unsigned char hour = 12; 12 | #define CLK A5//pins definitions for TM1637 and can be changed to other ports 13 | #define DIO A4 14 | TM1637 tm1637(CLK,DIO); 15 | void setup() 16 | { 17 | tm1637.set(); 18 | tm1637.init(); 19 | Timer1.initialize(500000);//timing for 500ms 20 | Timer1.attachInterrupt(TimingISR);//declare the interrupt serve routine:TimingISR 21 | } 22 | void loop() 23 | { 24 | if(Update == ON) 25 | { 26 | TimeUpdate(); 27 | tm1637.display(TimeDisp); 28 | } 29 | 30 | } 31 | void TimingISR() 32 | { 33 | halfsecond ++; 34 | Update = ON; 35 | if(halfsecond == 2){ 36 | second ++; 37 | if(second == 60) 38 | { 39 | minute ++; 40 | if(minute == 60) 41 | { 42 | hour ++; 43 | if(hour == 24)hour = 0; 44 | minute = 0; 45 | } 46 | second = 0; 47 | } 48 | halfsecond = 0; 49 | } 50 | // Serial.println(second); 51 | ClockPoint = (~ClockPoint) & 0x01; 52 | } 53 | void TimeUpdate(void) 54 | { 55 | if(ClockPoint)tm1637.point(POINT_ON); 56 | else tm1637.point(POINT_OFF); 57 | TimeDisp[0] = hour / 10; 58 | TimeDisp[1] = hour % 10; 59 | TimeDisp[2] = minute / 10; 60 | TimeDisp[3] = minute % 10; 61 | Update = OFF; 62 | } 63 | -------------------------------------------------------------------------------- /materials/四位数码管模块/四位数码管模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/四位数码管模块/四位数码管模块.doc -------------------------------------------------------------------------------- /materials/土壤传感器模块/turangchuanganq/turangchuanganq.ino: -------------------------------------------------------------------------------- 1 | void setup() 2 | { 3 | Serial.begin(9600); 4 | } 5 | void loop() 6 | { 7 | Serial.print("Moisture Sensor Value:"); 8 | Serial.println(analogRead(0)); 9 | delay(1000); 10 | } 11 | -------------------------------------------------------------------------------- /materials/土壤传感器模块/土壤传感器模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/土壤传感器模块/土壤传感器模块.doc -------------------------------------------------------------------------------- /materials/声音传感器模块/shengychuanganqi/shengychuanganqi.ino: -------------------------------------------------------------------------------- 1 | void setup() 2 | { 3 | Serial.begin(9600); // 打开串口,设置波特率为9600 bps 4 | } 5 | void loop() 6 | { 7 | int val; 8 | val=analogRead(0); //传感器接于模拟口0 9 | Serial.println(val,DEC);//从串口发送数据并换行 10 | delay(100); 11 | } 12 | -------------------------------------------------------------------------------- /materials/声音传感器模块/声音传感器模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/声音传感器模块/声音传感器模块.doc -------------------------------------------------------------------------------- /materials/摇杆模块/yaoganmokuai/yaoganmokuai.ino: -------------------------------------------------------------------------------- 1 | int JoyStick_X = 0; //x 2 | int JoyStick_Y = 1; //y 3 | int JoyStick_Z = 3; //key 4 | 5 | void setup() 6 | { 7 | pinMode(JoyStick_Z, INPUT); 8 | Serial.begin(9600); // 9600 bps 9 | } 10 | void loop() 11 | { 12 | int x,y,z; 13 | x=analogRead(JoyStick_X); 14 | y=analogRead(JoyStick_Y); 15 | z=digitalRead(JoyStick_Z); 16 | Serial.print(x ,DEC); 17 | Serial.print(","); 18 | Serial.print(y ,DEC); 19 | Serial.print(","); 20 | Serial.println(z ,DEC); 21 | delay(100); 22 | } 23 | -------------------------------------------------------------------------------- /materials/摇杆模块/摇杆模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/摇杆模块/摇杆模块.doc -------------------------------------------------------------------------------- /materials/有源蜂鸣器传感器模块/youyuanfengmingqi/youyuanfengmingqi.ino: -------------------------------------------------------------------------------- 1 | int buzzPin=3 ; //定义蜂鸣器链接引脚 2 | void setup() 3 | { 4 | pinMode(buzzPin ,OUTPUT); //定义引脚模式为输出模式 5 | } 6 | 7 | void loop() 8 | { 9 | digitalWrite(buzzPin,HIGH); //输入高电平 10 | delay(1000); //延时1秒 11 | digitalWrite(buzzPin,LOW); //输入低电平 12 | delay(1000); //延时1秒 13 | } 14 | -------------------------------------------------------------------------------- /materials/有源蜂鸣器传感器模块/有源蜂鸣器传感器模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/有源蜂鸣器传感器模块/有源蜂鸣器传感器模块.doc -------------------------------------------------------------------------------- /materials/模拟灰度传感器/monihuidu/monihuidu.ino: -------------------------------------------------------------------------------- 1 | void setup() 2 | { 3 | Serial.begin(9600); // open serial port, set the baud rate to 9600 bps 4 | } 5 | void loop() 6 | { 7 | int val; 8 | val=analogRead(0); //connect grayscale sensor to Analog 0 9 | Serial.println(val,DEC);//print the value to serial 10 | delay(100); 11 | } 12 | -------------------------------------------------------------------------------- /materials/模拟灰度传感器/模拟灰度传感器.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/模拟灰度传感器/模拟灰度传感器.doc -------------------------------------------------------------------------------- /materials/步进电机驱动板模块/bujindianji/bujindianji.ino: -------------------------------------------------------------------------------- 1 | /* Simple Stepper Motor Control Exaple Code 2 | * 3 | * by Dejan Nedelkovski, www.HowToMechatronics.com 4 | * 5 | */ 6 | // defines pins numbers 7 | const int stepPin = 3; 8 | const int dirPin = 4; 9 | 10 | void setup() { 11 | // Sets the two pins as Outputs 12 | pinMode(stepPin,OUTPUT); 13 | pinMode(dirPin,OUTPUT); 14 | } 15 | void loop() { 16 | digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction 17 | // Makes 200 pulses for making one full cycle rotation 18 | for(int x = 0; x < 200; x++) { 19 | digitalWrite(stepPin,HIGH); 20 | delayMicroseconds(500); 21 | digitalWrite(stepPin,LOW); 22 | delayMicroseconds(500); 23 | } 24 | delay(1000); // One second delay 25 | 26 | digitalWrite(dirPin,LOW); //Changes the rotations direction 27 | // Makes 400 pulses for making two full cycle rotation 28 | for(int x = 0; x < 400; x++) { 29 | digitalWrite(stepPin,HIGH); 30 | delayMicroseconds(500); 31 | digitalWrite(stepPin,LOW); 32 | delayMicroseconds(500); 33 | } 34 | delay(1000); 35 | } 36 | -------------------------------------------------------------------------------- /materials/步进电机驱动板模块/步进电机驱动板模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/步进电机驱动板模块/步进电机驱动板模块.doc -------------------------------------------------------------------------------- /materials/水位传感器/shuiwei1/shuiwei1.ino: -------------------------------------------------------------------------------- 1 | int val = 0; 2 | int shuiwei = A0; 3 | void setup() { 4 | Serial.begin(9600); 5 | } 6 | 7 | void loop() { 8 | val = analogRead(A0); 9 | Serial.print("shui wei = ") ; 10 | Serial.println(val); 11 | delay(1000); 12 | } 13 | -------------------------------------------------------------------------------- /materials/水位传感器/shuiwei2/shuiwei2.ino: -------------------------------------------------------------------------------- 1 | int analogPin = A1; //水位传感器连接到模拟口 1 2 | int led = 12; //食 人鱼灯连接到数字口 12 3 | int val = 0; //定 义变量 val 初值为 0 4 | int data = 0; //定义变量 data 初值为 0 5 | void setup() 6 | { 7 | pinMode(led, OUTPUT); //定义 led 为输出引脚 8 | Serial.begin(9600); //设定波特率为 9600 9 | } 10 | void loop() 11 | { 12 | val = analogRead(analogPin); //读取模拟值送给变量 val 13 | if( val>600){ //判断变量 val 是否大于 600 14 | digitalWrite(led,HIGH); //变量 val 大于 600 时,点亮食人鱼灯 15 | } 16 | else{ 17 | digitalWrite(led,LOW); //变量 val 小于 600 时,熄灭食人鱼灯 18 | } 19 | data = val; //变量 val 赋值给变 量 data 20 | Serial.println(data); //串口打印变量 data 21 | delay(100); 22 | } 23 | -------------------------------------------------------------------------------- /materials/水位传感器/水位传感器.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/水位传感器/水位传感器.doc -------------------------------------------------------------------------------- /materials/流水灯/1BBA36C7-9725-47c4-82F9-555342DC247C.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/流水灯/1BBA36C7-9725-47c4-82F9-555342DC247C.png -------------------------------------------------------------------------------- /materials/流水灯/SI2302.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/流水灯/SI2302.pdf -------------------------------------------------------------------------------- /materials/流水灯/breath_LED/breath_LED.pde: -------------------------------------------------------------------------------- 1 | #define LED 9 2 | int i = 0; 3 | 4 | void setup() 5 | { 6 | pinMode(LED,OUTPUT); 7 | } 8 | void loop() 9 | { 10 | for(i=0;i<255;i++) 11 | { 12 | analogWrite(LED,i); 13 | delay(15); 14 | } 15 | for(i=255;i>0;i--) 16 | { 17 | analogWrite(LED,i); 18 | delay(15); 19 | } 20 | analogWrite(LED,0); 21 | delay(1000); 22 | } 23 | -------------------------------------------------------------------------------- /materials/温度传感器模块/wenduchengxu1/wenduchengxu1.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // 定义DS18B20数据口连接arduino的2号IO上 5 | #define ONE_WIRE_BUS 2 6 | 7 | // 初始连接在单总线上的单总线设备 8 | OneWire oneWire(ONE_WIRE_BUS); 9 | DallasTemperature sensors(&oneWire); 10 | 11 | void setup(void) 12 | { 13 | // 设置串口通信波特率 14 | Serial.begin(9600); 15 | Serial.println("Dallas Temperature IC Control Library Demo"); 16 | 17 | // 初始库 18 | sensors.begin(); 19 | } 20 | 21 | void loop(void) 22 | { 23 | Serial.print("Requesting temperatures..."); 24 | sensors.requestTemperatures(); // 发送命令获取温度 25 | Serial.println("DONE"); 26 | 27 | Serial.print("Temperature for the device 1 (index 0) is: "); 28 | Serial.println(sensors.getTempCByIndex(0)); 29 | -------------------------------------------------------------------------------- /materials/温度传感器模块/wenduchengxu2/wenduchengxu2.ino: -------------------------------------------------------------------------------- 1 | #include 2 | OneWire ds(10); // 连接arduino10引脚 3 | 4 | void setup(void) { 5 | Serial.begin(9600); 6 | } 7 | 8 | void loop(void) { 9 | byte i; 10 | byte present = 0; 11 | byte type_s; 12 | byte data[12]; 13 | byte addr[8]; 14 | float celsius, fahrenheit; 15 | 16 | if ( !ds.search(addr)) { 17 | Serial.println("No more addresses."); 18 | Serial.println(); 19 | ds.reset_search(); 20 | delay(250); 21 | return; 22 | } 23 | 24 | Serial.print("ROM ="); 25 | for( i = 0; i < 8; i++) { 26 | Serial.write(' '); 27 | Serial.print(addr[i], HEX); 28 | } 29 | 30 | if (OneWire::crc8(addr, 7) != addr[7]) { 31 | Serial.println("CRC is not valid!"); 32 | return; 33 | } 34 | Serial.println(); 35 | 36 | // the first ROM byte indicates which chip 37 | switch (addr[0]) { 38 | case 0x10: 39 | Serial.println(" Chip = DS18S20"); // or old DS1820 40 | type_s = 1; 41 | break; 42 | case 0x28: 43 | Serial.println(" Chip = DS18B20"); 44 | type_s = 0; 45 | break; 46 | case 0x22: 47 | Serial.println(" Chip = DS1822"); 48 | type_s = 0; 49 | break; 50 | default: 51 | Serial.println("Device is not a DS18x20 family device."); 52 | return; 53 | } 54 | 55 | ds.reset(); 56 | ds.select(addr); 57 | ds.write(0x44,1); // start conversion, with parasite power on at the end 58 | 59 | delay(1000); // maybe 750ms is enough, maybe not 60 | // we might do a ds.depower() here, but the reset will take care of it. 61 | 62 | present = ds.reset(); 63 | ds.select(addr); 64 | ds.write(0xBE); // Read Scratchpad 65 | 66 | Serial.print(" Data = "); 67 | Serial.print(present,HEX); 68 | Serial.print(" "); 69 | for ( i = 0; i < 9; i++) { // we need 9 bytes 70 | data[i] = ds.read(); 71 | Serial.print(data[i], HEX); 72 | Serial.print(" "); 73 | } 74 | Serial.print(" CRC="); 75 | Serial.print(OneWire::crc8(data, 8), HEX); 76 | Serial.println(); 77 | 78 | // convert the data to actual temperature 79 | 80 | unsigned int raw = (data[1] << 8) | data[0]; 81 | if (type_s) { 82 | raw = raw << 3; // 9 bit resolution default 83 | if (data[7] == 0x10) { 84 | // count remain gives full 12 bit resolution 85 | raw = (raw & 0xFFF0) + 12 - data[6]; 86 | } 87 | } else { 88 | byte cfg = (data[4] & 0x60); 89 | if (cfg == 0x00) raw = raw << 3; // 9 bit resolution, 93.75 ms 90 | else if (cfg == 0x20) raw = raw << 2; // 10 bit res, 187.5 ms 91 | else if (cfg == 0x40) raw = raw << 1; // 11 bit res, 375 ms 92 | // default is 12 bit resolution, 750 ms conversion time 93 | } 94 | celsius = (float)raw / 16.0; 95 | fahrenheit = celsius * 1.8 + 32.0; 96 | Serial.print(" Temperature = "); 97 | Serial.print(celsius); 98 | Serial.print(" Celsius, "); 99 | Serial.print(fahrenheit); 100 | Serial.println(" Fahrenheit"); 101 | } 102 | -------------------------------------------------------------------------------- /materials/温度传感器模块/温度传感器模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/温度传感器模块/温度传感器模块.doc -------------------------------------------------------------------------------- /materials/火焰传感器模块.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/火焰传感器模块.zip -------------------------------------------------------------------------------- /materials/火焰传感器模块/huoyanchuanganmokuai/huoyanchuanganmokuai.ino: -------------------------------------------------------------------------------- 1 | void setup() 2 | { //初始化函数 3 | Serial.begin(9600); //设置串口波特率为9600 4 | } 5 | void loop() 6 | { 7 | Serial.print("Flame Sensor Value:"); //串口打印Flame Sensor Value: 8 | Serial.println(analogRead(0)); //串口打印A0口读取的模拟值 9 | delay(100); //延时100ms 10 | } 11 | -------------------------------------------------------------------------------- /materials/火焰传感器模块/火焰传感器模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/火焰传感器模块/火焰传感器模块.doc -------------------------------------------------------------------------------- /materials/碰撞传感器模块/pengzhuang/pengzhuang.ino: -------------------------------------------------------------------------------- 1 | int sw = 3;//定义引脚 2 | int val = 0; 3 | void setup() 4 | { 5 | Serial.begin(9600);//设置波特率 6 | pinMode(sw,INPUT); 7 | } 8 | 9 | void loop() 10 | { 11 | 12 | val = digitalRead(sw); //读传感器信息 13 | if(LOW == val) 14 | { 15 | Serial.println(“switch is CLOSE”); 16 | delay(500); 17 | } 18 | else 19 | { 20 | Serial.println(“switch is OPEN”); 21 | delay(500); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /materials/碰撞传感器模块/碰撞传感器模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/碰撞传感器模块/碰撞传感器模块.doc -------------------------------------------------------------------------------- /materials/磁力传感器模块/cilichuanganmokuai/cilichuangan/cilichuangan.ino: -------------------------------------------------------------------------------- 1 | int magnetic=2; //定义数字接口 9为magnetic(磁感应模块) 2 | int led=13; //定义数字接口 8为LED灯 3 | void setup() 4 | { 5 | pinMode(led,OUTPUT); //设置led为数字输出 6 | pinMode(magnetic,INPUT); //设置magnetic为数字输入 7 | } 8 | 9 | void loop() 10 | { 11 | if(digitalRead(magnetic)) //如果感应到强磁场 12 | digitalWrite(led, HIGH); //LED灯亮起 13 | else //如果未感应到强磁场 14 | digitalWrite(led, LOW); //LED灯熄灭 15 | } 16 | -------------------------------------------------------------------------------- /materials/磁力传感器模块/磁力传感器模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/磁力传感器模块/磁力传感器模块.doc -------------------------------------------------------------------------------- /materials/红外发射传感器模块/hongwaifas/fasheduan/fasheduan.ino: -------------------------------------------------------------------------------- 1 | #include 2 | IRsend irsend; 3 | void setup() 4 | { 5 | } 6 | void loop() { 7 | 8 | irsend.sendRC5(0x0, 8); //send 0x0 code (8 bits) 9 | delay(200); 10 | irsend.sendRC5(0x1, 8); 11 | delay(200); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /materials/红外发射传感器模块/hongwaifas/hongwaifas.ino: -------------------------------------------------------------------------------- 1 | void setup() { 2 | // initialize digital pin 13 as an output. 3 | pinMode(3, OUTPUT); 4 | } 5 | // the loop function runs over and over again forever 6 | void loop() { 7 | digitalWrite(3, HIGH); // turn the LED on (HIGH is the voltage level) 8 | delay(1000); // wait for a second 9 | digitalWrite(3, LOW); // turn the LED off by making the voltage LOW 10 | delay(1000); // wait for a second 11 | } 12 | -------------------------------------------------------------------------------- /materials/红外发射传感器模块/hongwaifas/jieshou/jieshou.ino: -------------------------------------------------------------------------------- 1 | #include 2 | const int RECV_PIN = 11; 3 | const int LED_PIN = 13; 4 | IRrecv irrecv(RECV_PIN); 5 | decode_results results; 6 | void setup() 7 | { 8 | Serial.begin(9600); 9 | irrecv.enableIRIn(); // Start the receiver 10 | } 11 | void loop() 12 | { 13 | if (irrecv.decode(&results)) 14 | { 15 | if ( results.bits > 0 ) 16 | { 17 | int state; 18 | if ( 0x1 == results.value ) 19 | { 20 | state = HIGH; 21 | } 22 | else 23 | { 24 | state = LOW; 25 | } 26 | digitalWrite( LED_PIN, state ); 27 | } 28 | irrecv.resume(); // prepare to receive the next value 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /materials/红外发射传感器模块/红外发射传感器模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/红外发射传感器模块/红外发射传感器模块.doc -------------------------------------------------------------------------------- /materials/红外接收传感器模块/hongwaijieshou/hongwai/hongwai.ino: -------------------------------------------------------------------------------- 1 | #define IR_LED 2 //IR 接收数字口2 2 | #define MAX 128 3 | #define MICRO_STEP 10 4 | #define IDLE_PULSE 4000 5 | unsigned long pulses[MAX]; 6 | unsigned char IRCOM[7]; 7 | unsigned long z; 8 | int w; 9 | byte f=B00000000; // 定义f 为位 10 | int n; 11 | int ledpin=9; // 定义数字口9 为LED 模块接口 12 | void setup() 13 | { 14 | pinMode(IR_LED, INPUT); 15 | Serial.begin(115200); 16 | pinMode(ledpin,OUTPUT); //定义ledpin 为输出模式 17 | } 18 | 19 | void loop() 20 | { 21 | if( digitalRead(IR_LED) == LOW) 22 | { 23 | // 开始接收数据 24 | int count = 0; 25 | int exit = 0; 26 | while(!exit) 27 | { 28 | while( digitalRead(IR_LED) == LOW ) 29 | delayMic roseconds(MICRO_STEP); 30 | unsigned long start = micros(); 31 | int max_high = 0; 32 | while( digitalRead(IR_LED) == HIGH ) 33 | { 34 | delayMic roseconds(MICRO_STEP); 35 | max_high += MICRO_STEP; 36 | if( max_high > IDLE_PULSE ) 37 | { 38 | exit = 1; 39 | break; 40 | } 41 | } 42 | unsigned long duration = micros() - start; 43 | pulses[count++] = duration; 44 | } 45 | for(int i=3; i<4; i++) 46 | { 47 | for(int j=0;j<8;j++) 48 | { 49 | if(pulses[ i*8+j+1] < IDLE_PULSE) 50 | { 51 | IRCOM[i]=IRCOM [i] >> 1; 52 | if((pulses[i*8+j+1])>1000) 53 | {IRCOM[i] = IRCOM[i] | 0x80;} 54 | } 55 | z= pulses[i*8+j+1]; //将接收到的脉冲数据转换成十进制 56 | if(z<800) 57 | w=10000000; //如果Z 小于800 w=10000000 58 | else 59 | w=00000000; //如果Z 大于800 w=00000000 60 | f=f>>1; // 将f 右移1 位 61 | f=f+w; 62 | } 63 | } 64 | n=int(f); 65 | Serial.print(n);// 将接收到的数据打印到串口上 66 | analogWrite(ledpin,n); //将接收到的数据写入ledpin 接口,控制LED 亮度 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /materials/红外接收传感器模块/hongwaijieshou/hongwaijieshou.ino: -------------------------------------------------------------------------------- 1 | #define ADD 0x00 2 | int IR_S = 2; // 定义数字口2 为发射模块接口 3 | int a; 4 | void setup() 5 | { 6 | pinMode(IR_S, OUTPUT); //定义IR_S为输出模式 7 | Serial.begin(115200); //定义频率为115200 8 | } 9 | void loop() 10 | { 11 | uint8_t dat,temp; 12 | { 13 | a=analogRead(0); // 读取模拟口0 的值 14 | temp =a/4; 15 | Serial.println(temp,DEC ); // 将读取的数值打印到串口上 16 | IR_Send38KHZ(280,1);//发送9ms 的起始码 17 | IR_Send38KHZ(140,0);//发送4.5ms 的结果码 18 | 19 | IR_Sendcode(ADD);//用户识别码 20 | dat=~ADD; 21 | IR_Sendcode(dat);//用户识别码反吗 22 | IR_Sendcode(temp);// 操作码 23 | dat=~temp; 24 | IR_Sendcode(dat);//操作码反码 25 | IR_Send38KHZ(21,1);// 发送结束码 26 | } 27 | delay(200); 28 | } 29 | void IR_Send38KHZ(int x,int y) //产生38KHZ红外脉冲 30 | { 31 | for(int i=0;i>1; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /materials/红外接收传感器模块/红外接收传感器模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/红外接收传感器模块/红外接收传感器模块.doc -------------------------------------------------------------------------------- /materials/红色按键模块/hongseanj/hongseanj.ino: -------------------------------------------------------------------------------- 1 | const int buttonPin =2; // 定义大按钮模块链接引脚 2 | const int ledPin = 13; // 定义板载LED引脚 3 | 4 | int buttonState = 0; // 定义大按钮模块状态变量 5 | 6 | void setup() { 7 | // 初始化LED为输出模式 8 | pinMode(ledPin, OUTPUT); 9 | //初始化大按钮模块为输入模式 10 | pinMode(buttonPin, INPUT); 11 | } 12 | 13 | void loop(){ 14 | // 读取按键状态 15 | buttonState = digitalRead(buttonPin); 16 | 17 | // 检查按键是否被按下 18 | if (buttonState == LOW) { 19 | // 点亮LED 20 | digitalWrite(ledPin, HIGH); 21 | } 22 | else { 23 | //熄灭LED 24 | digitalWrite(ledPin, LOW); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /materials/红色按键模块/红色按键模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/红色按键模块/红色按键模块.doc -------------------------------------------------------------------------------- /materials/继电器模块/jidianqi/jidianqi.ino: -------------------------------------------------------------------------------- 1 | int ctl = 3;//定义引脚 2 | void setup() 3 | { 4 | pinMode(ctl,OUTPUT); 5 | } 6 | 7 | void loop() 8 | { 9 | digitalWrite(ctl,HIGH); 10 | delay(1000); 11 | digitalWrite(ctl,LOW); 12 | delay(1000); 13 | } 14 | -------------------------------------------------------------------------------- /materials/继电器模块/继电器模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/继电器模块/继电器模块.doc -------------------------------------------------------------------------------- /materials/触摸传感器模块/chumchuanganqi/chumchuanganqi.ino: -------------------------------------------------------------------------------- 1 | int ledPin = 13; // 设置指示灯为板载测试灯 2 | int KEY = 2; // 连接触摸传感器到数字接口2 3 | 4 | void setup() 5 | { 6 | pinMode(ledPin, OUTPUT); //设置连接到指示灯的管脚为输出模式 7 | pinMode(KEY, INPUT); //设置触摸传感器的连接管脚为输入模式 8 | } 9 | 10 | void loop() 11 | { 12 | if(digitalRead(KEY)==HIGH) //读取触摸传感器的状态值 13 | { 14 | digitalWrite(ledPin, HIGH); //如果获取电平为高,则打开灯 15 | } 16 | else 17 | { 18 | digitalWrite(ledPin, LOW); //如果获取电平为底,则关闭灯 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /materials/触摸传感器模块/触摸传感器模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/触摸传感器模块/触摸传感器模块.doc -------------------------------------------------------------------------------- /materials/超声波传感器模块/chaoshengbchuanganqidanxian/chaoshengbchuanganqi.ino: -------------------------------------------------------------------------------- 1 | int duration; //变量duration 用来存储脉冲时间 2 | int distance; //变量distance 用来存储距离 3 | int srfPin = 2; //定义srfPin 引脚为 2 4 | void setup() 5 | { 6 | Serial.begin(9600); 7 | } 8 | void loop() 9 | { 10 | pinMode(srfPin, OUTPUT); 11 | digitalWrite(srfPin, LOW); 12 | delayMicroseconds(2); 13 | digitalWrite(srfPin, HIGH); 14 | delayMicroseconds(10); 15 | digitalWrite(srfPin, LOW); 16 | pinMode(srfPin, INPUT); 17 | duration = pulseIn(srfPin, HIGH); 18 | distance = duration/58; // 将脉冲时间转化为距离(单位:厘米) 19 | Serial.println(distance); // 输出距离值 20 | delay(50); 21 | } 22 | -------------------------------------------------------------------------------- /materials/超声波传感器模块/chaoshengboshuangxian/chaoshengboshuangxian.ino: -------------------------------------------------------------------------------- 1 | int inputPin=4; // 定义超声波信号接收接口 2 | int outputPin=5; // 定义超声波信号发出接口 3 | int ledpin=13; // 定义ledPin 引脚为13 4 | void setup() 5 | { 6 | Serial.begin(9600); 7 | pinMode(ledpin,OUTPUT); 8 | pinMode(inputPin, INPUT); 9 | pinMode(outputPin, OUTPUT); 10 | } 11 | void loop() 12 | { 13 | digitalWrite(outputPin, LOW); //使发出发出超声波信号接口低电平2 μs 14 | delayMicroseconds(2); 15 | digitalWrite(outputPin, HIGH); 16 | //使发出发出超声波信号接口高电平10μs ,这里是至少10μs 17 | delayMicroseconds(10); 18 | digitalWrite(outputPin, LOW); // 保持发出超声波信号接口低电平 19 | int distance = pulseIn(inputPin, HIGH); // 读出脉冲时间 20 | distance= distance/58; // 将脉冲时间转化为距离(单位:厘米) 21 | Serial.println(distance); // 输出距离值 22 | delay(50); 23 | if (distance >=50) 24 | { //如果距离大于50厘米小灯亮起 25 | digitalWrite(ledpin,HIGH); 26 | } //如果距离小于50厘米小灯熄灭 27 | else 28 | digitalWrite(ledpin,LOW); 29 | } 30 | -------------------------------------------------------------------------------- /materials/陶瓷震动传感器模块/taocizhendong/taocizhendong.ino: -------------------------------------------------------------------------------- 1 | void setup() 2 | { 3 | Serial.begin(9600); //打开串口,设置串口波特率为9600bps 4 | } 5 | void loop() 6 | { 7 | int val; 8 | val=analogRead(0); //将模拟压电陶瓷震动传感器连接到模拟接口0 9 | Serial.print("Vibration is "); 10 | Serial.println(val,DEC);//通过串口打印读取到的模拟值 11 | delay(100); 12 | } 13 | -------------------------------------------------------------------------------- /materials/陶瓷震动传感器模块/陶瓷震动传感器模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/陶瓷震动传感器模块/陶瓷震动传感器模块.doc -------------------------------------------------------------------------------- /materials/震动传感器模块/zhendong/zhendong.ino: -------------------------------------------------------------------------------- 1 | int hzPin = 2; 2 | int ledPin = 13; 3 | int hzState = 0; 4 | void setup() { 5 | pinMode(ledPin, OUTPUT); 6 | pinMode(hzPin, INPUT); 7 | } 8 | 9 | void loop(){ 10 | hzState = digitalRead(hzPin); 11 | if (hzState == LOW) 12 | { 13 | digitalWrite(ledPin, HIGH); 14 | } 15 | else { 16 | digitalWrite(ledPin, LOW); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /materials/震动传感器模块/震动传感器模块.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/震动传感器模块/震动传感器模块.doc -------------------------------------------------------------------------------- /materials/霍尔传感器/huoer/huoer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 根据inputPin的高低电平,点亮或熄灭LED 3 | */ 4 | int ledPin = 13; // choose the pin for the LED 5 | int inputPin = 2; // Connect Hall sensor to Pin2 6 | int val = 0; // variable for reading the pin status 7 | void setup() { 8 | pinMode(ledPin, OUTPUT); // declare LED as output 9 | pinMode(inputPin, INPUT); // declare pushbutton as input 10 | } 11 | void loop(){ 12 | val = digitalRead(inputPin); // read input value 13 | if (val == HIGH) { // check if the input is HIGH 14 | digitalWrite(ledPin, LOW); // turn LED OFF 15 | } else { 16 | digitalWrite(ledPin, HIGH); // turn LED ON 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /materials/霍尔传感器/霍尔传感器.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/esperyong/learn-sensors/620b2eea1d729022b958ffa961ea48555f5a0722/materials/霍尔传感器/霍尔传感器.doc --------------------------------------------------------------------------------