-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
240 changed files
with
13,140 additions
and
3,754 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"restructuredtext.confPath": "${workspaceFolder}\\docs\\source" | ||
} |
42 changes: 42 additions & 0 deletions
42
code/Lesson_10_Flammable_Gas_Detection/Lesson_10_Flammable_Gas_Detection.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/****************************************************** | ||
* name:Flammable Gas Detection | ||
* function:ignite a lighter. Then the sensor detects the gas emitted. Thus, the LED on the gas sensor and that attached to pin 13 on the SunFounder Uno board will light up. Also you can see the value at A0 and D0 printed on Serial Monitor. | ||
* connection: | ||
* MQ-2 gas sensor Uno R3 | ||
* D0 7 | ||
* A0 A0 | ||
* GND GND | ||
* VCC 5V | ||
*******************************************************/ | ||
//Email:support@sunfounder.com | ||
//Website:www.sunfounder.com | ||
|
||
const int ledPin = 13;//the led attach to pin13 | ||
const int analogPin=A0; //the DO on the Module attach to Pin7 on the SunFounder | ||
const int digitalPin=7; //the D0 attach to pin7 | ||
int Astate=0; | ||
boolean Dstate=0; | ||
void setup() | ||
{ | ||
//set the pins state | ||
pinMode (digitalPin,INPUT); | ||
pinMode(ledPin,OUTPUT); | ||
Serial.begin(9600); | ||
} | ||
void loop() | ||
{ | ||
Astate=analogRead(analogPin);//read the value of A0 | ||
Serial.println(Astate); //peint | ||
Dstate=digitalRead(digitalPin);//read the value of D0 | ||
Serial.println(Dstate);//print | ||
if( Dstate==HIGH ) //if the value of D0 is HIGH | ||
{ | ||
digitalWrite(ledPin,LOW);//turn off led | ||
} | ||
if( Dstate==LOW)//else | ||
{ | ||
digitalWrite(ledPin,HIGH);//turn on the led | ||
} | ||
delay(200);//delay 200ms | ||
} | ||
|
64 changes: 64 additions & 0 deletions
64
code/Lesson_11_Humiture_Detection/Lesson_11_Humiture_Detection.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/***************************************************** | ||
* name:Humiture Detection | ||
* function:you can see the current value of humidity and temperature displayed on the I2C LCD1602. | ||
******************************************************/ | ||
//Email:support@sunfounder.com | ||
//Website:www.sunfounder.com | ||
|
||
//include the libraries | ||
#include <dht.h> | ||
#include <LiquidCrystal_I2C.h> | ||
#include <Wire.h> | ||
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display | ||
|
||
dht DHT;//create a variable type of dht | ||
|
||
const int DHT11_PIN= 7;//Humiture sensor attach to pin7 | ||
|
||
void setup() | ||
{ | ||
Serial.begin(9600);//initialize the serial | ||
lcd.init(); //initialize the lcd | ||
lcd.backlight(); //open the backlight | ||
} | ||
|
||
void loop() | ||
{ | ||
// READ DATA | ||
//Serial.println("DHT11:"); | ||
|
||
int chk = DHT.read11(DHT11_PIN);//read the value returned from sensor | ||
switch (chk) | ||
{ | ||
case DHTLIB_OK: | ||
//Serial.println("OK!"); | ||
break; | ||
case DHTLIB_ERROR_CHECKSUM: | ||
//Serial.print("Checksum error,\t"); | ||
break; | ||
case DHTLIB_ERROR_TIMEOUT: | ||
//Serial.print("Time out error,\t"); | ||
break; | ||
default: | ||
//Serial.print("Unknown error,\t"); | ||
break; | ||
} | ||
// DISPLAY DATA | ||
lcd.setCursor(0, 0); | ||
lcd.print("Tem:"); | ||
//Serial.print("Tem:"); | ||
lcd.print(DHT.temperature,1); //print the temperature on lcd | ||
// Serial.print(DHT.temperature,1); | ||
lcd.print(char(223));//print the unit" ℃ " | ||
lcd.print("C"); | ||
// Serial.println(" C"); | ||
lcd.setCursor(0, 1); | ||
lcd.print("Hum:"); | ||
//Serial.print("Hum:"); | ||
lcd.print(DHT.humidity,1); //print the humidity on lcd | ||
//Serial.print(DHT.humidity,1); | ||
lcd.print(" %"); | ||
//Serial.println(" %"); | ||
delay(200); //wait a while | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/********************************************* | ||
* name:Joystick PS2 | ||
* function:push the joystick and the coordinates of X and Y axes displayed on Serial Monitor will change accordingly; | ||
* press down the joystick, and the coordinate of Z=0 will also be displayed. | ||
connection: | ||
Joystick PS2 SunFounder Uno R3 | ||
GND GND | ||
VCC 5V | ||
Bt 7 | ||
x A0 | ||
y A1 | ||
***********************************************/ | ||
//Email: support@sunfounder.com | ||
//Website: www.sunfounder.com | ||
|
||
const int xPin = A0; //X attach to A0 | ||
const int yPin = A1; //Y attach to A1 | ||
const int btPin = 7; //Bt attach to digital 7 | ||
|
||
void setup() | ||
{ | ||
pinMode(btPin,INPUT); //set btpin as INPUT | ||
digitalWrite(btPin, HIGH); //and HIGH | ||
Serial.begin(9600); //initialize serial | ||
} | ||
|
||
void loop() | ||
{ | ||
Serial.print("X: ");//print "X: " | ||
Serial.print(analogRead(xPin),DEC); //read the value of A0 and print it in decimal | ||
Serial.print("\tY: "); //print "Y: " | ||
Serial.print(analogRead(yPin),DEC); //read the value of A1 and print it in decimal | ||
Serial.print("\tZ: "); //print "Z: " | ||
Serial.println(digitalRead(btPin)); ////read the value of pin7 and print it | ||
delay(100);//delay 100ms | ||
} | ||
|
27 changes: 27 additions & 0 deletions
27
code/Lesson_13_Controlling_an_LED_by_Button/Lesson_13_Controlling_an_LED_by_Button.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//Turns on and off a LED ,when pressings button attach to pin7 | ||
/**********************************/ | ||
const int keyPin = 7; //the number of the key pin | ||
const int ledPin = 13;//the number of the led pin | ||
/**********************************/ | ||
void setup() | ||
{ | ||
pinMode(keyPin,INPUT);//initialize the key pin as input | ||
pinMode(ledPin,OUTPUT);//initialize the led pin as output | ||
} | ||
/**********************************/ | ||
void loop() | ||
{ | ||
|
||
boolean Value=digitalRead(keyPin);//read the state of the key value | ||
//and check if the kye is pressed | ||
//if it is,the state is HIGH | ||
if(Value ==HIGH ) | ||
{ | ||
digitalWrite(ledPin,LOW);//turn on the led | ||
} | ||
else | ||
{ | ||
digitalWrite(ledPin,HIGH);//turn off the led | ||
} | ||
} | ||
/************************************/ |
40 changes: 40 additions & 0 deletions
40
code/Lesson_14_Mercury_Switch/Lesson_14_Mercury_Switch.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/************************************************************ | ||
* name:Mercury Switch | ||
* function:tilt the switch. | ||
* Then the indicators on the switch and the LED attached to pin 13 on the SunFounder Uno board will light up. | ||
**************************************************************/ | ||
// Email: support@sunfounder.com | ||
// website: www.sunfounder.com | ||
|
||
const int mercuryPin = 7; // the number of the Mercury Switch pin | ||
const int ledPin = 13; // the number of the LED pin | ||
|
||
// variables will change: | ||
int mercuryState = 0; // variable for reading the Mercury Switch status | ||
|
||
void setup() { | ||
// initialize the LED pin as an output: | ||
pinMode(ledPin, OUTPUT); | ||
// initialize the Mercury Switch pin as an input: | ||
pinMode(mercuryPin, INPUT); | ||
Serial.begin(9600); | ||
} | ||
|
||
void loop(){ | ||
// read the state of the Mercury Switch value: | ||
mercuryState = digitalRead(mercuryPin); | ||
//print the value on serial monitor | ||
Serial.print("Vaule: "); | ||
Serial.println(mercuryState); | ||
if (mercuryState == LOW) | ||
{ | ||
// turn LED on: | ||
digitalWrite(ledPin, HIGH); | ||
} | ||
else { | ||
// turn LED off: | ||
digitalWrite(ledPin, LOW); | ||
} | ||
delay(100);//delay | ||
} | ||
|
27 changes: 27 additions & 0 deletions
27
code/Lesson_14_Vibration_Switch/Lesson_14_Vibration_Switch.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const int vibswPin = 8; //the Vibration Switch attach to | ||
const int ledPin = 13; //the led attach to | ||
int val = 0; //initialize the variable val as 0 | ||
/******************************************/ | ||
void setup() | ||
{ | ||
pinMode(vibswPin,INPUT); //initialize vibration switch as an input | ||
pinMode(ledPin,OUTPUT); //initialize ledPin switch as an output | ||
//Serial.begin(9600); | ||
} | ||
/*******************************************/ | ||
void loop() | ||
{ | ||
val = digitalRead(vibswPin); //read the value from vibration switch | ||
//Serial.println(val); | ||
if(val == LOW) //without vibration signal | ||
{ | ||
digitalWrite(ledPin,HIGH); //turn off the led | ||
delay(500);//delay 500ms,The LED will be on for 500ms | ||
} | ||
else | ||
{ | ||
digitalWrite(ledPin,LOW); //turn on the led | ||
} | ||
} | ||
/*********************************************/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/*************************************************** | ||
name:Touch Switch | ||
function: | ||
************************************************/ | ||
//Email:support@sunfounder.com | ||
//Website:www.sunfounder.com | ||
|
||
|
||
const int SensorPin=7; //touch switch attach to pin7 | ||
const int ledPin = 13; //pin13 built-in led | ||
int SensorState=0; //store the value of touch switch | ||
const int ledPin = 1; | ||
void setup() | ||
{ | ||
pinMode(SensorPin,INPUT);//set sensorPin as INPUT | ||
pinMode(ledPin,OUTPUT); // set ledPin as OUTPUT | ||
Serial.begin(9600); //initialize the serial monitor | ||
|
||
} | ||
|
||
void loop() | ||
{ | ||
SensorState=digitalRead(SensorPin);//read the value of pin7 | ||
Serial.println( SensorState);//print it in serial monitor | ||
if(SensorState==HIGH) //if the value is HIGH | ||
{ | ||
digitalWrite(ledPin,LOW); //turn off the led | ||
} | ||
else | ||
{ | ||
digitalWrite(ledPin,HIGH); //turn on the led | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
code/Lesson_16_Photo-interrupter/Lesson_16_Photo-interrupter.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
/**********************************/ | ||
const int photoPin = 7; //the number of the key pin | ||
const int ledPin = 13;//the number of the led pin | ||
/**********************************/ | ||
void setup() | ||
{ | ||
pinMode(photoPin,INPUT); | ||
pinMode(ledPin,OUTPUT);//initialize the led pin as output | ||
} | ||
/**********************************/ | ||
void loop() | ||
{ | ||
|
||
boolean Value=digitalRead(photoPin); | ||
|
||
//if it is,the state is HIGH | ||
if(Value ==HIGH ) | ||
{ | ||
digitalWrite(ledPin,LOW);//turn on the led | ||
} | ||
else | ||
{ | ||
digitalWrite(ledPin,HIGH);//turn off the led | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/***************************************************** | ||
* name:Photoswitch | ||
* function: hold the photoresistor with your fingers and check the value at A0 on Serial Monitor. | ||
* You can see when the resistance is up to 400ohm, | ||
* the normally open contact of the relay is closed and the LED connected to pin 13 on the SunFounder Uno board lights up; | ||
* or else, it keeps out. | ||
************************************************/ | ||
//Email:support@sunfounder.com | ||
//website:www.sunfounder.com | ||
|
||
const int photocellPin = A0; //photoresistor module attach to A0 | ||
const int ledPin = 13; //pin 13 built-in led | ||
const int relayPin=8; //relay module attach to digital 8 | ||
int outputValue = 0; | ||
/*************************************************/ | ||
void setup() | ||
{ | ||
pinMode(relayPin,OUTPUT); //set relayPin as OUTPUT | ||
pinMode(ledPin,OUTPUT); //set ledPin as OUTPUT | ||
Serial.begin(9600); //initialize the serial communication as 9600bps | ||
} | ||
/*************************************************/ | ||
void loop() | ||
{ | ||
outputValue = analogRead(photocellPin);//read the value of photoresistor | ||
Serial.println(outputValue); //print it in serial monitor | ||
if(outputValue >= 400) //if the value of photoreisitor is greater than 400 | ||
{ | ||
digitalWrite(ledPin,HIGH); //turn on the led | ||
digitalWrite(relayPin,LOW); //relay connected | ||
} | ||
else //else | ||
{ | ||
digitalWrite(ledPin,LOW); //turn off the led | ||
digitalWrite(relayPin,HIGH); //and relay disconnected | ||
} | ||
delay(1000); //delay 1s | ||
} | ||
/*************************************************/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/***************************************************** | ||
* name:Reed Switch | ||
* function:use a magnet to approach the reed switch, and the LED on the reed switch module and that on the SunFounder board light up. Move the magnet farther and the LED will go out. | ||
**************************************************/ | ||
// Email: support@sunfounder.com | ||
// website: www.sunfounder.com | ||
|
||
const int digitalInPin = 7;// reed switch attach to pin7 | ||
const int ledPin = 13;// pin13 built-in led | ||
|
||
void setup() | ||
{ | ||
pinMode(digitalInPin,INPUT);// set digitalInPin as INPUT | ||
pinMode(ledPin,OUTPUT); // set ledPin as OUTPUT | ||
} | ||
|
||
void loop() | ||
{ | ||
boolean stat = digitalRead(digitalInPin);//read the value of pin7 to stat | ||
if(stat == HIGH)// if it it HIGH | ||
{ | ||
digitalWrite(ledPin,LOW);// then turn off the led | ||
} | ||
else //else | ||
{ | ||
digitalWrite(ledPin,HIGH); // turn on the led | ||
} | ||
} | ||
|
Oops, something went wrong.