11、傾斜傳感器
-
接線圖
接線圖 -
模塊
模塊程序 -
IDE
ide 源碼
int senPin=A5;;
int redpin=8;
int val=0;
void setup()
{
pinMode(redpin, OUTPUT); //set redled out
Serial.begin(9600); // set the serial
}
/******************************************************/
void loop()
{
val=analogRead(senPin); //read the value of senpin
Serial.println(val);
if(val){
digitalWrite(redpin,HIGH);
}else{
digitalWrite(redpin,LOW); //give the sensor high or low
}
}
/********************************************************/
-
實(shí)例效果
實(shí)例
12、火焰?zhèn)鞲衅?/h3>
-
接線
接線
-
IDE
IDE
源碼
int senPin=A5;;
int redpin=8;
int val=0;
void setup()
{
pinMode(redpin, OUTPUT); //set redled out
Serial.begin(9600); // set the serial
}
/******************************************************/
void loop()
{
val=analogRead(senPin); //read the value of senpin
Serial.println(val);
if(val>50){
digitalWrite(redpin,HIGH);
}else{
digitalWrite(redpin,LOW); //give the sensor high or low
}
}
/********************************************************/
-
模塊
模塊
實(shí)例 沒有打火機(jī) 下次補(bǔ)
13、聲音傳感器
-
接線圖
接線圖
-
模塊圖
模塊
-
IDE
IDE
int senPin=2;;
int redpin=8;
int val=0;
void setup()
{
pinMode(redpin, OUTPUT); //set redled out
pinMode(senPin, INPUT); //set pin input
}
/******************************************************/
void loop()
{
val = digitalRead(senPin);
if(val){
digitalWrite(redpin,HIGH);
delay(3000);
}else{
digitalWrite(redpin,LOW); //give the sensor high or low
}
}
/********************************************************/
-
實(shí)例
實(shí)例
14、薄模按鍵
-
連線
接線
接口 4-11
圖
- IDE
const int numRows=4;
const int numCols=4;//define row and column
const int debouceTime=20;//remove the debouce time
const char keymap[numRows][numCols]={
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};//key value
const int rowPins[numRows]={4,5,6,7};
const int colPins[numCols]={8,9,10,11};
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
for(int row=0;row<numRows;row++){
pinMode(rowPins[row],INPUT);
digitalWrite(rowPins[row],HIGH);
}
for(int column;column<numCols;column++){
pinMode(colPins[column],OUTPUT);
digitalWrite(colPins[column],HIGH);
} //define the reset
}
void loop() {
char key=getkey();
if(key!=0)
{
Serial.println(key);
}
}
char getkey(){
char key=0;
for(int column=0;column<numCols;column++){
digitalWrite(colPins[column],LOW);
for(int row=0;row<numRows;row++){
if(digitalRead(rowPins[row])==LOW){
delay(debouceTime);
while(digitalRead(rowPins[row])==LOW);
key=keymap[row][column];
}
}
digitalWrite(colPins[column],HIGH); //de-active the column
}
return key;
}
-
效果
效果
15、9G舵機(jī)實(shí)驗(yàn)
-
接線圖
接線
-
模塊
模塊
-
IDE
IDE
#include <Servo.h>
Servo myservo;
int pos=0;
void setup(){
myservo.attach(9);//control pin 9
}
void loop(){
for(pos=0;pos<180;pos+=1){
myservo.write(pos);
delay(15);//change the position
}
for(pos=180;pos>=1;pos-=1){
myservo.write(pos);
delay(15); //delay 15s
}
}
- 實(shí)例
實(shí)例
接線

接線
IDE

IDE
源碼
int senPin=A5;;
int redpin=8;
int val=0;
void setup()
{
pinMode(redpin, OUTPUT); //set redled out
Serial.begin(9600); // set the serial
}
/******************************************************/
void loop()
{
val=analogRead(senPin); //read the value of senpin
Serial.println(val);
if(val>50){
digitalWrite(redpin,HIGH);
}else{
digitalWrite(redpin,LOW); //give the sensor high or low
}
}
/********************************************************/
模塊

模塊
實(shí)例 沒有打火機(jī) 下次補(bǔ)
接線圖

接線圖
模塊圖

模塊
IDE

IDE
int senPin=2;;
int redpin=8;
int val=0;
void setup()
{
pinMode(redpin, OUTPUT); //set redled out
pinMode(senPin, INPUT); //set pin input
}
/******************************************************/
void loop()
{
val = digitalRead(senPin);
if(val){
digitalWrite(redpin,HIGH);
delay(3000);
}else{
digitalWrite(redpin,LOW); //give the sensor high or low
}
}
/********************************************************/
實(shí)例

實(shí)例
連線

接線
接口 4-11

圖
const int numRows=4;
const int numCols=4;//define row and column
const int debouceTime=20;//remove the debouce time
const char keymap[numRows][numCols]={
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};//key value
const int rowPins[numRows]={4,5,6,7};
const int colPins[numCols]={8,9,10,11};
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
for(int row=0;row<numRows;row++){
pinMode(rowPins[row],INPUT);
digitalWrite(rowPins[row],HIGH);
}
for(int column;column<numCols;column++){
pinMode(colPins[column],OUTPUT);
digitalWrite(colPins[column],HIGH);
} //define the reset
}
void loop() {
char key=getkey();
if(key!=0)
{
Serial.println(key);
}
}
char getkey(){
char key=0;
for(int column=0;column<numCols;column++){
digitalWrite(colPins[column],LOW);
for(int row=0;row<numRows;row++){
if(digitalRead(rowPins[row])==LOW){
delay(debouceTime);
while(digitalRead(rowPins[row])==LOW);
key=keymap[row][column];
}
}
digitalWrite(colPins[column],HIGH); //de-active the column
}
return key;
}
效果

效果
接線圖

接線
模塊

模塊
IDE

IDE
#include <Servo.h>
Servo myservo;
int pos=0;
void setup(){
myservo.attach(9);//control pin 9
}
void loop(){
for(pos=0;pos<180;pos+=1){
myservo.write(pos);
delay(15);//change the position
}
for(pos=180;pos>=1;pos-=1){
myservo.write(pos);
delay(15); //delay 15s
}
}

實(shí)例



