├── .gitignore
├── 1010_-_asbsgs_array_ex1
└── 1010_-_asbsgs_array_ex1.ino
├── 1020_-_asbsgs_array_ex2
└── 1020_-_asbsgs_array_ex2.ino
├── 1030_-_asbsgs_array_ex3
└── 1030_-_asbsgs_array_ex3.ino
├── 1040_-_asbsgs_array_ex4
└── 1040_-_asbsgs_array_ex4.ino
├── LICENSE
├── Schematics
├── 0400 - Photoresistor
│ ├── 0400 - Photoresistor partial.png
│ └── 0400 - Photoresistor.png
├── 0410 - UV Light Sensor
│ └── 0410 - UV Light Sensor.png
├── 0420 - RGB light sensor TC34725
│ ├── 0420 - TCS34725 4.pdf
│ ├── 0420 - TCS34725 with RGB LED.jpg
│ ├── 0420 - TCS34725 with RGB LED.png
│ ├── 0420 - TCS34725 with RGB LED_old.png
│ └── ASBS17 - 0440 - Thermistor notes.png
├── 0430 - DHT22
│ └── 0430 - DHT22.png
├── 0440 - Thermistor
│ ├── 0440 - Thermistor 3V3.png
│ └── 0440 - Thermistor 5V.png
├── 0450 - TMP36 Temperature sensor
│ ├── 0450 - TMP36 Temperature sensor 3V3.png
│ └── 0450 - TMP36 Temperature sensor 5V.png
├── 0460 - Temperature with the MCP9808
│ └── 0460 - Temperature MCP9808.png
├── 0470 - BMP085 environment sensor
│ └── 0470 - BMP085 environment sensor.png
├── 0480 - BMP180 environment sensor
│ └── 0480 - BMP180 environment sensor.png
├── 0500 - Infrared motion sensor
│ ├── 0500 - Infrared sensor with Arduino.png
│ ├── 0500 - Infrared sensor.png
│ ├── DSC_0025.JPG
│ ├── DSC_0026.JPG
│ ├── DSC_0027.JPG
│ ├── DSC_0028.JPG
│ ├── IMG_4367 800.JPG
│ ├── IMG_4367.JPG
│ ├── L10 - Notes.pages
│ │ ├── Data
│ │ │ ├── pasted-image-24.tif
│ │ │ ├── pasted-image-26.tif
│ │ │ ├── pasted-image-28.tif
│ │ │ ├── pasted-image-30.tif
│ │ │ ├── pasted-image-34.tif
│ │ │ ├── pasted-image-small-25.png
│ │ │ ├── pasted-image-small-27.png
│ │ │ ├── pasted-image-small-29.png
│ │ │ ├── pasted-image-small-31.png
│ │ │ └── pasted-image-small-35.png
│ │ ├── Index.zip
│ │ ├── Metadata
│ │ │ ├── BuildVersionHistory.plist
│ │ │ ├── DocumentIdentifier
│ │ │ └── Properties.plist
│ │ ├── preview-micro.jpg
│ │ ├── preview-web.jpg
│ │ └── preview.jpg
│ ├── PIRExplainerPhoto.JPG
│ ├── pir-passive-infrared-proximity-motion-sensor.pdf
│ └── pir_motion_sensor_hcsr501_2.jpg
├── 0510 - Ultrasonic distance sensor
│ └── 0510 - Ultrasonic Sensor HC-SR04.png
├── 0520 - ADXL335 accelerometer
│ ├── 0520 - ADXL335 accelerometer 1.png
│ └── 0520 - ADXL335 accelerometer 2.png
├── 0560 - Analog and digital microphone
│ ├── 0560 - Analog microphone.png
│ └── 0560 - Digital sound sensor.png
├── 0700 - LCD screen parallel
│ ├── 0700 - LCD character screen DHT22.png
│ ├── 0700 - LCD character screen DHT22_bb.png
│ ├── 0700 LCD fz.pdf
│ ├── 0700 LCD fz.png
│ ├── 0700 LCD with sensor.png
│ ├── 0700 LCD.png
│ ├── L24 - Fritzing simple.fzz
│ └── L24 - LCD character screen DHT22.fzz
├── Arduino Uno Fritzing
│ └── Arduino Uno.key
└── ArduinoUnoFRITZING.png
├── _0300_-_RGB_blink
└── _0300_-_RGB_blink.ino
├── _0300_-_RGB_combine
└── _0300_-_RGB_combine.ino
├── _0400_-_Photoresistor_-_1
└── _0400_-_Photoresistor_-_1.ino
├── _0410_-_UV_Sensor_-_1
└── _0410_-_UV_Sensor_-_1.ino
├── _0420_-_RGB_light_sensor_-_1
└── _0420_-_RGB_light_sensor_-_1.ino
├── _0420_-_RGB_light_sensor_-_2
└── _0420_-_RGB_light_sensor_-_2.ino
├── _0430_-_DHT22
└── _0430_-_DHT22.ino
├── _0440_-_Termistor
└── _0440_-_Termistor.ino
├── _0440_-_Thermistor_with_library
└── _0440_-_Thermistor_with_library.ino
├── _0450_-_TMP36_temperature_sensor
└── _0450_-_TMP36_temperature_sensor.ino
├── _0460_-_Temperature_MCP9808
└── _0460_-_Temperature_MCP9808.ino
├── _0480_-BMP180_-_2
└── _0480_-BMP180_-_2.ino
├── _0480_-_BMP180_-_1
└── _0480_-_BMP180_-_1.ino
├── _0490_-_Environment_sensor_BME280
└── _0490_-_Environment_sensor_BME280.ino
├── _0500_-_Infrared_Sensor_1
└── _0500_-_Infrared_Sensor_1.ino
├── _0500_-_Infrared_Sensor_2
└── _0500_-_Infrared_Sensor_2.ino
├── _0510_-_Ultrasonic_Distance_Sensor
└── _0510_-_Ultrasonic_Distance_Sensor.ino
├── _0520_-_Acceleration_ADXL335_-_1
└── _0520_-_Acceleration_ADXL335_-_1.ino
├── _0520_-_Acceleration_ADXL335_-_2
└── _0520_-_Acceleration_ADXL335_-_2.ino
├── _0520_-_Acceleration_ADXL335_-_3
└── _0520_-_Acceleration_ADXL335_-_3.ino
├── _0560_-_Analog_microphone
└── _0560_-_Analog_microphone.ino
├── _0560_-_Digital_sound_sensor
└── _0560_-_Digital_sound_sensor.ino
├── _0570_-_Hall_Effect_sensor
└── _0570_-_Hall_Effect_sensor.ino
├── _0580_-_Reed_Switch
└── _0580_-_Reed_Switch.ino
├── _0590_-_Magnetometer_Compass_HMC5883
└── _0590_-_Magnetometer_Compass_HMC5883.ino
├── _0650_-_PassiveBuzzerSimple
└── _0650_-_PassiveBuzzerSimple.ino
├── _0650_-_ToneMelodyBuzzer
├── _0650_-_ToneMelodyBuzzer.ino
└── pitches.h
├── _0700a_-_LCD_display
└── _0700a_-_LCD_display.ino
├── _0700b_-_LCD_display_with_DHT_sensor
└── _0700b_-_LCD_display_with_DHT_sensor.ino
├── _0710_-_LCD_I2C
└── _0710_-_LCD_I2C.ino
├── _0720_-_Adafruit_LCD_shield
└── _0720_-_Adafruit_LCD_shield.ino
└── i2c_scanner
└── i2c_scanner.ino
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .AppleDouble
3 | .LSOverride
4 |
5 | # Icon must end with two \r
6 | Icon
7 |
8 |
9 | # Thumbnails
10 | ._*
11 |
12 | # Files that might appear on external disk
13 | .Spotlight-V100
14 | .Trashes
15 |
16 | # Directories potentially created on remote AFP share
17 | .AppleDB
18 | .AppleDesktop
19 | Network Trash Folder
20 | Temporary Items
21 | .apdisk
22 |
23 | # Compiled Object files
24 | *.slo
25 | *.lo
26 | *.o
27 | *.obj
28 |
29 | # Precompiled Headers
30 | *.gch
31 | *.pch
32 |
33 | # Compiled Dynamic libraries
34 | *.so
35 | *.dylib
36 | *.dll
37 |
38 | # Fortran module files
39 | *.mod
40 | *.smod
41 |
42 | # Compiled Static libraries
43 | *.lai
44 | *.la
45 | *.a
46 | *.lib
47 |
48 | # Executables
49 | *.exe
50 | *.out
51 | *.app
52 |
--------------------------------------------------------------------------------
/1010_-_asbsgs_array_ex1/1010_-_asbsgs_array_ex1.ino:
--------------------------------------------------------------------------------
1 | /*
2 | * An example of how to create an use an array of integers
3 | * We'll declare an array of 5 integers.
4 | * We'll print the contents in the serial monitor.
5 | * We'll do some calculations, store the results, and print the results in the serial monitor.
6 | *
7 | */
8 |
9 | int my_integers[5] = {1, 2, 3, 4, 5} ; // We want this array to contain 5 integers,
10 | // so we'll declare it with size 5.
11 |
12 | void setup() {
13 | Serial.begin(9600);
14 |
15 | while (!Serial) {
16 | ; // wait for serial port to connect. Needed for native USB
17 | }
18 |
19 | Serial.println("Your array numbers:");
20 | for (int i = 0; i<5; i++) // Experiment to see what happens if your index goes out of bounds
21 | {
22 | Serial.print("Index ");
23 | Serial.print(i);
24 | Serial.print(" contains value ");
25 | Serial.println(my_integers[i]);
26 | }
27 |
28 | Serial.println();
29 | Serial.println("Let's do some calculations:");
30 | for (int i = 0; i<4; i++)
31 | {
32 | Serial.print(my_integers[i]);
33 | Serial.print(" + ");
34 | Serial.print(my_integers[i+1]);
35 | Serial.print(" = ");
36 | Serial.println(my_integers[i] + my_integers[i+1]);
37 | }
38 |
39 | Serial.println();
40 | Serial.println("Let's do some calculations, and store the results:");
41 | for (int i = 0; i<4; i++)
42 | {
43 | Serial.print(my_integers[i]);
44 | Serial.print(" + ");
45 | Serial.print(my_integers[i+1]);
46 | Serial.print(" = ");
47 | int sum = my_integers[i] + my_integers[i+1];
48 | my_integers[i] = sum;
49 | Serial.print(my_integers[i]);
50 | Serial.print(" -> Index ");
51 | Serial.print(i);
52 | Serial.print(" now contains value ");
53 | Serial.println(my_integers[i]);
54 | }
55 | }
56 |
57 | void loop() {
58 | // put your main code here, to run repeatedly:
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/1020_-_asbsgs_array_ex2/1020_-_asbsgs_array_ex2.ino:
--------------------------------------------------------------------------------
1 | /*
2 | * An example of how to create an use an array of chars
3 | * We'll declare an array of 5 chars.
4 | * We'll print the contents in the serial monitor.
5 | *
6 | * The table of ASCII character from https://en.wikipedia.org/wiki/ASCII
7 | * is useful.
8 | *
9 | */
10 |
11 | //char my_char[5] = {'a', 'b', 'c', 'd', 'e'} ; // We want this array to contain 5 char,
12 | // so we'll declare it with size 5.
13 | // Try the exact same experiment with byte
14 |
15 | //char my_char[5] = "abcde"; // Alternative definition 1
16 |
17 | //String my_char = "abcde"; // Alternative definition 2, using a String
18 |
19 | void setup() {
20 | Serial.begin(9600);
21 |
22 | while (!Serial) {
23 | ; // wait for serial port to connect. Needed for native USB
24 | }
25 |
26 | Serial.println("Your array char:");
27 | for (int i = 0; i<5; i++) // Experiment to see what happens if your index goes out of bounds
28 | {
29 | Serial.print("Index ");
30 | Serial.print(i);
31 | Serial.print(" contains char '");
32 | Serial.print(my_char[i]);
33 | Serial.print("', ASCII decimal ");
34 | Serial.println(my_char[i], DEC);
35 | }
36 |
37 | Serial.println();
38 | Serial.println("Let's do some calculations:");
39 | for (int i = 0; i<4; i++)
40 | {
41 | Serial.print(my_char[i]);
42 | Serial.print(" + ");
43 | Serial.print(my_char[i+1]);
44 | Serial.print(" = ");
45 | Serial.println(my_char[i] + my_char[i+1]);
46 | }
47 |
48 | Serial.println();
49 | Serial.println("Let's do some calculations, and store the results:");
50 | for (int i = 0; i<4; i++)
51 | {
52 | Serial.print(my_char[i]);
53 | Serial.print(" + ");
54 | Serial.print(my_char[i+1]);
55 | Serial.print(" = ");
56 | char sum = my_char[i] + my_char[i+1]; // Beware, I am using a char here, which is
57 | // a single byte. This means that if this
58 | // calculation yields more than 256, it will
59 | // truncate without an error.
60 | my_char[i] = sum;
61 | Serial.print(my_char[i], DEC);
62 | Serial.print(" -> Index ");
63 | Serial.print(i);
64 | Serial.print(" now contains value ");
65 | Serial.println(my_char[i], DEC);
66 | }
67 | }
68 |
69 | void loop() {
70 | // put your main code here, to run repeatedly:
71 | }
72 |
--------------------------------------------------------------------------------
/1030_-_asbsgs_array_ex3/1030_-_asbsgs_array_ex3.ino:
--------------------------------------------------------------------------------
1 | /*
2 | * Control an LED using an array.
3 | *
4 | * Create a pattern with LED on and off information in one array,
5 | * and on/off durations in a second array.
6 | *
7 | *
8 | */
9 |
10 | const int ledPin = 7;
11 | const int totalStates = 9;
12 | int ledState[totalStates] = {1, 0, 1, 0, 1, 0, 0, 1, 0};
13 | int ledDuration[totalStates] = {200,400,500,100,200,50, 50, 500, 500 };
14 |
15 | void setup() {
16 | pinMode(ledPin, OUTPUT);
17 | }
18 |
19 | void loop() {
20 | for (int i = 0; i < totalStates; i++)
21 | {
22 | digitalWrite(ledPin,ledState[i]);
23 | delay(ledDuration[i]);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/1040_-_asbsgs_array_ex4/1040_-_asbsgs_array_ex4.ino:
--------------------------------------------------------------------------------
1 | /*
2 | * Control an LED using an array, like in example 3, but the
3 | * pattern is configurable.
4 | *
5 | * Create a pattern with LED on and off information in one array,
6 | * and on/off durations in a second array.
7 | *
8 | *
9 | */
10 |
11 | const int ledPin = 7;
12 | const int totalStates = 9;
13 | int ledState[totalStates]; // undefined, we'll ask the user for input
14 | int ledDuration[totalStates] = {200,400,500,100,200,50, 50, 500, 500 };
15 |
16 | void setup() {
17 | pinMode(ledPin, OUTPUT);
18 | Serial.begin(9600);
19 | while (!Serial) {
20 | ; // wait for serial port to connect. Needed for native USB
21 | }
22 |
23 | for (int i = 0; i < totalStates; i++)
24 | {
25 | Serial.print("Please type 1 or 0 for pattern step ");
26 | Serial.print(i);
27 | Serial.print(" out of ");
28 | Serial.print(totalStates - 1);
29 | Serial.print(" (default is 1): ");
30 |
31 | while (Serial.available()==0)
32 | {
33 | }
34 |
35 | char userInput = Serial.read();
36 | if (userInput == '1')
37 | ledState[i] = 1;
38 | else if (userInput == '0')
39 | ledState[i] = 0;
40 | else
41 | ledState[i] = 1;
42 |
43 | Serial.println(ledState[i]);
44 | }
45 | Serial.println("Thank you, now let's blink this LED using this pattern:");
46 | for (int i = 0; i < totalStates; i++)
47 | {
48 | Serial.print("Step ");
49 | Serial.print(i);
50 | Serial.print(" state is: ");
51 | Serial.print(ledState[i]);
52 | Serial.print(" with duration ");
53 | Serial.println(ledDuration[i]);
54 | }
55 | }
56 |
57 | void loop() {
58 | for (int i = 0; i < totalStates; i++)
59 | {
60 | digitalWrite(ledPin,ledState[i]);
61 | delay(ledDuration[i]);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 Peter Dalmaris
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Schematics/0400 - Photoresistor/0400 - Photoresistor partial.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0400 - Photoresistor/0400 - Photoresistor partial.png
--------------------------------------------------------------------------------
/Schematics/0400 - Photoresistor/0400 - Photoresistor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0400 - Photoresistor/0400 - Photoresistor.png
--------------------------------------------------------------------------------
/Schematics/0410 - UV Light Sensor/0410 - UV Light Sensor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0410 - UV Light Sensor/0410 - UV Light Sensor.png
--------------------------------------------------------------------------------
/Schematics/0420 - RGB light sensor TC34725/0420 - TCS34725 4.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0420 - RGB light sensor TC34725/0420 - TCS34725 4.pdf
--------------------------------------------------------------------------------
/Schematics/0420 - RGB light sensor TC34725/0420 - TCS34725 with RGB LED.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0420 - RGB light sensor TC34725/0420 - TCS34725 with RGB LED.jpg
--------------------------------------------------------------------------------
/Schematics/0420 - RGB light sensor TC34725/0420 - TCS34725 with RGB LED.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0420 - RGB light sensor TC34725/0420 - TCS34725 with RGB LED.png
--------------------------------------------------------------------------------
/Schematics/0420 - RGB light sensor TC34725/0420 - TCS34725 with RGB LED_old.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0420 - RGB light sensor TC34725/0420 - TCS34725 with RGB LED_old.png
--------------------------------------------------------------------------------
/Schematics/0420 - RGB light sensor TC34725/ASBS17 - 0440 - Thermistor notes.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0420 - RGB light sensor TC34725/ASBS17 - 0440 - Thermistor notes.png
--------------------------------------------------------------------------------
/Schematics/0430 - DHT22/0430 - DHT22.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0430 - DHT22/0430 - DHT22.png
--------------------------------------------------------------------------------
/Schematics/0440 - Thermistor/0440 - Thermistor 3V3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0440 - Thermistor/0440 - Thermistor 3V3.png
--------------------------------------------------------------------------------
/Schematics/0440 - Thermistor/0440 - Thermistor 5V.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0440 - Thermistor/0440 - Thermistor 5V.png
--------------------------------------------------------------------------------
/Schematics/0450 - TMP36 Temperature sensor/0450 - TMP36 Temperature sensor 3V3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0450 - TMP36 Temperature sensor/0450 - TMP36 Temperature sensor 3V3.png
--------------------------------------------------------------------------------
/Schematics/0450 - TMP36 Temperature sensor/0450 - TMP36 Temperature sensor 5V.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0450 - TMP36 Temperature sensor/0450 - TMP36 Temperature sensor 5V.png
--------------------------------------------------------------------------------
/Schematics/0460 - Temperature with the MCP9808/0460 - Temperature MCP9808.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0460 - Temperature with the MCP9808/0460 - Temperature MCP9808.png
--------------------------------------------------------------------------------
/Schematics/0470 - BMP085 environment sensor/0470 - BMP085 environment sensor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0470 - BMP085 environment sensor/0470 - BMP085 environment sensor.png
--------------------------------------------------------------------------------
/Schematics/0480 - BMP180 environment sensor/0480 - BMP180 environment sensor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0480 - BMP180 environment sensor/0480 - BMP180 environment sensor.png
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/0500 - Infrared sensor with Arduino.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0500 - Infrared motion sensor/0500 - Infrared sensor with Arduino.png
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/0500 - Infrared sensor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0500 - Infrared motion sensor/0500 - Infrared sensor.png
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/DSC_0025.JPG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0500 - Infrared motion sensor/DSC_0025.JPG
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/DSC_0026.JPG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0500 - Infrared motion sensor/DSC_0026.JPG
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/DSC_0027.JPG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0500 - Infrared motion sensor/DSC_0027.JPG
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/DSC_0028.JPG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0500 - Infrared motion sensor/DSC_0028.JPG
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/IMG_4367 800.JPG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0500 - Infrared motion sensor/IMG_4367 800.JPG
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/IMG_4367.JPG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0500 - Infrared motion sensor/IMG_4367.JPG
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/Data/pasted-image-24.tif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/Data/pasted-image-24.tif
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/Data/pasted-image-26.tif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/Data/pasted-image-26.tif
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/Data/pasted-image-28.tif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/Data/pasted-image-28.tif
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/Data/pasted-image-30.tif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/Data/pasted-image-30.tif
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/Data/pasted-image-34.tif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/Data/pasted-image-34.tif
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/Data/pasted-image-small-25.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/Data/pasted-image-small-25.png
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/Data/pasted-image-small-27.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/Data/pasted-image-small-27.png
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/Data/pasted-image-small-29.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/Data/pasted-image-small-29.png
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/Data/pasted-image-small-31.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/Data/pasted-image-small-31.png
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/Data/pasted-image-small-35.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/Data/pasted-image-small-35.png
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/Index.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/Index.zip
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/Metadata/BuildVersionHistory.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Template: 01_Modern_Report (2013-09-27 16:56)
6 | M5.0-1465-1
7 | M5.2-1860-1
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/Metadata/DocumentIdentifier:
--------------------------------------------------------------------------------
1 | AEEA068C-1117-4CCF-91F8-7534149918C0
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/Metadata/Properties.plist:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/Metadata/Properties.plist
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/preview-micro.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/preview-micro.jpg
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/preview-web.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/preview-web.jpg
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/preview.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0500 - Infrared motion sensor/L10 - Notes.pages/preview.jpg
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/PIRExplainerPhoto.JPG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0500 - Infrared motion sensor/PIRExplainerPhoto.JPG
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/pir-passive-infrared-proximity-motion-sensor.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0500 - Infrared motion sensor/pir-passive-infrared-proximity-motion-sensor.pdf
--------------------------------------------------------------------------------
/Schematics/0500 - Infrared motion sensor/pir_motion_sensor_hcsr501_2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0500 - Infrared motion sensor/pir_motion_sensor_hcsr501_2.jpg
--------------------------------------------------------------------------------
/Schematics/0510 - Ultrasonic distance sensor/0510 - Ultrasonic Sensor HC-SR04.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0510 - Ultrasonic distance sensor/0510 - Ultrasonic Sensor HC-SR04.png
--------------------------------------------------------------------------------
/Schematics/0520 - ADXL335 accelerometer/0520 - ADXL335 accelerometer 1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0520 - ADXL335 accelerometer/0520 - ADXL335 accelerometer 1.png
--------------------------------------------------------------------------------
/Schematics/0520 - ADXL335 accelerometer/0520 - ADXL335 accelerometer 2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0520 - ADXL335 accelerometer/0520 - ADXL335 accelerometer 2.png
--------------------------------------------------------------------------------
/Schematics/0560 - Analog and digital microphone/0560 - Analog microphone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0560 - Analog and digital microphone/0560 - Analog microphone.png
--------------------------------------------------------------------------------
/Schematics/0560 - Analog and digital microphone/0560 - Digital sound sensor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0560 - Analog and digital microphone/0560 - Digital sound sensor.png
--------------------------------------------------------------------------------
/Schematics/0700 - LCD screen parallel/0700 - LCD character screen DHT22.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0700 - LCD screen parallel/0700 - LCD character screen DHT22.png
--------------------------------------------------------------------------------
/Schematics/0700 - LCD screen parallel/0700 - LCD character screen DHT22_bb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0700 - LCD screen parallel/0700 - LCD character screen DHT22_bb.png
--------------------------------------------------------------------------------
/Schematics/0700 - LCD screen parallel/0700 LCD fz.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0700 - LCD screen parallel/0700 LCD fz.pdf
--------------------------------------------------------------------------------
/Schematics/0700 - LCD screen parallel/0700 LCD fz.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0700 - LCD screen parallel/0700 LCD fz.png
--------------------------------------------------------------------------------
/Schematics/0700 - LCD screen parallel/0700 LCD with sensor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0700 - LCD screen parallel/0700 LCD with sensor.png
--------------------------------------------------------------------------------
/Schematics/0700 - LCD screen parallel/0700 LCD.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0700 - LCD screen parallel/0700 LCD.png
--------------------------------------------------------------------------------
/Schematics/0700 - LCD screen parallel/L24 - Fritzing simple.fzz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0700 - LCD screen parallel/L24 - Fritzing simple.fzz
--------------------------------------------------------------------------------
/Schematics/0700 - LCD screen parallel/L24 - LCD character screen DHT22.fzz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/0700 - LCD screen parallel/L24 - LCD character screen DHT22.fzz
--------------------------------------------------------------------------------
/Schematics/Arduino Uno Fritzing/Arduino Uno.key:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/Arduino Uno Fritzing/Arduino Uno.key
--------------------------------------------------------------------------------
/Schematics/ArduinoUnoFRITZING.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/futureshocked/ArduinoSbSGettingStarted/544e73ee1d35b68b6866dd4d9086a19e978376ef/Schematics/ArduinoUnoFRITZING.png
--------------------------------------------------------------------------------
/_0300_-_RGB_blink/_0300_-_RGB_blink.ino:
--------------------------------------------------------------------------------
1 | /*
2 | Blink
3 | Turns on an LED on for one second, then off for one second, repeatedly.
4 |
5 | Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
6 | it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN takes care
7 | of use the correct LED pin whatever is the board used.
8 | If you want to know what pin the on-board LED is connected to on your Arduino model, check
9 | the Technical Specs of your board at https://www.arduino.cc/en/Main/Products
10 |
11 | This example code is in the public domain.
12 |
13 | modified 8 May 2014
14 | by Scott Fitzgerald
15 |
16 | modified 2 Sep 2016
17 | by Arturo Guadalupi
18 | */
19 |
20 | //const int red_pin = 3;
21 |
22 | #define RED_PIN 3
23 | #define BLUE_PIN 6
24 | #define GREEN_PIN 5
25 |
26 | // the setup function runs once when you press reset or power the board
27 | void setup() {
28 | // initialize digital pin LED_BUILTIN as an output.
29 | pinMode(RED_PIN, OUTPUT);
30 | pinMode(BLUE_PIN, OUTPUT);
31 | pinMode(GREEN_PIN, OUTPUT);
32 | }
33 |
34 | // the loop function runs over and over again forever
35 | void loop() {
36 | digitalWrite(GREEN_PIN, LOW);
37 | digitalWrite(RED_PIN, HIGH); // turn the LED on (HIGH is the voltage level)
38 | delay(1000); // wait for a second
39 | digitalWrite(RED_PIN, LOW); // turn the LED off by making the voltage LOW
40 | digitalWrite(BLUE_PIN, HIGH);
41 | delay(1000); // wait for a second
42 | digitalWrite(BLUE_PIN, LOW); // turn the LED off by making the voltage LOW
43 | digitalWrite(GREEN_PIN, HIGH);
44 | delay(1000);
45 | }
46 |
--------------------------------------------------------------------------------
/_0300_-_RGB_combine/_0300_-_RGB_combine.ino:
--------------------------------------------------------------------------------
1 | #define RED_PIN 3
2 | #define BLUE_PIN 6
3 | #define GREEN_PIN 5
4 |
5 | // the setup function runs once when you press reset or power the board
6 | void setup() {
7 | // initialize digital pin LED_BUILTIN as an output.
8 | pinMode(RED_PIN, OUTPUT);
9 | pinMode(BLUE_PIN, OUTPUT);
10 | pinMode(GREEN_PIN, OUTPUT);
11 | }
12 |
13 | // the loop function runs over and over again forever
14 | void loop() {
15 | analogWrite(GREEN_PIN, 50);
16 | analogWrite(RED_PIN, 100);
17 | analogWrite(BLUE_PIN, 100);
18 | // digitalWrite(GREEN_PIN, HIGH);
19 | // digitalWrite(RED_PIN, HIGH);
20 | // digitalWrite(BLUE_PIN, HIGH);
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/_0400_-_Photoresistor_-_1/_0400_-_Photoresistor_-_1.ino:
--------------------------------------------------------------------------------
1 | /* Photo-light sensor demo sketch
2 | *
3 | * This sketch gets an analog reading from a photosensor.
4 | * A photosensor is a light-dependant resistor (LDR).
5 | * The reading is proportional to the ambient light.
6 | *
7 | * This sketch was written for Arduino Step by Step by Peter Dalmaris.
8 | *
9 | * Components
10 | * ----------
11 | * - Arduino Uno
12 | * - Light sensor
13 | * - 10 kΩ resistor (or close)
14 | *
15 | * Libraries
16 | * ---------
17 | * - NONE
18 | *
19 | * Connections
20 | * -----------
21 | *
22 | * Connect the Arduino 5V pin to one end of the
23 | * LDR. Connect the resistor to the Arduino GND
24 | * pin. Connect the free pins on the LDR and
25 | * resistor together. Connect the LDR and resistor
26 | * junction to the Arduino analog pin 0. This
27 | * structure is called a "voltage divider".
28 | * 10 kΩ
29 | * 5V -----OOO------\/\/\/-----GND
30 | * |
31 | * |
32 | * |
33 | * A0
34 | *
35 | *
36 | * Other information
37 | * -----------------
38 | * For information on the photoresistors: https://en.wikipedia.org/wiki/Photoresistor
39 | * For information on the voltage divider: https://en.wikipedia.org/wiki/Voltage_divider
40 | * For a voltage divider calculator go to: http://txplo.re/2e65gSX
41 | *
42 | * Created on October 8 2016 by Peter Dalmaris
43 | *
44 | */
45 |
46 | // the setup routine runs once when you press reset:
47 | void setup() {
48 | // initialize serial communication at 9600 bits per second:
49 | Serial.begin(9600);
50 | }
51 |
52 | // the loop routine runs over and over again forever:
53 | void loop() {
54 | // read the input on analog pin 0:
55 | int sensorValue = analogRead(A0);
56 | // print out the value you read:
57 | Serial.println(sensorValue);
58 | delay(10);
59 | }
60 |
--------------------------------------------------------------------------------
/_0410_-_UV_Sensor_-_1/_0410_-_UV_Sensor_-_1.ino:
--------------------------------------------------------------------------------
1 | /* UV sensor demonstration sketch
2 | *
3 | * This sketch reads the state of the Adafruit analog UV sensor.
4 | * It then converst the analog reading to a voltage, and then
5 | * the voltage to an actual UV index value.
6 | *
7 | * This sketch was written for Arduino Step by Step by Peter Dalmaris.
8 | *
9 | * Components
10 | * ----------
11 | * - Arduino Uno
12 | * - Adafruit UV sensor breakout or equivelant
13 | *
14 | * Libraries
15 | * ---------
16 | * NONE
17 | *
18 | * Connections
19 | * -----------
20 | * Break out | Arduino Uno
21 | * -----------------------------
22 | * + | 5V
23 | * - | GND
24 | * Out | A0
25 | *
26 | *
27 | * Other information
28 | * -----------------
29 | * This sensor can detect UV light at 240-370nm.
30 | * This contains UVA and most of UVB.
31 | * For more information on UV light see https://en.wikipedia.org/wiki/Ultraviolet
32 | * For more information on the breakout see https://www.adafruit.com/product/1918
33 | * For information on the UV index scale see https://www.epa.gov/sunsafety/uv-index-scale-1
34 | * Sensor datasheet: https://cdn-shop.adafruit.com/datasheets/1918guva.pdf
35 | *
36 | * Created on October 8 2016 by Peter Dalmaris
37 | *
38 | */
39 |
40 | // the setup routine runs once when you press reset:
41 | void setup() {
42 | // initialize serial communication at 9600 bits per second:
43 | Serial.begin(9600);
44 | }
45 |
46 | // the loop routine runs over and over again forever:
47 | void loop() {
48 | // read the input on analog pin 0:
49 | int sensorValue = analogRead(A0);
50 |
51 | // Calculate the actual voltage at sensor out
52 | float voltage = sensorValue * (5.0 / 1023.0);
53 |
54 | //Print the value of the analog input
55 | Serial.print(sensorValue);
56 | Serial.print(",");
57 |
58 | //Print the UV index value. As per the specifications for the sensor,
59 | //this is done by dividing the sensor output voltage by 0.1
60 | Serial.println(voltage/0.1);
61 | delay(100); // delay in between reads for stability
62 | }
63 |
--------------------------------------------------------------------------------
/_0420_-_RGB_light_sensor_-_1/_0420_-_RGB_light_sensor_-_1.ino:
--------------------------------------------------------------------------------
1 | /* RGB light sensor demo sketch
2 | *
3 | * This sketch gets a color RGB reading from the light sensor
4 | * on the Adafruit TCS34725 (or equivelant) breakout module.
5 | *
6 | * If you connect an RGB LED, then the color that the sensor reads
7 | * will be displayed through the LED.
8 | *
9 | * This sketch was adapted from the original that comes with the
10 | * Adafruit library for Arduino Step by Step by Peter Dalmaris.
11 | *
12 | * Components
13 | * ----------
14 | * - Arduino Uno
15 | * - Adafruit RGB TCS34725 sensor breakout or equivelant
16 | * - RGB LED
17 | * - Two 560 Ohm resistors
18 | * - One 1 KOhm resistor
19 | *
20 | * Libraries
21 | * ---------
22 | * - Wire
23 | * - Adafruit_TCS34725
24 | *
25 | * Connections
26 | * -----------
27 | * Break out | Arduino Uno
28 | * -----------------------------
29 | * VIN | 5V
30 | * GND | GND
31 | * SCL | SCL or A5
32 | * SDA | SDA or A4
33 | * LED | GND to turn off (or any digital out set to LOW)
34 | * INT | 2 (but not used in this sketch)
35 | *
36 | * Other information
37 | * -----------------
38 | * For information on RGB color: https://en.wikipedia.org/wiki/RGB_color_model
39 | * For information on color temperature: https://en.wikipedia.org/wiki/Color_temperature
40 | * For more information on the breakout see https://www.adafruit.com/product/1334
41 | * The repository for the library used is at https://github.com/adafruit/Adafruit_TCS34725
42 | *
43 | * Created on October 8 2016 by Peter Dalmaris
44 | *
45 | */
46 |
47 | #include
48 | #include "Adafruit_TCS34725.h"
49 |
50 | // Pick analog outputs, for the UNO these three work well
51 | // use ~560 ohm resistor between Red & Blue, ~1K for green (its brighter)
52 | #define redpin 3
53 | #define greenpin 5
54 | #define bluepin 6
55 | // for a common anode LED, connect the common pin to +5V
56 | // for common cathode, connect the common to ground
57 |
58 | // set to false if using a common cathode LED
59 | #define commonAnode false
60 |
61 | // our RGB -> eye-recognized gamma color
62 | byte gammatable[256];
63 |
64 |
65 | Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);
66 |
67 | void setup() {
68 | Serial.begin(9600);
69 | Serial.println("Color View Test!");
70 |
71 | if (tcs.begin()) {
72 | Serial.println("Found sensor");
73 | } else {
74 | Serial.println("No TCS34725 found ... check your connections");
75 | while (1); // halt!
76 | }
77 |
78 | // use these three pins to drive an LED
79 | pinMode(redpin, OUTPUT);
80 | pinMode(greenpin, OUTPUT);
81 | pinMode(bluepin, OUTPUT);
82 |
83 | // thanks PhilB for this gamma table!
84 | // it helps convert RGB colors to what humans see
85 | for (int i=0; i<256; i++) {
86 | float x = i;
87 | x /= 255;
88 | x = pow(x, 2.5);
89 | x *= 255;
90 |
91 | if (commonAnode) {
92 | gammatable[i] = 255 - x;
93 | } else {
94 | gammatable[i] = x;
95 | }
96 | //Serial.println(gammatable[i]);
97 | }
98 | }
99 |
100 |
101 | void loop() {
102 | uint16_t clear, red, green, blue;
103 |
104 | tcs.setInterrupt(false); // turn on LED
105 |
106 | delay(60); // takes 50ms to read
107 |
108 | tcs.getRawData(&red, &green, &blue, &clear);
109 |
110 | tcs.setInterrupt(true); // turn off LED
111 |
112 | Serial.print("C:\t"); Serial.print(clear);
113 | Serial.print("\tR:\t"); Serial.print(red);
114 | Serial.print("\tG:\t"); Serial.print(green);
115 | Serial.print("\tB:\t"); Serial.print(blue);
116 |
117 | // Figure out some basic hex code for visualization
118 | uint32_t sum = clear;
119 | float r, g, b;
120 | r = red; r /= sum;
121 | g = green; g /= sum;
122 | b = blue; b /= sum;
123 | r *= 256; g *= 256; b *= 256;
124 | Serial.print("\t");
125 | Serial.print((int)r, HEX); Serial.print((int)g, HEX); Serial.print((int)b, HEX);
126 | Serial.println();
127 |
128 | analogWrite(redpin, gammatable[(int)r]);
129 | analogWrite(greenpin, gammatable[(int)g]);
130 | analogWrite(bluepin, gammatable[(int)b]);
131 | }
132 |
133 |
--------------------------------------------------------------------------------
/_0420_-_RGB_light_sensor_-_2/_0420_-_RGB_light_sensor_-_2.ino:
--------------------------------------------------------------------------------
1 | /* RGB light sensor demo sketch
2 | *
3 | * This sketch gets a color RGB reading from the light sensor
4 | * on the Adafruit TCS34725 (or equivelant) breakout module.
5 | *
6 | * This sketch was adapted from the original that comes with the
7 | * Adafruit library for Arduino Step by Step by Peter Dalmaris.
8 | *
9 | * Components
10 | * ----------
11 | * - Arduino Uno
12 | * - Adafruit RGB TCS34725 sensor breakout or equivelant
13 | *
14 | * Libraries
15 | * ---------
16 | * - Wire
17 | * - Adafruit_TCS34725
18 | *
19 | * Connections
20 | * -----------
21 | * Break out | Arduino Uno
22 | * -----------------------------
23 | * VIN | 5V
24 | * GND | GND
25 | * SCL | SCL or A5
26 | * SDA | SDA or A4
27 | * LED | GND to turn off (or any digital out set to LOW)
28 | * INT | 2 (but not used in this sketch)
29 | *
30 | * Other information
31 | * -----------------
32 | * For information on RGB color: https://en.wikipedia.org/wiki/RGB_color_model
33 | * For information on color temperature: https://en.wikipedia.org/wiki/Color_temperature
34 | * For more information on the breakout see https://www.adafruit.com/product/1334
35 | * The repository for the library used is at https://github.com/adafruit/Adafruit_TCS34725
36 | *
37 | * Created on October 8 2016 by Peter Dalmaris
38 | *
39 | */
40 |
41 | #include
42 | #include "Adafruit_TCS34725.h"
43 |
44 | Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);
45 |
46 | void setup() {
47 | Serial.begin(9600);
48 | Serial.println("Color View Test!");
49 |
50 | if (tcs.begin()) {
51 | Serial.println("Found sensor");
52 | } else {
53 | Serial.println("No TCS34725 found ... check your connections");
54 | while (1); // halt!
55 | }
56 |
57 | }
58 |
59 | void loop() {
60 | uint16_t clear, red, green, blue;
61 |
62 | tcs.setInterrupt(false); // turn on LED
63 |
64 | delay(60); // takes 50ms to read
65 |
66 | tcs.getRawData(&red, &green, &blue, &clear);
67 |
68 | tcs.setInterrupt(true); // turn off LED
69 |
70 | Serial.print("C:\t"); Serial.print(clear);
71 | Serial.print("\tR:\t"); Serial.print(red);
72 | Serial.print("\tG:\t"); Serial.print(green);
73 | Serial.print("\tB:\t"); Serial.println(blue);
74 | }
75 |
76 |
--------------------------------------------------------------------------------
/_0430_-_DHT22/_0430_-_DHT22.ino:
--------------------------------------------------------------------------------
1 | /* DHT22/11 temerature and humidity sensor demonstration sketch
2 | *
3 | * This sketch reads the temperature and humidity from a DHT sensor.
4 | *
5 | * This is a common digital sensor which is calibrated in factory
6 | * and outputs true values so that no further calculations are needed
7 | * on the Arduino.
8 |
9 | *
10 | * This sketch was adapted for Arduino Step by Step by Peter Dalmaris from the
11 | * demo sketch that ships with the Adafruit library.
12 | *
13 | * Components
14 | * ----------
15 | * - Arduino Uno
16 | * - A DHT22 or DHT11 sensor
17 | * - 10 kOhm resistor to pull up the data pin
18 | *
19 | * Libraries
20 | * ---------
21 | * DHT.h
22 | *
23 | * Connections
24 | * -----------
25 | *
26 | * Hold the sensor so that the grill is towards you. Here are the connections
27 | *
28 | * -----------
29 | * | - | - |
30 | * | - | - |
31 | * | - | - |
32 | * | - | - |
33 | * -----------
34 | * | | | |
35 | * | | | |
36 | * | | | |
37 | * | | | |
38 | * 5V 2 GND
39 | * data
40 | *
41 | * Connect a 10KOhm resistor between the 5V and data pin (2)
42 | *
43 | * Other information
44 | * -----------------
45 | *
46 | * DHT22 datasheet: https://www.sparkfun.com/datasheets/Sensors/Temperature/DHT22.pdf
47 | * The Github repository for the library: https://github.com/adafruit/DHT-sensor-library
48 | * The DHT library requires Adafruit's Unified Sensor Driver. Install that by searching
49 | * for "Adafruit Unified Sensor" in the Library Manager.
50 | * Learn more about the Unified Driver: https://github.com/adafruit/Adafruit_Sensor
51 | * About the Heat Index:
52 | * About pull up and pull down resistors:
53 | *
54 | *
55 | *
56 | * Created on October 11 2016 by Peter Dalmaris
57 | *
58 | */
59 |
60 | // Example testing sketch for various DHT humidity/temperature sensors
61 | // Written by ladyada, public domain
62 |
63 | #include "DHT.h"
64 |
65 | #define DHTPIN 2 // what digital pin we're connected to
66 |
67 | // Uncomment whatever type you're using!
68 | //#define DHTTYPE DHT11 // DHT 11
69 | #define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
70 | //#define DHTTYPE DHT21 // DHT 21 (AM2301)
71 |
72 | // Initialize DHT sensor.
73 | // Note that older versions of this library took an optional third parameter to
74 | // tweak the timings for faster processors. This parameter is no longer needed
75 | // as the current DHT reading algorithm adjusts itself to work on faster procs.
76 | DHT dht(DHTPIN, DHTTYPE);
77 |
78 | void setup() {
79 | Serial.begin(9600);
80 | Serial.println("DHTxx test!");
81 |
82 | dht.begin();
83 | }
84 |
85 | void loop() {
86 | // Wait a few seconds between measurements.
87 | delay(2000);
88 |
89 | // Reading temperature or humidity takes about 250 milliseconds!
90 | // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
91 | float h = dht.readHumidity();
92 | // Read temperature as Celsius (the default)
93 | float t = dht.readTemperature();
94 | // Read temperature as Fahrenheit (isFahrenheit = true)
95 | float f = dht.readTemperature(true);
96 |
97 | // Check if any reads failed and exit early (to try again).
98 | if (isnan(h) || isnan(t) || isnan(f)) {
99 | Serial.println("Failed to read from DHT sensor!");
100 | return;
101 | }
102 |
103 | // Compute heat index in Fahrenheit (the default)
104 | float hif = dht.computeHeatIndex(f, h);
105 | // Compute heat index in Celsius (isFahreheit = false)
106 | float hic = dht.computeHeatIndex(t, h, false);
107 |
108 | Serial.print("Humidity: ");
109 | Serial.print(h);
110 | Serial.print(" %\t");
111 | Serial.print("Temperature: ");
112 | Serial.print(t);
113 | Serial.print(" *C ");
114 | Serial.print(f);
115 | Serial.print(" *F\t");
116 | Serial.print("Heat index: ");
117 | Serial.print(hic);
118 | Serial.print(" *C ");
119 | Serial.print(hif);
120 | Serial.println(" *F");
121 | }
122 |
--------------------------------------------------------------------------------
/_0440_-_Termistor/_0440_-_Termistor.ino:
--------------------------------------------------------------------------------
1 | /* Thermistor temperature sensor demonstration sketch
2 | *
3 | * This sketch calculates the the resistane of a
4 | * thermistor connected in a voltage divider circuit.
5 | *
6 | * This sketch was written for Arduino Step by Step by Peter Dalmaris.
7 | *
8 | * Components
9 | * ----------
10 | * - Arduino Uno
11 | * - thermistor temperature sensor
12 | * - 10 kOhm resistor
13 | *
14 | * Libraries
15 | * ---------
16 | * Thermistor.h
17 | *
18 | * Connections
19 | * -----------
20 | *
21 | * Connect the Arduino 5V pin to one end of the
22 | * thermistor. Connect the resistor to the Arduino GND
23 | * pin. Connect the free pins on the thermistor and
24 | * resistor together. Connect the thermistor and resistor
25 | * junction to the Arduino analog pin 0. This
26 | * structure is called a "voltage divider".
27 | * 10 kΩ
28 | * 5V -----OOO------\/\/\/-----GND
29 | * |
30 | * |
31 | * |
32 | * A0
33 | *
34 | *
35 | * Other information
36 | * -----------------
37 | *
38 | * About the termistor: https://en.wikipedia.org/wiki/Thermistor
39 | * The Github repository for the library: https://github.com/panStamp/thermistor
40 | *
41 | *
42 | *
43 | * Created on October 8 2016 by Peter Dalmaris
44 | *
45 | */
46 |
47 | // the value of the 'other' resistor. I am using a 10 KOhm resistor.
48 | #define SERIESRESISTOR 9950
49 |
50 | // What pin to connect the sensor to
51 | #define THERMISTORPIN A0
52 |
53 | void setup(void) {
54 | Serial.begin(9600);
55 | }
56 |
57 | void loop(void) {
58 | float reading;
59 |
60 | reading = analogRead(THERMISTORPIN);
61 |
62 | Serial.print("Analog reading ");
63 | Serial.println(reading);
64 |
65 | // convert the value to resistance
66 | reading = (1023 / reading) - 1;
67 | reading = SERIESRESISTOR / reading;
68 | Serial.print("Thermistor resistance ");
69 | Serial.println(reading);
70 |
71 | delay(1000);
72 | }
73 |
--------------------------------------------------------------------------------
/_0440_-_Thermistor_with_library/_0440_-_Thermistor_with_library.ino:
--------------------------------------------------------------------------------
1 | /* Thermistor temperature sensor demonstration sketch
2 | *
3 | * This sketch calculates the the temperature by reading the voltage of a
4 | * thermistor connected in a voltage divider circuit.
5 | *
6 | * It then does a caclulation to convert this raw reading into a temperature.
7 | *
8 | * This sketch was adapted for Arduino Step by Step by Peter Dalmaris from the
9 | * demo sketch that ships with the library, written by Daniel Berenguer.
10 | *
11 | * Components
12 | * ----------
13 | * - Arduino Uno
14 | * - thermistor temperature sensor
15 | * - 10 kOhm resistor
16 | *
17 | * Libraries
18 | * ---------
19 | * Thermistor.h
20 | *
21 | * Connections
22 | * -----------
23 | *
24 | * Connect the Arduino 5V pin to one end of the
25 | * thermistor. Connect the resistor to the Arduino GND
26 | * pin. Connect the free pins on the thermistor and
27 | * resistor together. Connect the thermistor and resistor
28 | * junction to the Arduino analog pin 0. This
29 | * structure is called a "voltage divider".
30 | * 10 kΩ
31 | * 5V -----OOO------\/\/\/-----GND
32 | * |
33 | * |
34 | * |
35 | * A0
36 | *
37 | *
38 | * Other information
39 | * -----------------
40 | *
41 | * About the termistor: https://en.wikipedia.org/wiki/Thermistor
42 | * The Github repository for the library: https://github.com/panStamp/thermistor
43 | *
44 | *
45 | *
46 | * Created on October 8 2016 by Peter Dalmaris
47 | *
48 | */
49 |
50 | /**
51 | * Copyright (c) 2015 panStamp S.L.U.
52 | *
53 | * This file is part of the panStamp project.
54 | *
55 | * panStamp is free software; you can redistribute it and/or modify
56 | * it under the terms of the GNU General Public License as published by
57 | * the Free Software Foundation; either version 2 of the License, or
58 | * (at your option) any later version.
59 | *
60 | * panStamp is distributed in the hope that it will be useful,
61 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
62 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
63 | * GNU General Public License for more details.
64 | *
65 | * You should have received a copy of the GNU General Public License
66 | * along with panStamp; if not, write to the Free Software
67 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
68 | * USA
69 | *
70 | * Author: Daniel Berenguer
71 | * Creation date: 06/24/2015
72 | */
73 |
74 | #include "thermistor.h"
75 |
76 | // Analog pin used to read the NTC
77 | #define NTC_PIN A0
78 |
79 | // Thermistor object
80 | THERMISTOR thermistor(NTC_PIN, // Analog pin
81 | 7500, // Nominal resistance at 25 ºC
82 | 3950, // thermistor's beta coefficient
83 | 9950); // Value of the series resistor
84 |
85 | // Global temperature reading
86 | uint16_t temp;
87 |
88 | /**
89 | * setup
90 | *
91 | * Arduino setup function
92 | */
93 | void setup()
94 | {
95 | Serial.begin(9600);
96 | }
97 |
98 | /**
99 | * loop
100 | *
101 | * Arduino main loop
102 | */
103 | void loop()
104 | {
105 | temp = thermistor.read(); // Read temperature
106 |
107 | Serial.print("Temp in 1/10 ºC : ");
108 | Serial.println(temp);
109 |
110 | delay(5000);
111 | }
112 |
113 |
--------------------------------------------------------------------------------
/_0450_-_TMP36_temperature_sensor/_0450_-_TMP36_temperature_sensor.ino:
--------------------------------------------------------------------------------
1 | /* TMP36 temperature sensor demonstration sketch
2 | *
3 | * This sketch reads the the voltage of the TMP36 sensor output pin.
4 | * It then does a caclulation to convert this raw reading into a temperature.
5 | *
6 | * This sketch was written for Arduino Step by Step by Peter Dalmaris.
7 | *
8 | * Components
9 | * ----------
10 | * - Arduino Uno
11 | * - TMP36 temperature sensor
12 | *
13 | * Libraries
14 | * ---------
15 | * NONE
16 | *
17 | * Connections
18 | * -----------
19 | *
20 | * As you look at the sensor with the label facing you, the left most pin is #1
21 | *
22 | * Break out | Arduino Uno
23 | * -----------------------------
24 | * 1 | 5V
25 | * 2 | A0
26 | * 3 | GND
27 | *
28 | *
29 | * Other information
30 | * -----------------
31 | *
32 | * Datasheet: http://www.analog.com/media/en/technical-documentation/data-sheets/TMP35_36_37.pdf
33 | *
34 | * Created on October 8 2016 by Peter Dalmaris
35 | *
36 | */
37 |
38 | int sensorPin = 0; // The reading is obtained from analog pin 0 (A0)
39 | float supply_voltage = 5; // 3.3; //If you are useing a 3.3V supply voltage, change this accordingly.
40 | // If you are using the 3.3V supply also uncomment line 44.
41 | // If you are using the 5V supply, use the value "5" here.
42 |
43 | void setup()
44 | {
45 | // analogReference(EXTERNAL); // If using 3.3V as reference by bridging it to the AREF pin,
46 | // then uncomment this line. If using 5V then this is not necessary.
47 | Serial.begin(9600); // Start the serial connection with the computer
48 | // to view the result open the serial monitor
49 | }
50 |
51 | void loop()
52 | {
53 | //getting the voltage reading from the temperature sensor
54 | int reading = analogRead(sensorPin);
55 |
56 | // converting that reading to voltage, for 3.3v arduino use 3.3
57 | float voltage = reading * supply_voltage / 1024;
58 |
59 | // print out the voltage
60 | Serial.print(voltage); Serial.println(" volts");
61 |
62 | // now print out the temperature
63 | float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree with 500 mV offset
64 | //to degrees ((voltage - 500mV) times 100)
65 | Serial.print(temperatureC); Serial.println(" degrees C");
66 |
67 | // now convert to Fahrenheit
68 | float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
69 | Serial.print(temperatureF); Serial.println(" degrees F");
70 |
71 | delay(1000); //waiting a second
72 | }
73 |
--------------------------------------------------------------------------------
/_0460_-_Temperature_MCP9808/_0460_-_Temperature_MCP9808.ino:
--------------------------------------------------------------------------------
1 | /* Temperature MCP9808 sensor demo sketch
2 | *
3 | * This sketch reads the temperature from the MCP9808 precision sensor
4 | * on the Adafruit TCS34725 (or equivelant) breakout module.
5 | *
6 | * This sketch was adapted from the original that comes with the
7 | * Adafruit library for Arduino Step by Step by Peter Dalmaris.
8 | *
9 | * Components
10 | * ----------
11 | * - Arduino Uno
12 | * - Adafruit MCP9808 breakout module (or equivelant)
13 | *
14 | * Libraries
15 | * ---------
16 | * - Wire
17 | * - Adafruit_MCP9808
18 | *
19 | * Connections
20 | * -----------
21 | * Break out | Arduino Uno
22 | * -----------------------------
23 | * VIN | 5V
24 | * GND | GND
25 | * SCL | SCL or A5
26 | * SDA | SDA or A4
27 |
28 | *
29 | * Other information
30 | * -----------------
31 | * There are three pads on the sensor breakout that can be used
32 | * to change the I2C address.
33 | * MCP9808 datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/25095A.pdf
34 | * Adafruit product page: https://www.adafruit.com/product/1782
35 | * Adafruit library on Github: https://github.com/adafruit/Adafruit_MCP9808_Library
36 | *
37 | * Created on October 8 2016 by Peter Dalmaris
38 | *
39 | */
40 |
41 | /**************************************************************************/
42 | /*!
43 | This is a demo for the Adafruit MCP9808 breakout
44 | ----> http://www.adafruit.com/products/1782
45 | Adafruit invests time and resources providing this open source code,
46 | please support Adafruit and open-source hardware by purchasing
47 | products from Adafruit!
48 | */
49 | /**************************************************************************/
50 |
51 | #include
52 | #include "Adafruit_MCP9808.h"
53 |
54 | // Create the MCP9808 temperature sensor object
55 | Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
56 |
57 | void setup() {
58 | Serial.begin(9600);
59 | Serial.println("MCP9808 demo");
60 |
61 | // Make sure the sensor is found, you can also pass in a different i2c
62 | // address with tempsensor.begin(0x19) for example
63 | if (!tempsensor.begin(0x19)) {
64 | Serial.println("Couldn't find MCP9808!");
65 | while (1);
66 | }
67 | }
68 |
69 | void loop() {
70 | // Read and print out the temperature, then convert to *F
71 | float c = tempsensor.readTempC();
72 | float f = c * 9.0 / 5.0 + 32;
73 | Serial.print("Temp: "); Serial.print(c); Serial.print("*C\t");
74 | Serial.print(f); Serial.println("*F");
75 | delay(250);
76 |
77 | Serial.println("Shutdown MCP9808.... ");
78 | tempsensor.shutdown_wake(1); // shutdown MSP9808 - power consumption ~0.1 mikro Ampere
79 |
80 | delay(2000);
81 |
82 | Serial.println("wake up MCP9808.... "); // wake up MSP9808 - power consumption ~200 mikro Ampere
83 | tempsensor.shutdown_wake(0);
84 |
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/_0480_-BMP180_-_2/_0480_-BMP180_-_2.ino:
--------------------------------------------------------------------------------
1 | /* BMP180 sensor demo sketch
2 | *
3 | * This sketch extracts barometric pressure and temperature
4 | * from the BMP180 breakout module.
5 | *
6 | * This sketch was adapted from the original that comes with the
7 | * Adafruit Adafruit_BMP085_U library for Arduino Step by Step by Peter Dalmaris.
8 | *
9 | * Components
10 | * ----------
11 | * - Arduino Uno
12 | * - BMP180 sensor breakout or equivelant (the BMP085 will also work)
13 | *
14 | * Libraries
15 | * ---------
16 | * - Wire
17 | * - Adafruit_Sensor
18 | * - Adafruit_BMP085_U
19 | *
20 | * Connections
21 | * -----------
22 | * Break out | Arduino Uno
23 | * -----------------------------
24 | * VIN | 5V
25 | * GND | GND
26 | * SCL | SCL or A5
27 | * SDA | SDA or A4
28 | *
29 | * Other information
30 | * -----------------
31 | * For information on barometric pressure: https://en.wikipedia.org/wiki/Atmospheric_pressure
32 | * For information on the Adafruit library is at https://github.com/adafruit/Adafruit_BMP085_Unified
33 | * Datasheet: https://github.com/sparkfun/BMP180_Breakout/raw/master/Documentation/BMP180%20Datasheet%20V2.5.pdf
34 | *
35 | * For best results, find the atmospheric pressure at sea level at the closest location to yours,
36 | * and store it in the seaLevelPressure variable.
37 | *
38 | * Created on October 8 2016 by Peter Dalmaris
39 | *
40 | *
41 | * This driver uses the Adafruit unified sensor library (Adafruit_Sensor),
42 | * which provides a common 'type' for sensor data and some helper functions.
43 | *
44 | * To use this driver you will also need to download the Adafruit_Sensor
45 | * library and include it in your libraries folder.
46 | *
47 | * You should also assign a unique ID to this sensor for use with
48 | * the Adafruit Sensor API so that you can identify this particular
49 | * sensor in any data logs, etc. To assign a unique ID, simply
50 | * provide an appropriate value in the constructor below (12345
51 | * is used by default in this example).
52 | *
53 | * Connections
54 | * ===========
55 | * Connect SCL to analog 5
56 | * Connect SDA to analog 4
57 | * Connect VDD to 3.3V DC
58 | * Connect GROUND to common ground
59 | *
60 | * History
61 | * =======
62 | * 2013/JUN/17 - Updated altitude calculations (KTOWN)
63 | * 2013/FEB/13 - First version (KTOWN)
64 | */
65 |
66 | #include
67 | #include
68 | #include
69 |
70 |
71 |
72 | Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);
73 |
74 | /**************************************************************************/
75 | /*
76 | Displays some basic information on this sensor from the unified
77 | sensor API sensor_t type (see Adafruit_Sensor for more information)
78 | */
79 | /**************************************************************************/
80 | void displaySensorDetails(void)
81 | {
82 | sensor_t sensor;
83 | bmp.getSensor(&sensor);
84 | Serial.println("------------------------------------");
85 | Serial.print ("Sensor: "); Serial.println(sensor.name);
86 | Serial.print ("Driver Ver: "); Serial.println(sensor.version);
87 | Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);
88 | Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" hPa");
89 | Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" hPa");
90 | Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" hPa");
91 | Serial.println("------------------------------------");
92 | Serial.println("");
93 | delay(500);
94 | }
95 |
96 | /**************************************************************************/
97 | /*
98 | Arduino setup function (automatically called at startup)
99 | */
100 | /**************************************************************************/
101 | void setup(void)
102 | {
103 | Serial.begin(9600);
104 | Serial.println("Pressure Sensor Test"); Serial.println("");
105 | Serial.println("Starting");
106 |
107 | bmp.begin();
108 | /* Initialise the sensor */
109 | if(!bmp.begin())
110 | {
111 | /* There was a problem detecting the BMP085 ... check your connections */
112 | Serial.print("Ooops, no BMP085 detected ... Check your wiring or I2C ADDR!");
113 | while(1);
114 | }
115 | Serial.println("Started");
116 |
117 | /* Display some basic information on this sensor */
118 | displaySensorDetails();
119 | }
120 |
121 | /**************************************************************************/
122 | /*
123 | Arduino loop function, called once 'setup' is complete (your own code
124 | should go here)
125 | */
126 | /**************************************************************************/
127 | void loop(void)
128 | {
129 | /* Get a new sensor event */
130 | sensors_event_t event;
131 | bmp.getEvent(&event);
132 |
133 | /* Display the results (barometric pressure is measure in hPa) */
134 | if (event.pressure)
135 | {
136 | /* Display atmospheric pressue in hPa */
137 | Serial.print("Pressure: ");
138 | Serial.print(event.pressure);
139 | Serial.println(" hPa");
140 |
141 | /* Calculating altitude with reasonable accuracy requires pressure *
142 | * sea level pressure for your position at the moment the data is *
143 | * converted, as well as the ambient temperature in degress *
144 | * celcius. If you don't have these values, a 'generic' value of *
145 | * 1013.25 hPa can be used (defined as SENSORS_PRESSURE_SEALEVELHPA *
146 | * in sensors.h), but this isn't ideal and will give variable *
147 | * results from one day to the next. *
148 | * *
149 | * You can usually find the current SLP value by looking at weather *
150 | * websites or from environmental information centers near any major *
151 | * airport. *
152 | * *
153 | * For example, for Paris, France you can check the current mean *
154 | * pressure and sea level at: http://bit.ly/16Au8ol */
155 |
156 | /* First we get the current temperature from the BMP085 */
157 | float temperature;
158 | bmp.getTemperature(&temperature);
159 | Serial.print("Temperature: ");
160 | Serial.print(temperature);
161 | Serial.println(" C");
162 |
163 | /* Then convert the atmospheric pressure, and SLP to altitude */
164 | /* Update this next line with the current SLP for better results */
165 | // float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;
166 | float seaLevelPressure = 1003.4;
167 | Serial.print("Altitude: ");
168 | Serial.print(bmp.pressureToAltitude(seaLevelPressure,
169 | event.pressure));
170 | Serial.println(" m");
171 | Serial.println("");
172 | }
173 | else
174 | {
175 | Serial.println("Sensor error");
176 | }
177 | delay(1000);
178 | }
179 |
--------------------------------------------------------------------------------
/_0480_-_BMP180_-_1/_0480_-_BMP180_-_1.ino:
--------------------------------------------------------------------------------
1 | /* BMP180 sensor demo sketch
2 | *
3 | * This sketch extracts barometric pressure and temperature
4 | * from the BMP180 breakout module.
5 | *
6 | * This sketch was adapted from the original that comes with the
7 | * Sparkfun SFE_BMP180 library for Arduino Step by Step by Peter Dalmaris.
8 | *
9 | * Components
10 | * ----------
11 | * - Arduino Uno
12 | * - BMP180 sensor breakout or equivelant (the BMP085 will also work)
13 | *
14 | * Libraries
15 | * ---------
16 | * - Wire
17 | * - SFE_BMP180
18 | *
19 | * Connections
20 | * -----------
21 | * Break out | Arduino Uno
22 | * -----------------------------
23 | * VIN | 5V
24 | * GND | GND
25 | * SCL | SCL or A5
26 | * SDA | SDA or A4
27 | *
28 | * Other information
29 | * -----------------
30 | * For information on barometric pressure: https://en.wikipedia.org/wiki/Atmospheric_pressure
31 | * For information on the Sparkfun library is at https://github.com/sparkfun/BMP180_Breakout_Arduino_Library
32 | * Datasheet: https://github.com/sparkfun/BMP180_Breakout/raw/master/Documentation/BMP180%20Datasheet%20V2.5.pdf
33 | *
34 | * For best results, insert the actual height at your location in the ALTITUDE variable.
35 | *
36 | * Created on October 8 2016 by Peter Dalmaris
37 | *
38 | * ORIGINAL HEADER from the Sparkfun library
39 | *
40 | * This sketch shows how to use the SFE_BMP180 library to read the
41 | * Bosch BMP180 barometric pressure sensor.
42 | * https://www.sparkfun.com/products/11824
43 | *
44 | * Like most pressure sensors, the BMP180 measures absolute pressure.
45 | * This is the actual ambient pressure seen by the device, which will
46 | * vary with both altitude and weather.
47 | *
48 | * Before taking a pressure reading you must take a temparture reading.
49 | * This is done with startTemperature() and getTemperature().
50 | * The result is in degrees C.
51 | *
52 | * Once you have a temperature reading, you can take a pressure reading.
53 | * This is done with startPressure() and getPressure().
54 | * The result is in millibar (mb) aka hectopascals (hPa).
55 | *
56 | * If you'll be monitoring weather patterns, you will probably want to
57 | * remove the effects of altitude. This will produce readings that can
58 | * be compared to the published pressure readings from other locations.
59 | * To do this, use the sealevel() function. You will need to provide
60 | * the known altitude at which the pressure was measured.
61 | *
62 | * If you want to measure altitude, you will need to know the pressure
63 | * at a baseline altitude. This can be average sealevel pressure, or
64 | * a previous pressure reading at your altitude, in which case
65 | * subsequent altitude readings will be + or - the initial baseline.
66 | * This is done with the altitude() function.
67 | *
68 | * Hardware connections:
69 | *
70 | * - (GND) to GND
71 | * + (VDD) to 3.3V or 5V
72 | *
73 | * (WARNING: do not connect + to 5V or the sensor will be damaged!)
74 | *
75 | * You will also need to connect the I2C pins (SCL and SDA) to your
76 | * Arduino. The pins are different on different Arduinos:
77 | *
78 | * Any Arduino pins labeled: SDA SCL
79 | * Uno, Redboard, Pro: A4 A5
80 | * Mega2560, Due: 20 21
81 | * Leonardo: 2 3
82 | *
83 | * Leave the IO (VDDIO) pin unconnected. This pin is for connecting
84 | * the BMP180 to systems with lower logic levels such as 1.8V
85 | *
86 | * Have fun! -Your friends at SparkFun.
87 | *
88 | * The SFE_BMP180 library uses floating-point equations developed by the
89 | * Weather Station Data Logger project: http://wmrx00.sourceforge.net/
90 | *
91 | * Our example code uses the "beerware" license. You can do anything
92 | * you like with this code. No really, anything. If you find it useful,
93 | * buy me a beer someday.
94 | *
95 | * V10 Mike Grusin, SparkFun Electronics 10/24/2013
96 | * V1.1.2 Updates for Arduino 1.6.4 5/2015
97 | */
98 |
99 |
100 | #include
101 | #include
102 |
103 | // You will need to create an SFE_BMP180 object, here called "pressure":
104 |
105 | SFE_BMP180 pressure;
106 |
107 | #define ALTITUDE 217.0 // Altitude of Tech Explorations's HQ in Sydney, AUS in meters
108 |
109 | void setup()
110 | {
111 | Serial.begin(9600);
112 | Serial.println("REBOOT");
113 |
114 | // Initialize the sensor (it is important to get calibration values stored on the device).
115 |
116 | if (pressure.begin())
117 | Serial.println("BMP180 init success");
118 | else
119 | {
120 | // Oops, something went wrong, this is usually a connection problem,
121 | // see the comments at the top of this sketch for the proper connections.
122 |
123 | Serial.println("BMP180 init fail\n\n");
124 | while(1); // Pause forever.
125 | }
126 | }
127 |
128 | void loop()
129 | {
130 | char status;
131 | double T,P,p0,a;
132 |
133 | // Loop here getting pressure readings every 10 seconds.
134 |
135 | // If you want sea-level-compensated pressure, as used in weather reports,
136 | // you will need to know the altitude at which your measurements are taken.
137 | // We're using a constant called ALTITUDE in this sketch:
138 |
139 | Serial.println();
140 | Serial.print("provided altitude: ");
141 | Serial.print(ALTITUDE,0);
142 | Serial.print(" meters, ");
143 | Serial.print(ALTITUDE*3.28084,0);
144 | Serial.println(" feet");
145 |
146 | // If you want to measure altitude, and not pressure, you will instead need
147 | // to provide a known baseline pressure. This is shown at the end of the sketch.
148 |
149 | // You must first get a temperature measurement to perform a pressure reading.
150 |
151 | // Start a temperature measurement:
152 | // If request is successful, the number of ms to wait is returned.
153 | // If request is unsuccessful, 0 is returned.
154 |
155 | status = pressure.startTemperature();
156 | if (status != 0)
157 | {
158 | // Wait for the measurement to complete:
159 | delay(status);
160 |
161 | // Retrieve the completed temperature measurement:
162 | // Note that the measurement is stored in the variable T.
163 | // Function returns 1 if successful, 0 if failure.
164 |
165 | status = pressure.getTemperature(T);
166 | if (status != 0)
167 | {
168 | // Print out the measurement:
169 | Serial.print("temperature: ");
170 | Serial.print(T,2);
171 | Serial.print(" deg C, ");
172 | Serial.print((9.0/5.0)*T+32.0,2);
173 | Serial.println(" deg F");
174 |
175 | // Start a pressure measurement:
176 | // The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait).
177 | // If request is successful, the number of ms to wait is returned.
178 | // If request is unsuccessful, 0 is returned.
179 |
180 | status = pressure.startPressure(3);
181 | if (status != 0)
182 | {
183 | // Wait for the measurement to complete:
184 | delay(status);
185 |
186 | // Retrieve the completed pressure measurement:
187 | // Note that the measurement is stored in the variable P.
188 | // Note also that the function requires the previous temperature measurement (T).
189 | // (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.)
190 | // Function returns 1 if successful, 0 if failure.
191 |
192 | status = pressure.getPressure(P,T);
193 | if (status != 0)
194 | {
195 | // Print out the measurement:
196 | Serial.print("absolute pressure: ");
197 | Serial.print(P,2);
198 | Serial.print(" mb, ");
199 | Serial.print(P*0.0295333727,2);
200 | Serial.println(" inHg");
201 |
202 | // The pressure sensor returns abolute pressure, which varies with altitude.
203 | // To remove the effects of altitude, use the sealevel function and your current altitude.
204 | // This number is commonly used in weather reports.
205 | // Parameters: P = absolute pressure in mb, ALTITUDE = current altitude in m.
206 | // Result: p0 = sea-level compensated pressure in mb
207 |
208 | p0 = pressure.sealevel(P,ALTITUDE); // we're at 1655 meters (Boulder, CO)
209 | Serial.print("relative (sea-level) pressure: ");
210 | Serial.print(p0,2);
211 | Serial.print(" mb, ");
212 | Serial.print(p0*0.0295333727,2);
213 | Serial.println(" inHg");
214 |
215 | // On the other hand, if you want to determine your altitude from the pressure reading,
216 | // use the altitude function along with a baseline pressure (sea-level or other).
217 | // Parameters: P = absolute pressure in mb, p0 = baseline pressure in mb.
218 | // Result: a = altitude in m.
219 |
220 | a = pressure.altitude(P,p0);
221 | Serial.print("computed altitude: ");
222 | Serial.print(a,0);
223 | Serial.print(" meters, ");
224 | Serial.print(a*3.28084,0);
225 | Serial.println(" feet");
226 | }
227 | else Serial.println("error retrieving pressure measurement\n");
228 | }
229 | else Serial.println("error starting pressure measurement\n");
230 | }
231 | else Serial.println("error retrieving temperature measurement\n");
232 | }
233 | else Serial.println("error starting temperature measurement\n");
234 |
235 | delay(5000); // Pause for 5 seconds.
236 | }
237 |
--------------------------------------------------------------------------------
/_0490_-_Environment_sensor_BME280/_0490_-_Environment_sensor_BME280.ino:
--------------------------------------------------------------------------------
1 | /* BME280 sensor demo sketch
2 | *
3 | * This sketch demonstrates the use of the BME280 environment sensor.
4 | * It extracts barometric pressure, temperature and humidity values
5 | * from the BME280breakout module.
6 | *
7 | * This sensor can communicate via SPI or I2C
8 | *
9 | * This sketch was adapted from the original that comes with the
10 | * Adafruit Adafruit_BME280 library for Arduino Step by Step by Peter Dalmaris.
11 | *
12 | * Components
13 | * ----------
14 | * - Arduino Uno
15 | * - BME280 sensor breakout or equivelant (the BMP085 will also work)
16 | *
17 | * Libraries
18 | * ---------
19 | * - Wire
20 | * - Adafruit_Sensor
21 | * - Adafruit_BME280
22 | *
23 | * Connections
24 | * -----------
25 | * In the demo, we will use both the SPI interface and I2C interfaces.
26 | *
27 | * For SPI:
28 | * Break out | Arduino Uno
29 | * -----------------------------
30 | * VIN | 5V
31 | * GND | GND
32 | * SCK | 13 (can change)
33 | * SDO | 12 (can change)
34 | * SDI | 11 (can change)
35 | * CS | 10 (can change)
36 | *
37 | * For I2C:
38 | * Break out | Arduino Uno
39 | * -----------------------------
40 | * VIN | 5V
41 | * GND | GND
42 | * SCK | SCL or A5
43 | * SDA | SDA or A4
44 | *
45 | *
46 | * Other information
47 | * -----------------
48 | * For information on barometric pressure: https://en.wikipedia.org/wiki/Atmospheric_pressure
49 | * For information on the Adafruit library is at https://github.com/adafruit/Adafruit_BME280_Library
50 | * Adafruit product page: https://www.adafruit.com/products/2652
51 | * Datasheet: https://www.bosch-sensortec.com/bst/products/all_products/bme280
52 | *
53 | * For best results, find the atmospheric pressure at sea level at the closest location to yours,
54 | * and store it in the SEALEVELPRESSURE_HPA variable.
55 | *
56 | * Created on October 8 2016 by Peter Dalmaris
57 | *
58 | */
59 | /***************************************************************************
60 | This is a library for the BME280 humidity, temperature & pressure sensor
61 |
62 | Designed specifically to work with the Adafruit BME280 Breakout
63 | ----> http://www.adafruit.com/products/2650
64 |
65 | These sensors use I2C or SPI to communicate, 2 or 4 pins are required
66 | to interface.
67 |
68 | Adafruit invests time and resources providing this open source code,
69 | please support Adafruit andopen-source hardware by purchasing products
70 | from Adafruit!
71 |
72 | Written by Limor Fried & Kevin Townsend for Adafruit Industries.
73 | BSD license, all text above must be included in any redistribution
74 | ***************************************************************************/
75 |
76 | #include
77 | #include
78 | #include
79 | #include
80 |
81 | //#define BME_SCK 13
82 | //#define BME_MISO 12
83 | //#define BME_MOSI 11
84 | //#define BME_CS 10
85 |
86 | #define SEALEVELPRESSURE_HPA (1017.8)
87 |
88 | //#define BME280_ADDRESS (0x76)
89 |
90 | Adafruit_BME280 bme; // I2C
91 | //Adafruit_BME280 bme(BME_CS); // hardware SPI
92 | //Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK);
93 |
94 | void setup() {
95 | Serial.begin(9600);
96 | Serial.println(F("BME280 test"));
97 |
98 | if (!bme.begin()) {
99 | Serial.println("Could not find a valid BME280 sensor, check wiring!");
100 | while (1);
101 | }
102 | }
103 |
104 | void loop() {
105 | Serial.print("Temperature = ");
106 | Serial.print(bme.readTemperature());
107 | Serial.println(" *C");
108 |
109 | Serial.print("Pressure = ");
110 |
111 | Serial.print(bme.readPressure() / 100.0F);
112 | Serial.println(" hPa");
113 |
114 | Serial.print("Approx. Altitude = ");
115 | Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
116 | Serial.println(" m");
117 |
118 | Serial.print("Humidity = ");
119 | Serial.print(bme.readHumidity());
120 | Serial.println(" %");
121 |
122 | Serial.println();
123 | delay(2000);
124 | }
125 |
--------------------------------------------------------------------------------
/_0500_-_Infrared_Sensor_1/_0500_-_Infrared_Sensor_1.ino:
--------------------------------------------------------------------------------
1 | /* Infrred sensor demo sketch
2 | *
3 | * This sketch demonstrates the use of the PIR infrared motion sensor.
4 | *
5 | * This is an example of the minimum code needed to operate the PIR sensor
6 | * with the Arduino. A PIR sensor controls an LED, without the use of
7 | * an Arduino.
8 | *
9 | * This sketch was written for Arduino Step by Step by Peter Dalmaris.
10 | *
11 | * Components
12 | * ----------
13 | * - Arduino Uno
14 | * - Infrared motion sensor
15 | * - An LED
16 | * - A 220 Ohm resistor for the LED
17 | *
18 | * Libraries
19 | * ---------
20 | * - None
21 | *
22 | * Connections
23 | * -----------
24 | * Break out | Arduino Uno
25 | * -----------------------------
26 | * VCC | 5V
27 | * GND | GND
28 | * OUT | 4
29 | *
30 | * Also connect an LED to simulate a controlled device.
31 | * 220 Ohm
32 | * 3 ----/\/\/\/\----(LED |)----GND
33 | *
34 | *
35 | * Other information
36 | * -----------------
37 | * For information on PIR sensors: https://en.wikipedia.org/wiki/Passive_infrared_sensor
38 | * Datasheet: https://www.mpja.com/download/31227sc.pdf
39 | *
40 | * Created on October 14 2016 by Peter Dalmaris
41 | *
42 | */
43 |
44 | int ledPin = 4; // choose the pin for the LED
45 | int inputPin = 3; // choose the input pin (for PIR sensor)
46 | int pirState = LOW; // we start, assuming no motion detected
47 | int val = 0; // variable for reading the pin status
48 |
49 | //the time we give the sensor to calibrate (10-60 secs according to the datasheet)
50 | int calibrationTime = 30; //This time is in seconds
51 |
52 | void setup() {
53 | pinMode(ledPin, OUTPUT); // declare LED as output
54 | pinMode(inputPin, INPUT); // declare sensor as input
55 |
56 | Serial.begin(9600);
57 | Serial.println("Waiting for the sensor to warm up.");
58 | // delay(calibrationTime * 1000); // Convert the time from seconds to milliseconds.
59 | Serial.println("SENSOR ACTIVE");
60 | }
61 |
62 | void loop(){
63 | val = digitalRead(inputPin); // read input value
64 |
65 | if (val == HIGH) { // check if the input is HIGH
66 | digitalWrite(ledPin, HIGH); // turn LED ON
67 | if (pirState == LOW) {
68 | // we have just turned on
69 | Serial.println("Motion detected!");
70 | // We only want to print on the output change, not state
71 | pirState = HIGH;
72 | }
73 | } else {
74 | digitalWrite(ledPin, LOW); // turn LED OFF
75 | if (pirState == HIGH){
76 | // we have just turned off
77 | Serial.println("Motion ended!");
78 | // We only want to print on the output change, not state
79 | pirState = LOW;
80 | }
81 | }
82 | delay(1000);
83 | }
84 |
85 |
--------------------------------------------------------------------------------
/_0500_-_Infrared_Sensor_2/_0500_-_Infrared_Sensor_2.ino:
--------------------------------------------------------------------------------
1 | /* Infrred sensor demo sketch
2 | *
3 | * This sketch demonstrates the use of the PIR infrared motion sensor.
4 | *
5 | * The sketch adds to the bare minimum version by allowing extra time
6 | * after the sensor goes LOW for the LED to remain HIGH. This could be
7 | * useful in a scenario where you want a light to go on in a room when
8 | * someone enters it, but to turn of a few minutes after they leave it.
9 | *
10 | * This sketch was adapted from the original that comes with the
11 | * Adafruit library for Arduino Step by Step by Peter Dalmaris.
12 | *
13 | * Components
14 | * ----------
15 | * - Arduino Uno
16 | * - Infrared motion sensor
17 | * - An LED
18 | * - A 220 Ohm resistor for the LEd
19 | *
20 | * Libraries
21 | * ---------
22 | * - None
23 | *
24 | * Connections
25 | * -----------
26 | * Break out | Arduino Uno
27 | * -----------------------------
28 | * VCC | 5V
29 | * GND | GND
30 | * OUT | 4
31 | *
32 | * Also connect an LED to simulate a controlled device.
33 | * 220 Ohm
34 | * 3 ----/\/\/\/\----(LED |)----GND
35 |
36 | *
37 | * Other information
38 | * -----------------
39 | * For information on PIR sensors: https://en.wikipedia.org/wiki/Passive_infrared_sensor
40 | * Datasheet: https://www.mpja.com/download/31227sc.pdf
41 | *
42 | * Created on October 14 2016 by Peter Dalmaris
43 | *
44 | */
45 |
46 | int ledPin = 4; // choose the pin for the LED
47 | int inputPin = 3; // choose the input pin (for PIR sensor)
48 | int pirState = true; // we start, assuming no motion detected
49 | int val = 0; // variable for reading the pin status
50 | int minSecAfterPIRLow = 5000; // If the sensor reports low
51 | // remain HIGH for this many milliseconds
52 | long unsigned int timeTurnedLow;
53 | boolean takeLowTime; //This variable is used to record the event where the sensor turns off
54 |
55 | //the time we give the sensor to calibrate (10-60 secs according to the datasheet)
56 | int calibrationTime = 30;
57 |
58 | void setup() {
59 | pinMode(ledPin, OUTPUT); // declare LED as output
60 | pinMode(inputPin, INPUT); // declare sensor as input
61 |
62 | takeLowTime = LOW;
63 |
64 | Serial.begin(9600);
65 |
66 | Serial.println("Waiting for the sensor to warm up.");
67 | delay(calibrationTime * 1000); // Convert the time from seconds to milliseconds.
68 | Serial.println("SENSOR ACTIVE");
69 | }
70 |
71 | void loop(){
72 | val = digitalRead(inputPin); // read input value
73 |
74 | if (val == HIGH) { // check if the input is HIGH
75 | digitalWrite(ledPin, HIGH); // turn LED ON
76 | if (pirState == LOW) {
77 | // we have just turned on
78 | Serial.println("Motion detected!");
79 | // We only want to print on the output change, not state
80 | pirState = HIGH;
81 | }
82 | } else {
83 |
84 | if (pirState == HIGH){
85 | // we have just turned off
86 | Serial.println("Motion ended!");
87 | // We only want to print on the output change, not state
88 | pirState = LOW;
89 | timeTurnedLow = millis(); //take the millis at the moment the sensor went LOW
90 | }
91 | }
92 |
93 | //This block checks to see if enough time has passed after the PRI went LOW.
94 | //If yes, and assuming that the PIR sensor did not go HIGH again, turn off the LED
95 | if(!pirState && (millis() - timeTurnedLow) > minSecAfterPIRLow){
96 | Serial.println("Extended time HIGH ended!");
97 | digitalWrite(ledPin, LOW); // turn LED OFF
98 | }
99 |
100 | delay(1000);
101 | }
102 |
103 |
--------------------------------------------------------------------------------
/_0510_-_Ultrasonic_Distance_Sensor/_0510_-_Ultrasonic_Distance_Sensor.ino:
--------------------------------------------------------------------------------
1 | /* Ultrasonic distance sensor HC-SR04 demo sketch
2 | *
3 | * This sketch calculates the distance between the HC-SR04 sensor and
4 | * an object directly infront of it.
5 | *
6 | *
7 | * This sketch was written for Arduino Step by Step by Peter Dalmaris.
8 | *
9 | * Components
10 | * ----------
11 | * - Arduino Uno
12 | * - HC-SR04 sensor
13 | *
14 | * Libraries
15 | * ---------
16 | * - NONE
17 | *
18 | * Connections
19 | * -----------
20 | * Break out | Arduino Uno
21 | * -----------------------------
22 | * VCC | 5V
23 | * GND | GND
24 | * Echo | 12
25 | * Trig | 13
26 | *
27 | *
28 | * Other information
29 | * -----------------
30 | * For information on the ultrasonic transducer: https://en.wikipedia.org/wiki/Ultrasonic_transducer
31 | * For information on ultrasounds: https://en.wikipedia.org/wiki/Ultrasound
32 | * HC-SR04 datasheet: https://docs.google.com/document/d/1Y-yZnNhMYy7rwhAgyL_pfa39RsB-x2qR4vP8saG73rE
33 | * Information about the pulseIn function: https://www.arduino.cc/en/Reference/PulseIn
34 | *
35 | * Created on October 21 2016 by Peter Dalmaris
36 | *
37 | */
38 |
39 |
40 | #define trigPin 13
41 | #define echoPin 12
42 |
43 | void setup() {
44 | Serial.begin (9600);
45 | pinMode(trigPin, OUTPUT);
46 | pinMode(echoPin, INPUT);
47 | }
48 |
49 | void loop() {
50 | long duration, distance;
51 | digitalWrite(trigPin, LOW);
52 | delayMicroseconds(2);
53 | digitalWrite(trigPin, HIGH);
54 | delayMicroseconds(10);
55 | digitalWrite(trigPin, LOW);
56 | duration = pulseIn(echoPin, HIGH);
57 | distance = (duration/2) / 29.1;
58 |
59 | if (distance >= 200 || distance <= 0){
60 | Serial.println("Out of range");
61 | }
62 | else {
63 | Serial.print(distance);
64 | Serial.println(" cm");
65 | }
66 | delay(500);
67 | }
68 |
--------------------------------------------------------------------------------
/_0520_-_Acceleration_ADXL335_-_1/_0520_-_Acceleration_ADXL335_-_1.ino:
--------------------------------------------------------------------------------
1 | /* ADXL335 3-axis acceleration sensor demo sketch 1
2 | *
3 | * This sketch gets raw X-Y-Z acceleration readings from the
4 | * ADXL335 sensor.
5 | *
6 | * The readings come from any 3 available analog inputs, but in this
7 | * sketch we will use A3, A2 and A1.
8 | *
9 | * Notice that the breakout only works at 3.3V voltage level. Therefore,
10 | * connect Vcc to the Arduino's 3.3V pin. To ensure that the Arduino analog
11 | * inputs are sampled at that level, connect the breakout VCC to the
12 | * Arduino HREF pin.
13 | *
14 | * This sketch was written for Arduino Step by Step by Peter Dalmaris.
15 | *
16 | * Components
17 | * ----------
18 | * - Arduino Uno
19 | * - ADXL335 sensor breakout or equivelant
20 | *
21 | * Libraries
22 | * ---------
23 | * - NONE
24 | *
25 | * Connections
26 | * -----------
27 | * Break out | Arduino Uno
28 | * -----------------------------
29 | * VCC | 3.3V
30 | * GND | GND
31 | * X | A3
32 | * Y | A2
33 | * Z | A1
34 | * VCC | AREF This will ensure that the Arduino uses 0-3.3V as the sampling range
35 | *
36 | * You can also simply plug the ADXL335 breakout directly onto the analog pins header,
37 | * orienting it so that the axis pins plug into the header as per the connections table above.
38 | * If you do the connection this way, then Vcc will be connected to A5 and GND to A4. Remember to
39 | * uncomment the relevant lines in the setup function in order to properly power the sensor.
40 |
41 | *
42 | * Other information
43 | * -----------------
44 | * For information on acceleration: https://en.wikipedia.org/wiki/Acceleration
45 | * ADXL335 datasheet: http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL335.pdf
46 | *
47 | * As per the datasheet, the sensitivity of the sensor is ~300mV/g at 3V. We can use this information
48 | * to convert the analog reading into G-force reading (not implemented in this sketch).
49 | *
50 | * Created on October 8 2016 by Peter Dalmaris
51 | *
52 | */
53 |
54 |
55 | int X_axis = A3;
56 | int Y_axis = A2;
57 | int Z_axis = A1;
58 |
59 | const int groundpin = 18; // analog input pin 4 -- ground
60 | // Analog pins can be treated as digital pins.
61 | // Analog pin 4 corresponds to digital pin 18.
62 | const int powerpin = 19; // analog input pin 5 -- voltage
63 | // Analog pin 5 corresponds to digital pin 19
64 |
65 | int x, y, z; // These variables will hold the raw sensor values.
66 |
67 | void setup()
68 | {
69 | //analogReference(EXTERNAL); // This configures the analog to digital converter so that it
70 | // uses the AREF voltage. If you have connected the 3.3V
71 | // pin to the AREF pin on the Arduino, then the AREF voltage is 3.3V.
72 | // If you have pluged the breakout directly into the analog header
73 | // leave analogReference commented out.
74 |
75 | // Provide ground and power by using the analog inputs as normal
76 | // digital pins. This makes it possible to directly connect the
77 | // breakout board to the Arduino. If you use the normal 5V and
78 | // GND pins on the Arduino, you can remove these lines.
79 | pinMode(groundpin, OUTPUT);
80 | pinMode(powerpin, OUTPUT);
81 | digitalWrite(groundpin, LOW);
82 | digitalWrite(powerpin, HIGH);
83 |
84 | Serial.begin(9600); // sets the serial port to 9600
85 |
86 | delay(1000);
87 | }
88 |
89 | void loop()
90 | {
91 | x = analogRead(X_axis); // read analog input pin 0
92 | y = analogRead(Y_axis); // read analog input pin 1
93 | z = analogRead(Z_axis); // read analog input pin 1
94 |
95 | Serial.print(x); // print the raw value in the X axis
96 | Serial.print("\t"); // prints a tab between the numbers
97 | Serial.print(y); // print the raw value in the Y axis
98 | Serial.print("\t"); // prints a tab between the numbers
99 | Serial.print(z); // print the raw value in the Z axis
100 | Serial.println();
101 |
102 | delay(100); // wait 100ms for next reading
103 | }
104 |
--------------------------------------------------------------------------------
/_0520_-_Acceleration_ADXL335_-_2/_0520_-_Acceleration_ADXL335_-_2.ino:
--------------------------------------------------------------------------------
1 | /* ADXL335 3-axis acceleration sensor demo sketch 2
2 | *
3 | * This sketch gets raw X-Y-Z acceleration readings from the
4 | * ADXL335 sensor.
5 | *
6 | * Then, using those values, the sketch calculates the orientation of the Arduino.
7 | *
8 | * The readings come from any 3 available analog inputs, but in this
9 | * sketch we will use A3, A2 and A1.
10 | *
11 | * Notice that the breakout only works at 3.3V voltage level. Therefore,
12 | * connect Vcc to the Arduino's 3.3V pin. To ensure that the Arduino analog
13 | * inputs are sampled at that level, connect the breakout VCC to the
14 | * Arduino HREF pin.
15 | *
16 | * This sketch was written for Arduino Step by Step by Peter Dalmaris.
17 | *
18 | * Components
19 | * ----------
20 | * - Arduino Uno
21 | * - ADXL335 sensor breakout or equivelant
22 | *
23 | * Libraries
24 | * ---------
25 | * - NONE
26 | *
27 | * Connections
28 | * -----------
29 | * Break out | Arduino Uno
30 | * -----------------------------
31 | * VCC | 3.3V
32 | * GND | GND
33 | * X | A3
34 | * Y | A2
35 | * Z | A1
36 | * VCC | AREF This will ensure that the Arduino uses 0-3.3V as the sampling range
37 | *
38 | * You can also simply plug the ADXL335 breakout directly onto the analog pins header,
39 | * orienting it so that the axis pins plug into the header as per the connections table above.
40 | * If you do the connection this way, then Vcc will be connected to A5 and GND to A4. Remember to
41 | * uncomment the relevant lines in the setup function in order to properly power the sensor.
42 |
43 | *
44 | * Other information
45 | * -----------------
46 | * For information on acceleration: https://en.wikipedia.org/wiki/Acceleration
47 | * ADXL335 datasheet: http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL335.pdf
48 | *
49 | * As per the datasheet, the sensitivity of the sensor is ~300mV/g at 3V. We can use this information
50 | * to convert the analog reading into G-force reading (not implemented in this sketch).
51 | *
52 | * Created on October 8 2016 by Peter Dalmaris
53 | *
54 | */
55 |
56 |
57 | int X_axis = A3;
58 | int Y_axis = A2;
59 | int Z_axis = A1;
60 |
61 | const int groundpin = 18; // analog input pin 4 -- ground
62 | // Analog pins can be treated as digital pins.
63 | // Analog pin 4 corresponds to digital pin 18.
64 | const int powerpin = 19; // analog input pin 5 -- voltage
65 | // Analog pin 5 corresponds to digital pin 19
66 |
67 | int x, y, z; // These variables will hold the raw sensor values.
68 |
69 | void setup()
70 | {
71 | //analogReference(EXTERNAL); // This configures the analog to digital converter so that it
72 | // uses the AREF voltage. If you have connected the 3.3V
73 | // pin to the AREF pin on the Arduino, then the AREF voltage is 3.3V.
74 | // If you have pluged the breakout directly into the analog header
75 | // leave analogReference commented out.
76 |
77 | // Provide ground and power by using the analog inputs as normal
78 | // digital pins. This makes it possible to directly connect the
79 | // breakout board to the Arduino. If you use the normal 5V and
80 | // GND pins on the Arduino, you can remove these lines.
81 | pinMode(groundpin, OUTPUT);
82 | pinMode(powerpin, OUTPUT);
83 | digitalWrite(groundpin, LOW);
84 | digitalWrite(powerpin, HIGH);
85 |
86 | Serial.begin(9600); // sets the serial port to 9600
87 |
88 | delay(1000);
89 | }
90 |
91 | void loop()
92 | {
93 | x = analogRead(X_axis); // read analog input pin 0
94 | y = analogRead(Y_axis); // read analog input pin 1
95 | z = analogRead(Z_axis); // read analog input pin 1
96 |
97 | Serial.print(x); // print the raw value in the X axis
98 | Serial.print("\t"); // prints a tab between the numbers
99 | Serial.print(y); // print the raw value in the Y axis
100 | Serial.print("\t"); // prints a tab between the numbers
101 | Serial.print(z); // print the raw value in the Z axis
102 | Serial.print("\t");
103 | // Serial.println();
104 |
105 | if ((x>505 && x<515) && (y>495 && y<510) && (z>610 && z<625))
106 | {
107 |
108 | Serial.println("I am horizontal");
109 | }
110 | else if((x>505 && x<515) && (y>485 && y<510) && (z>410 && z<430))
111 | {
112 | Serial.println("I am flipped;");
113 | }
114 | else
115 | {
116 | Serial.println("I don't know which way I'm sitting!");
117 | }
118 |
119 | //Can you implement the code that helps the Arduino determine other orientations,
120 | //such as sitting on its long header, or on the connectors side?
121 |
122 | delay(100); // wait 100ms for next reading
123 | }
124 |
--------------------------------------------------------------------------------
/_0520_-_Acceleration_ADXL335_-_3/_0520_-_Acceleration_ADXL335_-_3.ino:
--------------------------------------------------------------------------------
1 | /* ADXL335 3-axis acceleration sensor demo sketch 2
2 | *
3 | * This sketch gets X-Y-Z acceleration readings from the
4 | * ADXL335 sensor and calculates the G-force for each axis.
5 | *
6 | * The readings come from any 3 available analog inputs.
7 | *
8 | * Notice that the breakout only works at 3.3V voltage level. Therefore,
9 | * connect Vcc to the Arduino's 3.3V pin. To ensure that the Arduino analog
10 | * inputs are sampled at that level, connect the breakout VCC to the
11 | * Arduino HREF pin.
12 | *
13 | * This sketch was written for Arduino Step by Step by Peter Dalmaris.
14 | *
15 | * Components
16 | * ----------
17 | * - Arduino Uno
18 | * - ADXL335 sensor breakout or equivelant
19 | *
20 | * Libraries
21 | * ---------
22 | * - NONE
23 | *
24 | * Connections
25 | * -----------
26 | * Break out | Arduino Uno
27 | * -----------------------------
28 | * VCC | 3.3V
29 | * GND | GND
30 | * X | A0
31 | * Y | A1
32 | * Z | A2
33 | * VCC | AREF This will ensure that the Arduino uses 0-3.3V as the sampling range
34 |
35 | *
36 | * Other information
37 | * -----------------
38 | * For information on acceleration: https://en.wikipedia.org/wiki/Acceleration
39 | * ADXL335 datasheet: http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL335.pdf
40 | *
41 | * As per the datasheet, the sensitivity of the sensor is ~300mV/g at 3V. We can use this information
42 | * to convert the analog reading into G-force reading.
43 | *
44 | * Created on October 8 2016 by Peter Dalmaris
45 | *
46 | */
47 |
48 | int x, y, z; // Use these variables to store the acceleration readings
49 | double x_volt, y_volt, z_volt; // To calculate G-forces I must first calculate voltages
50 | double x_g, y_g, z_g; // These vars will hold the G-forces
51 |
52 | int X_axis = 3;
53 | int Y_axis = 2;
54 | int Z_axis = 1;
55 |
56 | double largest_x, largest_y, largest_z;
57 |
58 | double zero_g_voltage;
59 |
60 |
61 | double sensitivity = 0.300; // 0.300 V/g
62 |
63 | char outstr[5]; // These char arrays are used to
64 | // format the final results into
65 | // a number with only 1 decimal.
66 |
67 | void setup()
68 | {
69 | Serial.begin(9600); // sets the serial port to 9600
70 | largest_x = 0;
71 | largest_y = 0;
72 | largest_z = 0;
73 |
74 | delay(1000);
75 | x = analogRead(X_axis); //Take a reading in x-axis to establish zero-g voltage
76 | zero_g_voltage = x;
77 | }
78 |
79 | void loop()
80 | {
81 | x = analogRead(X_axis); // read analog input pin 0
82 | y = analogRead(Y_axis); // read analog input pin 1
83 | z = analogRead(Z_axis); // read analog input pin 1
84 |
85 | x_volt = x * 3.3 / 1023;
86 | y_volt = y * 3.3 / 1023;
87 | z_volt = z * 3.3 / 1023;
88 |
89 | x_g = (x_volt-zero_g_voltage) / sensitivity;
90 | y_g = (y_volt-zero_g_voltage) / sensitivity;
91 | z_g = (z_volt-zero_g_voltage) / sensitivity;
92 |
93 | if (largest_x < x_g)
94 | largest_x = x_g;
95 |
96 | if (largest_y < y_g)
97 | largest_y = y_g;
98 |
99 | if (largest_z < z_g)
100 | largest_z = z_g;
101 |
102 |
103 | // dtostrf(largest_y,3, 1, outstr_y);
104 | // dtostrf(largest_z,3, 1, outstr_z);
105 |
106 | Serial.print("G-forces are x, y, z, largest x-y-z: ");
107 | Serial.print(x, DEC); // print the acceleration in the X axis
108 | Serial.print(" "); // prints a space between the numbers
109 | Serial.print(y, DEC); // print the acceleration in the Y axis
110 | Serial.print(" "); // prints a space between the numbers
111 | Serial.print(z, DEC); // print the acceleration in the Z axis
112 | Serial.print(", ");
113 | dtostrf(largest_x,3, 1, outstr);
114 | Serial.print(outstr);
115 | Serial.print(" - ");
116 | dtostrf(largest_y,3, 1, outstr);
117 | Serial.print(outstr);
118 | Serial.print(" - ");
119 | dtostrf(largest_z,3, 1, outstr);
120 | Serial.print(outstr);
121 | Serial.print(", zero G: ");
122 | Serial.println(zero_g_voltage);
123 | delay(100); // wait 100ms for next reading
124 | }
125 |
--------------------------------------------------------------------------------
/_0560_-_Analog_microphone/_0560_-_Analog_microphone.ino:
--------------------------------------------------------------------------------
1 | /* Analog microphone demo sketch
2 | *
3 | * This sketch detects loud noises using an analog electrelet microphone.
4 | *
5 | * This sketch was written for Arduino Step by Step by Peter Dalmaris.
6 | *
7 | * Components
8 | * ----------
9 | * - Arduino Uno
10 | * - Analog electrelet microphone
11 | *
12 | * Libraries
13 | * ---------
14 | * - None
15 | *
16 | * Connections
17 | * -----------
18 | * Break out | Arduino Uno
19 | * -----------------------------
20 | * VCC | 5V
21 | * GND | GND
22 | * AUD | A0
23 |
24 | *
25 | * Other information
26 | * -----------------
27 | * This code is useful if you want to do things like detect a knock on a door,
28 | * hands clapping, etc.
29 | *
30 | * Created on October 14 2016 by Peter Dalmaris
31 | *
32 | */
33 |
34 | int currentValue;
35 | int maxValue;
36 | int minValue;
37 | unsigned long timer;
38 | int sampleSpan = 200; // Amount in milliseconds to sample data
39 | int volume; // this roughly goes from 0 to 700
40 | int ledpin = 7;
41 |
42 | void setup()
43 | {
44 | Serial.begin(9600);
45 | pinMode (ledpin, OUTPUT);
46 | resetValues();
47 | }
48 |
49 | void loop()
50 | {
51 | currentValue = analogRead(A0);
52 |
53 | if (currentValue < minValue) {
54 | minValue = currentValue;
55 | }
56 | if (currentValue > maxValue) {
57 | maxValue = currentValue;
58 | }
59 |
60 | if (millis() - timer >= sampleSpan) {
61 | volume = maxValue - minValue;
62 | //Serial.println(volume);
63 | resetValues();
64 | }
65 |
66 | // I arbitrarily select 100 as the value above which the
67 | //microphone is picking a loud noise.
68 | if (volume > 400)
69 | {
70 | Serial.println("Loud");
71 | digitalWrite(ledpin,HIGH);
72 | } else
73 | {
74 | Serial.println("Quiet");
75 | digitalWrite(7,LOW);
76 | }
77 |
78 | }
79 |
80 | void resetValues()
81 | {
82 | maxValue = 0;
83 | minValue = 1024;
84 | timer = millis();
85 | }
86 |
--------------------------------------------------------------------------------
/_0560_-_Digital_sound_sensor/_0560_-_Digital_sound_sensor.ino:
--------------------------------------------------------------------------------
1 | /* Digital sound sensor demo sketch
2 | *
3 | * This sketch detects loud noises using a digital sound sensor.
4 | *
5 | * When the sensor detects a loud noise, it sends a message to the
6 | * serial monitor.
7 | *
8 | * This sketch was written for Arduino Step by Step by Peter Dalmaris.
9 | *
10 | * Components
11 | * ----------
12 | * - Arduino Uno
13 | * - Digital sound sensor
14 | *
15 | * Libraries
16 | * ---------
17 | * - None
18 | *
19 | * Connections
20 | * -----------
21 | * Break out | Arduino Uno
22 | * -----------------------------
23 | * + | 5V
24 | * G | GND
25 | * D0 | 10
26 |
27 | *
28 | * Other information
29 | * -----------------
30 | * This code is useful if you want to do things like detect a knock on a door,
31 | * hands clapping, etc.
32 | *
33 | * Created on October 14 2016 by Peter Dalmaris
34 | *
35 | */
36 |
37 | int soundDetectedPin = 10; // Use Pin 10 as our Input
38 | int soundDetectedVal = HIGH; // This is where we record our Sound Measurement
39 | boolean bAlarm = false;
40 | unsigned long lastSoundDetectTime; // Record the time that we measured a sound
41 | int soundAlarmTime = 500; // Number of milli seconds to keep the sound alarm high
42 | int ledpin = 7;
43 |
44 | void setup ()
45 | {
46 | Serial.begin(9600);
47 | pinMode (soundDetectedPin, INPUT) ; // input from the Sound Detection Module
48 | pinMode (ledpin, OUTPUT); // The built-in LED on pin 13 will light
49 | // up when there is a noise.
50 | }
51 | void loop ()
52 | {
53 | soundDetectedVal = digitalRead (soundDetectedPin) ; // read the sound alarm time
54 | if (soundDetectedVal == HIGH) // If we hear a sound
55 | {
56 | digitalWrite(ledpin,HIGH); // Turn the LED on to show there was a loud noise
57 | lastSoundDetectTime = millis(); // record the time of the sound alarm
58 | // This will output the LOUD message only once even if the signal remains
59 | // at HIGH. This way it will not scroll out of the window with the same message.
60 | if (!bAlarm){
61 | Serial.println("LOUD!");
62 | bAlarm = true;
63 | }
64 | }
65 |
66 | if( (millis()-lastSoundDetectTime) > soundAlarmTime && bAlarm){
67 | Serial.println("quiet");
68 | digitalWrite(ledpin,LOW);
69 | bAlarm = false;
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/_0570_-_Hall_Effect_sensor/_0570_-_Hall_Effect_sensor.ino:
--------------------------------------------------------------------------------
1 | /* Hall Effect sensor demo sketch
2 | *
3 | * This sketch demonstrates the use of a simple Hall Effect sensor.
4 | * The sensor works like a button. When a magnet is near it, the sensor
5 | * closes and the LED on Pin 13 turns on.
6 | *
7 | * This sketch was written for Arduino Step by Step by Peter Dalmaris.
8 | *
9 | * Components
10 | * ----------
11 | * - Arduino Uno
12 | * - Hall Effect sensor, like the USB1542 or equivelant
13 | * - 10 KOhm resistor for pull-up.
14 | *
15 | * Libraries
16 | * ---------
17 | * - None
18 | *
19 | * Connections
20 | * -----------
21 | *
22 | * Looking at the sensor facing the text:
23 | *
24 | * Sensor | Arduino Uno
25 | * -----------------------------
26 | * 1 | 5V
27 | * 2 | GND
28 | * 3 | 2
29 | *
30 | * Connect the resistor between sensor pins 1 and 3.
31 | *
32 | *
33 | * Other information
34 | * -----------------
35 | * For information on the Hall effect sensor: https://en.wikipedia.org/wiki/Hall_effect_sensor
36 | *
37 | * Created on October 8 2016 by Peter Dalmaris
38 | *
39 | */
40 |
41 | // constants won't change. They're used here to
42 | // set pin numbers:
43 | const int sensor = 2; // the number of the pushbutton pin
44 | const int ledPin = 13; // the number of the LED pin
45 |
46 | // variables will change:
47 | int buttonState = 0; // variable for reading the pushbutton status
48 |
49 | void setup() {
50 | // initialize the LED pin as an output:
51 | pinMode(ledPin, OUTPUT);
52 | // initialize the pushbutton pin as an input:
53 | pinMode(sensor, INPUT);
54 | }
55 |
56 | void loop() {
57 | // read the state of the pushbutton value:
58 | buttonState = digitalRead(sensor);
59 |
60 | // check if the pushbutton is pressed.
61 | // if it is, the buttonState is HIGH:
62 | if (buttonState == HIGH) {
63 | // turn LED on:
64 | digitalWrite(ledPin, HIGH);
65 | } else {
66 | // turn LED off:
67 | digitalWrite(ledPin, LOW);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/_0580_-_Reed_Switch/_0580_-_Reed_Switch.ino:
--------------------------------------------------------------------------------
1 | /* Reed switch demo sketch
2 | *
3 | * This sketch demonstrates the use of a Reed switch.
4 | * The sensor works like a button or a Hall effect sensor.
5 | * When a magnet is near it, the switch
6 | * closes and the LED on Pin 13 turns on.
7 | *
8 | * This sketch was written for Arduino Step by Step by Peter Dalmaris.
9 | *
10 | * Components
11 | * ----------
12 | * - Arduino Uno
13 | * - Reed switch
14 | * - 10 KOhm resistor for pull-up.
15 | *
16 | * Libraries
17 | * ---------
18 | * - None
19 | *
20 | * Connections
21 | * -----------
22 | * 10 KOhm
23 | * 5V -------(ReedSwitch)--------/\/\/\/\/\-------GND
24 | * |
25 | * |
26 | * |
27 | * |
28 | * 2
29 | *
30 | *
31 | *
32 | * Other information
33 | * -----------------
34 | * For information on the Reed switch: https://en.wikipedia.org/wiki/Reed_switch
35 | *
36 | * Created on October 8 2016 by Peter Dalmaris
37 | *
38 | */
39 |
40 | // constants won't change. They're used here to
41 | // set pin numbers:
42 | const int sensor = 2; // the number of the pushbutton pin
43 | const int ledPin = 13; // the number of the LED pin
44 |
45 | // variables will change:
46 | int buttonState = 0; // variable for reading the pushbutton status
47 |
48 | void setup() {
49 | // initialize the LED pin as an output:
50 | pinMode(ledPin, OUTPUT);
51 | // initialize the pushbutton pin as an input:
52 | pinMode(sensor, INPUT);
53 | }
54 |
55 | void loop() {
56 | // read the state of the pushbutton value:
57 | buttonState = digitalRead(sensor);
58 |
59 | // check if the pushbutton is pressed.
60 | // if it is, the buttonState is HIGH:
61 | if (buttonState == HIGH) {
62 | // turn LED on:
63 | digitalWrite(ledPin, HIGH);
64 | } else {
65 | // turn LED off:
66 | digitalWrite(ledPin, LOW);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/_0590_-_Magnetometer_Compass_HMC5883/_0590_-_Magnetometer_Compass_HMC5883.ino:
--------------------------------------------------------------------------------
1 | /* HMC5883 magnetometer sensor demo sketch 1
2 | *
3 | * This sketch show the usage of the HMC5883 sensor with the
4 | * Adafruit HMC5883 library.
5 | *
6 | * The readings come from any 3 available analog inputs.
7 | *
8 | * North is pointed by the X axis silksreen line when heading is 0 degrees.
9 | *
10 | * This sketch was adapted from the Adafruit sample for Arduino Step by Step by Peter Dalmaris.
11 | *
12 | * Components
13 | * ----------
14 | * - Arduino Uno
15 | * - HMC5883 sensor breakout or equivelant
16 | *
17 | * Libraries
18 | * ---------
19 | * - NONE
20 | *
21 | * Connections
22 | * -----------
23 | * Break out | Arduino Uno
24 | * -----------------------------
25 | * VCC | 5V
26 | * GND | GND
27 | * SCL | SCL or A5
28 | * SDA | SDA or A4
29 | * DRDY | Not connected
30 |
31 | *
32 | * Other information
33 | * -----------------
34 | * For information on magnetometers: https://en.wikipedia.org/wiki/Magnetometer
35 | * HMC5883 datasheet: https://cdn-shop.adafruit.com/datasheets/HMC5883L_3-Axis_Digital_Compass_IC.pdf
36 | * HMC5883 product page: https://www.adafruit.com/product/1746
37 | *
38 | *
39 | * Created on October 8 2016 by Peter Dalmaris
40 | *
41 | */
42 |
43 | /***************************************************************************
44 | This is a library example for the HMC5883 magnentometer/compass
45 |
46 | Designed specifically to work with the Adafruit HMC5883 Breakout
47 | http://www.adafruit.com/products/1746
48 |
49 | *** You will also need to install the Adafruit_Sensor library! ***
50 |
51 | These displays use I2C to communicate, 2 pins are required to interface.
52 |
53 | Adafruit invests time and resources providing this open source code,
54 | please support Adafruit andopen-source hardware by purchasing products
55 | from Adafruit!
56 |
57 | Written by Kevin Townsend for Adafruit Industries with some heading example from
58 | Love Electronics (loveelectronics.co.uk)
59 |
60 | This program is free software: you can redistribute it and/or modify
61 | it under the terms of the version 3 GNU General Public License as
62 | published by the Free Software Foundation.
63 |
64 | This program is distributed in the hope that it will be useful,
65 | but WITHOUT ANY WARRANTY; without even the implied warranty of
66 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67 | GNU General Public License for more details.
68 |
69 | You should have received a copy of the GNU General Public License
70 | along with this program. If not, see .
71 |
72 | ***************************************************************************/
73 |
74 | #include
75 | #include
76 | #include
77 |
78 | /* Assign a unique ID to this sensor at the same time */
79 | Adafruit_HMC5883_Unified mag = Adafruit_HMC5883_Unified(12345);
80 |
81 | void displaySensorDetails(void)
82 | {
83 | sensor_t sensor;
84 | mag.getSensor(&sensor);
85 | Serial.println("------------------------------------");
86 | Serial.print ("Sensor: "); Serial.println(sensor.name);
87 | Serial.print ("Driver Ver: "); Serial.println(sensor.version);
88 | Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);
89 | Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" uT");
90 | Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" uT");
91 | Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" uT");
92 | Serial.println("------------------------------------");
93 | Serial.println("");
94 | delay(500);
95 | }
96 |
97 | void setup(void)
98 | {
99 | Serial.begin(9600);
100 | Serial.println("HMC5883 Magnetometer Test"); Serial.println("");
101 |
102 | /* Initialise the sensor */
103 | if(!mag.begin())
104 | {
105 | /* There was a problem detecting the HMC5883 ... check your connections */
106 | Serial.println("Ooops, no HMC5883 detected ... Check your wiring!");
107 | while(1);
108 | }
109 |
110 | /* Display some basic information on this sensor */
111 | displaySensorDetails();
112 | }
113 |
114 | void loop(void)
115 | {
116 | /* Get a new sensor event */
117 | sensors_event_t event;
118 | mag.getEvent(&event);
119 |
120 | /* Display the results (magnetic vector values are in micro-Tesla (uT)) */
121 | Serial.print("X: "); Serial.print(event.magnetic.x); Serial.print(" ");
122 | Serial.print("Y: "); Serial.print(event.magnetic.y); Serial.print(" ");
123 | Serial.print("Z: "); Serial.print(event.magnetic.z); Serial.print(" ");Serial.println("uT");
124 |
125 | // Hold the module so that Z is pointing 'up' and you can measure the heading with x&y
126 | // Calculate heading when the magnetometer is level, then correct for signs of axis.
127 | float heading = atan2(event.magnetic.y, event.magnetic.x);
128 |
129 | // Once you have your heading, you must then add your 'Declination Angle', which is the 'Error' of the magnetic field in your location.
130 | // Find yours here: http://www.magnetic-declination.com/
131 | // Mine is: -13* 2' W, which is ~13 Degrees, or (which we need) 0.22 radians
132 | // If you cannot find your Declination, comment out these two lines, your compass will be slightly off.
133 | float declinationAngle = 0.21;
134 | heading += declinationAngle;
135 |
136 | // Correct for when signs are reversed.
137 | if(heading < 0)
138 | heading += 2*PI;
139 |
140 | // Check for wrap due to addition of declination.
141 | if(heading > 2*PI)
142 | heading -= 2*PI;
143 |
144 | // Convert radians to degrees for readability.
145 | float headingDegrees = heading * 180/M_PI;
146 |
147 | Serial.print("Heading (degrees): "); Serial.println(headingDegrees);
148 |
149 | delay(500);
150 | }
151 |
--------------------------------------------------------------------------------
/_0650_-_PassiveBuzzerSimple/_0650_-_PassiveBuzzerSimple.ino:
--------------------------------------------------------------------------------
1 | /* Passive buzzer demo sketch 1
2 | *
3 | * This sketch shows you how to play a tone using a passive
4 | * buzzer and the tone function that comes with the standard
5 | * Arduino library
6 | *
7 | * This sketch was written for Arduino Step by Step by Peter Dalmaris.
8 | *
9 | * Components
10 | * ----------
11 | * - Arduino Uno
12 | * - Passive buzzer with two or three pins
13 | *
14 | * Libraries
15 | * ---------
16 | * - None
17 | *
18 | * Connections
19 | * -----------
20 | * If you have a two pin passive buzzer, connect the pin marked "-"
21 | * to Arduino GND, and the other pin to Arduino pin 8.
22 | *
23 | * If you have a three pin passive buzzer, connect the pin marked "-"
24 | * to GND, the pin marked "S" to Arduino digital pin 8, and the last
25 | * pin to Arduino pin 5V.
26 | *
27 | * Created on November 21 2016 by Peter Dalmaris
28 | *
29 | */
30 |
31 | const int buzzer = 8;
32 |
33 | void setup(){
34 | pinMode(buzzer, OUTPUT); // Set buzzer - pin 8 as an output
35 | }
36 |
37 | void loop(){
38 | tone(buzzer, 1000); // Send 1KHz sound signal...
39 | delay(1000); // ...for 1 sec
40 | noTone(buzzer); // Stop sound...
41 | delay(1000); // ...for 1sec
42 | }
43 |
--------------------------------------------------------------------------------
/_0650_-_ToneMelodyBuzzer/_0650_-_ToneMelodyBuzzer.ino:
--------------------------------------------------------------------------------
1 | /* Passive buzzer demo sketch
2 | *
3 | * This sketch shows you how to play a tune using a passive
4 | * buzzer and the tone function that comes with the standard
5 | * Arduino library
6 | *
7 | * This sketch was adapted from the original that comes with the
8 | * Arduino IDE examples for Arduino Step by Step by Peter Dalmaris.
9 | *
10 | * Components
11 | * ----------
12 | * - Arduino Uno
13 | * - Passive buzzer with two or three pins
14 | *
15 | * Libraries
16 | * ---------
17 | * - None
18 | *
19 | * Connections
20 | * -----------
21 | * If you have a two-pin passive buzzer, connect the pin marked "-"
22 | * to Arduino GND, and the other pin to Arduino pin 8.
23 | *
24 | * If you have a three-pin passive buzzer, connect the pin marked "-"
25 | * to GND, the pin marked "S" to Arduino digital pin 8, and the last
26 | * pin to Arduino pin 5V.
27 | *
28 | * Created on November 21 2016 by Peter Dalmaris
29 | *
30 | */
31 |
32 | /* This is the original sketch header. */
33 | /*
34 | Melody
35 |
36 | Plays a melody
37 |
38 | circuit:
39 | * 8-ohm speaker on digital pin 8
40 |
41 | created 21 Jan 2010
42 | modified 30 Aug 2011
43 | by Tom Igoe
44 |
45 | This example code is in the public domain.
46 |
47 | http://www.arduino.cc/en/Tutorial/Tone
48 |
49 | */
50 | #include "pitches.h"
51 |
52 | // notes in the melody:
53 | int melody[] = {
54 | NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
55 | };
56 |
57 | // note durations: 4 = quarter note, 8 = eighth note, etc.:
58 | int noteDurations[] = {
59 | 4, 8, 8, 4, 4, 4, 4, 4
60 | };
61 |
62 | void setup() {
63 | // iterate over the notes of the melody:
64 | for (int thisNote = 0; thisNote < 8; thisNote++) {
65 |
66 | // to calculate the note duration, take one second
67 | // divided by the note type.
68 | //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
69 | int noteDuration = 1000 / noteDurations[thisNote];
70 | tone(8, melody[thisNote], noteDuration);
71 |
72 | // to distinguish the notes, set a minimum time between them.
73 | // the note's duration + 30% seems to work well:
74 | int pauseBetweenNotes = noteDuration * 1.30;
75 | delay(pauseBetweenNotes);
76 | // stop the tone playing:
77 | noTone(8);
78 | }
79 | }
80 |
81 | void loop() {
82 | // no need to repeat the melody.
83 | }
84 |
--------------------------------------------------------------------------------
/_0650_-_ToneMelodyBuzzer/pitches.h:
--------------------------------------------------------------------------------
1 | /*************************************************
2 | * Public Constants
3 | *************************************************/
4 |
5 | #define NOTE_B0 31
6 | #define NOTE_C1 33
7 | #define NOTE_CS1 35
8 | #define NOTE_D1 37
9 | #define NOTE_DS1 39
10 | #define NOTE_E1 41
11 | #define NOTE_F1 44
12 | #define NOTE_FS1 46
13 | #define NOTE_G1 49
14 | #define NOTE_GS1 52
15 | #define NOTE_A1 55
16 | #define NOTE_AS1 58
17 | #define NOTE_B1 62
18 | #define NOTE_C2 65
19 | #define NOTE_CS2 69
20 | #define NOTE_D2 73
21 | #define NOTE_DS2 78
22 | #define NOTE_E2 82
23 | #define NOTE_F2 87
24 | #define NOTE_FS2 93
25 | #define NOTE_G2 98
26 | #define NOTE_GS2 104
27 | #define NOTE_A2 110
28 | #define NOTE_AS2 117
29 | #define NOTE_B2 123
30 | #define NOTE_C3 131
31 | #define NOTE_CS3 139
32 | #define NOTE_D3 147
33 | #define NOTE_DS3 156
34 | #define NOTE_E3 165
35 | #define NOTE_F3 175
36 | #define NOTE_FS3 185
37 | #define NOTE_G3 196
38 | #define NOTE_GS3 208
39 | #define NOTE_A3 220
40 | #define NOTE_AS3 233
41 | #define NOTE_B3 247
42 | #define NOTE_C4 262
43 | #define NOTE_CS4 277
44 | #define NOTE_D4 294
45 | #define NOTE_DS4 311
46 | #define NOTE_E4 330
47 | #define NOTE_F4 349
48 | #define NOTE_FS4 370
49 | #define NOTE_G4 392
50 | #define NOTE_GS4 415
51 | #define NOTE_A4 440
52 | #define NOTE_AS4 466
53 | #define NOTE_B4 494
54 | #define NOTE_C5 523
55 | #define NOTE_CS5 554
56 | #define NOTE_D5 587
57 | #define NOTE_DS5 622
58 | #define NOTE_E5 659
59 | #define NOTE_F5 698
60 | #define NOTE_FS5 740
61 | #define NOTE_G5 784
62 | #define NOTE_GS5 831
63 | #define NOTE_A5 880
64 | #define NOTE_AS5 932
65 | #define NOTE_B5 988
66 | #define NOTE_C6 1047
67 | #define NOTE_CS6 1109
68 | #define NOTE_D6 1175
69 | #define NOTE_DS6 1245
70 | #define NOTE_E6 1319
71 | #define NOTE_F6 1397
72 | #define NOTE_FS6 1480
73 | #define NOTE_G6 1568
74 | #define NOTE_GS6 1661
75 | #define NOTE_A6 1760
76 | #define NOTE_AS6 1865
77 | #define NOTE_B6 1976
78 | #define NOTE_C7 2093
79 | #define NOTE_CS7 2217
80 | #define NOTE_D7 2349
81 | #define NOTE_DS7 2489
82 | #define NOTE_E7 2637
83 | #define NOTE_F7 2794
84 | #define NOTE_FS7 2960
85 | #define NOTE_G7 3136
86 | #define NOTE_GS7 3322
87 | #define NOTE_A7 3520
88 | #define NOTE_AS7 3729
89 | #define NOTE_B7 3951
90 | #define NOTE_C8 4186
91 | #define NOTE_CS8 4435
92 | #define NOTE_D8 4699
93 | #define NOTE_DS8 4978
94 |
95 |
96 |
--------------------------------------------------------------------------------
/_0700a_-_LCD_display/_0700a_-_LCD_display.ino:
--------------------------------------------------------------------------------
1 | /* LCD screen demo sketch
2 | *
3 | * This sketch shows you how to use the 16x2 LCD display in
4 | * 4-bit mode with the Arduino Uno.
5 | *
6 | * The LiquidCrystal
7 | * library works with all LCD displays that are compatible with the
8 | * Hitachi HD44780 driver. There are many of them out there, and you
9 | * can usually tell them by the 16-pin interface.
10 | *
11 | * Components
12 | * ----------
13 | * - Arduino Uno
14 | * - 10KOhm potentiometer
15 | * - jumper wires
16 | * - Breadboard
17 | *
18 | * Libraries
19 | * ---------
20 | * - LiquidCrystal (comes with Arduino IDE)
21 | *
22 | * Connections
23 | * -----------
24 | * LCD screen | Arduino Uno
25 | * -----------------------------
26 | * 1 (Vss) | GND
27 | * 2 (Vdd) | 5V
28 | * 3 (VO) | Potentiometer
29 | * 4 (RS) | 12
30 | * 5 (RW) | GND
31 | * 6 (E) | 11
32 | * 7 (D0) | Not connected
33 | * 8 (D1) | Not connected
34 | * 9 (D2) | Not connected
35 | * 10 (D3) | Not connected
36 | * 11 (D4) | 5
37 | * 12 (D5) | 4
38 | * 13 (D6) | 3
39 | * 14 (D7) | 2
40 | * 15 (A) | 5V
41 | * 16 (K) | GND
42 | *
43 | * For the potentiometer, connect the middle pin
44 | * to pin 3 (V0) of the display. The other two, connect
45 | * to 5V and GND. It doesn't matter which pin goes to
46 | * 5V and to GND.
47 | *
48 | * Other information
49 | * -----------------
50 | * For information on the LiquidCrystal library: https://www.arduino.cc/en/Reference/LiquidCrystal
51 | *
52 | * Created on November 18 2016 by Peter Dalmaris
53 | *
54 | */
55 |
56 | // include the library code:
57 | #include
58 |
59 | // initialize the library with the numbers of the interface pins
60 | LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
61 |
62 | void setup() {
63 | // set up the LCD's number of columns and rows:
64 | lcd.begin(16, 2);
65 | // Print a message to the LCD.
66 | lcd.print("hello, world!");
67 | }
68 |
69 | void loop() {
70 | // set the cursor to column 0, line 1
71 | // (note: line 1 is the second row, since counting begins with 0):
72 | lcd.setCursor(0, 1);
73 | // print the number of seconds since reset:
74 | lcd.print(millis()/1000);
75 | }
76 |
--------------------------------------------------------------------------------
/_0700b_-_LCD_display_with_DHT_sensor/_0700b_-_LCD_display_with_DHT_sensor.ino:
--------------------------------------------------------------------------------
1 | /* LCD screen with DHT22 sensor demo sketch
2 | *
3 | * This sketch shows you how to use the 16x2 LCD display in
4 | * 4-bit mode with the Arduino Uno, and display data from
5 | * the DHT22 sensor.
6 | *
7 | * The LiquidCrystal library works with all LCD displays that are
8 | * compatible with the Hitachi HD44780 driver. There are many
9 | * of them out there, and you can usually tell them by the
10 | * 16-pin interface.
11 | *
12 | * Components
13 | * ----------
14 | * - Arduino Uno
15 | * - 10KOhm potentiometer
16 | * - DHT22
17 | * - 10KOhm resistor for the sensor
18 | * - jumper wires
19 | * - Breadboard
20 | *
21 | * Libraries
22 | * ---------
23 | * - LiquidCrystal (comes with Arduino IDE)
24 | * - DHT
25 | *
26 | * Connections
27 | * -----------
28 | * LCD screen | Arduino Uno
29 | * -----------------------------
30 | * 1 (Vss) | GND
31 | * 2 (Vdd) | 5V
32 | * 3 (VO) | Potentiometer
33 | * 4 (RS) | 12
34 | * 5 (RW) | GND
35 | * 6 (E) | 11
36 | * 7 (D0) | Not connected
37 | * 8 (D1) | Not connected
38 | * 9 (D2) | Not connected
39 | * 10 (D3) | Not connected
40 | * 11 (D4) | 5
41 | * 12 (D5) | 4
42 | * 13 (D6) | 3
43 | * 14 (D7) | 2
44 | * 15 (A) | 5V
45 | * 16 (K) | GND
46 | *
47 | * For the potentiometer, connect the middle pin
48 | * to pin 3 (V0) of the display. The other two, connect
49 | * to 5V and GND. It doesn't matter which pin goes to
50 | * 5V and to GND.
51 | *
52 | * For the DHT22:
53 | *
54 | * * Hold the sensor so that the grill is towards you. Here are the connections
55 | *
56 | * -----------
57 | * | - | - |
58 | * | - | - |
59 | * | - | - |
60 | * | - | - |
61 | * -----------
62 | * | | | |
63 | * | | | |
64 | * | | | |
65 | * | | | |
66 | * 5V 2 GND
67 | * data
68 | *
69 | * Connect a 10KOhm resistor between the 5V and data pin (2)
70 | *
71 | * Other information
72 | * -----------------
73 | * For information on the LiquidCrystal library: https://www.arduino.cc/en/Reference/LiquidCrystal
74 | *
75 | * Created on November 18 2016 by Peter Dalmaris
76 | *
77 | */
78 |
79 | #include
80 | #include "DHT.h"
81 |
82 | #define DHTPIN 7 // what pin we're connected to
83 | #define DHTTYPE DHT22 // DHT 22 (AM2302)
84 | DHT dht(DHTPIN, DHTTYPE);
85 |
86 | // initialize the library with the numbers of the interface pins
87 | LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
88 |
89 | void setup() {
90 | // set up the LCD's number of columns and rows:
91 | lcd.begin(16, 2);
92 | // Print a message to the LCD.
93 | lcd.print("DHT test");
94 | dht.begin();
95 | }
96 |
97 | void loop() {
98 | float h = dht.readHumidity();
99 | float t = dht.readTemperature();
100 |
101 | // check if returns are valid, if they are NaN (not a number) then something went wrong!
102 | if (isnan(t) || isnan(h)) {
103 | lcd.clear();
104 | lcd.setCursor(0, 0);
105 | lcd.print("Can't get reading");
106 | lcd.setCursor(0, 1);
107 | lcd.print("from DHT");
108 |
109 | } else {
110 | lcd.clear();
111 | lcd.setCursor(0, 0);
112 | lcd.print("Hum: ");
113 | lcd.print(h);
114 | lcd.print(" %");
115 | lcd.setCursor(0, 1);
116 | lcd.print("Temp: ");
117 | lcd.print(t);
118 | lcd.print(" *C");
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/_0710_-_LCD_I2C/_0710_-_LCD_I2C.ino:
--------------------------------------------------------------------------------
1 | /* LCD screen with the I2C backpack demo sketch
2 | *
3 | * This sketch shows you how to use the 16x2 LCD display
4 | * using the I2C backpack adaptor. This way, we can save a
5 | * lot of digital pins on the Arduino.
6 | *
7 | * This I2C LCD backpack contains the PCF8574 port-expander
8 | * IC. Beware that this sketch can work with backpacks that
9 | * contains this IC, but may not work with variations.
10 | *
11 | *
12 | * Components
13 | * ----------
14 | * - Arduino Uno
15 | * - An I2C to LCD backpack adaptor
16 | * - jumper wires
17 | * - Breadboard
18 | *
19 | * Libraries
20 | * ---------
21 | * - LCD
22 | * - LiquidCrystal_I2C
23 | *
24 | * Connections
25 | * -----------
26 | * I2C backpack | Arduino Uno
27 | * -----------------------------
28 | * GND | GND
29 | * Vcc | 5V
30 | * SDA | SDA or A4
31 | * SCL | SCL or A5
32 | *
33 | *
34 | * Other information
35 | * -----------------
36 | * For information on the LiquidCrystal library: https://github.com/marcoschwartz/LiquidCrystal_I2C
37 | *
38 | * Created on November 18 2016 by Peter Dalmaris
39 | *
40 | */
41 |
42 | #include
43 |
44 | LiquidCrystal_I2C lcd(0x27,16,2);
45 |
46 | void setup()
47 | {
48 | lcd.init();
49 | lcd.backlight();
50 | lcd.setCursor(0, 0);
51 | lcd.print("Hello world!");
52 | lcd.setCursor(0, 1);
53 | lcd.print("Row number: ");
54 | lcd.setCursor(12, 1);
55 | lcd.print("2");
56 | }
57 | void loop()
58 | {
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/_0720_-_Adafruit_LCD_shield/_0720_-_Adafruit_LCD_shield.ino:
--------------------------------------------------------------------------------
1 | /* Adafruit RGB Character LCD Shield demo sketch
2 | *
3 | * This sketch shows you how to use the Adafruit RGB Character
4 | * LCD with buttons shield for the Arduino
5 | *
6 | * This shield contains a 16x2 RGB LCD screen, 4 directional
7 | * buttons, one select button, one reset button, and a
8 | * potentiometer to control the contrast with.
9 | *
10 | * Note that the shield is available in a kit that includes
11 | * the LCD screen. You can also use a monochrome LCD screen.
12 | *
13 | * Components
14 | * ----------
15 | * - Arduino Uno
16 | * - Adafruit RGB Character LCD Shield
17 | *
18 | * Libraries
19 | * ---------
20 | * - Wire
21 | * - Adafruit_MCP23017
22 | * - Adafruit_RGBLCDShield
23 | *
24 | * Connections
25 | * -----------
26 | *
27 | * Just plug the shield on the Arduino Uno and you are good to go.
28 | *
29 | *
30 | * Other information
31 | * -----------------
32 | * For information on the LCD chield: https://www.adafruit.com/product/714
33 | * For information on the Adafruit_RGBLCDShield library: https://github.com/adafruit/Adafruit-RGB-LCD-Shield-Library/
34 | * For information on the Adafruit_MCP23017 library: https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library
35 | * Install both libraries via the Library manager. Search for "Adafruit RGB LCD Shield Library" and "Adafruit MCP23017".
36 | *
37 | * Modified on November 18, 2016, by Peter Dalmaris from the original Adafruit demo sketch.
38 | * Updated on July 1, 2024, by Peter Dalmaris.
39 | *
40 | */
41 | /*********************
42 |
43 | Example code for the Adafruit RGB Character LCD Shield and Library
44 |
45 | This code displays text on the shield, and also reads the buttons on the keypad.
46 | When a button is pressed, the backlight changes color.
47 |
48 | **********************/
49 |
50 | // include the library code:
51 | #include
52 | #include // This library has changed its name in newer versions. Old name was Adafruit_MCP2317
53 | #include
54 |
55 | // The shield uses the I2C SCL and SDA pins. On classic Arduinos
56 | // this is Analog 4 and 5 so you can't use those for analogRead() anymore
57 | // However, you can connect other I2C sensors to the I2C bus and share
58 | // the I2C bus.
59 | Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
60 |
61 | // These #defines make it easy to set the backlight color
62 | #define RED 0x1
63 | #define YELLOW 0x3
64 | #define GREEN 0x2
65 | #define TEAL 0x6
66 | #define BLUE 0x4
67 | #define VIOLET 0x5
68 | #define WHITE 0x7
69 |
70 | void setup() {
71 | // Debugging output
72 | Serial.begin(9600);
73 | // set up the LCD's number of columns and rows:
74 | lcd.begin(16, 2);
75 | }
76 |
77 | void loop() {
78 | // set the cursor to column 0, line 1
79 | // (note: line 1 is the second row, since counting begins with 0):
80 | lcd.setCursor(0, 1);
81 | // print the number of seconds since reset:
82 | lcd.print(millis()/1000);
83 |
84 | uint8_t buttons = lcd.readButtons();
85 |
86 | if (buttons) {
87 | lcd.clear();
88 | lcd.setCursor(0,0);
89 | if (buttons & BUTTON_UP) {
90 | lcd.print("UP ");
91 | lcd.setBacklight(RED);
92 | }
93 | if (buttons & BUTTON_DOWN) {
94 | lcd.print("DOWN ");
95 | lcd.setBacklight(YELLOW);
96 | }
97 | if (buttons & BUTTON_LEFT) {
98 | lcd.print("LEFT ");
99 | lcd.setBacklight(GREEN);
100 | }
101 | if (buttons & BUTTON_RIGHT) {
102 | lcd.print("RIGHT ");
103 | lcd.setBacklight(TEAL);
104 | }
105 | if (buttons & BUTTON_SELECT) {
106 | lcd.print("SELECT ");
107 | lcd.setBacklight(VIOLET);
108 | }
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/i2c_scanner/i2c_scanner.ino:
--------------------------------------------------------------------------------
1 | // --------------------------------------
2 | // i2c_scanner
3 | //
4 | // Version 1
5 | // This program (or code that looks like it)
6 | // can be found in many places.
7 | // For example on the Arduino.cc forum.
8 | // The original author is not know.
9 | // Version 2, Juni 2012, Using Arduino 1.0.1
10 | // Adapted to be as simple as possible by Arduino.cc user Krodal
11 | // Version 3, Feb 26 2013
12 | // V3 by louarnold
13 | // Version 4, March 3, 2013, Using Arduino 1.0.3
14 | // by Arduino.cc user Krodal.
15 | // Changes by louarnold removed.
16 | // Scanning addresses changed from 0...127 to 1...119,
17 | // according to the i2c scanner by Nick Gammon
18 | // http://www.gammon.com.au/forum/?id=10896
19 | // Version 5, March 28, 2013
20 | // As version 4, but address scans now to 127.
21 | // A sensor seems to use address 120.
22 | // Version 6, November 27, 2015.
23 | // Added waiting for the Leonardo serial communication.
24 | //
25 | //
26 | // This sketch tests the standard 7-bit addresses
27 | // Devices with higher bit address might not be seen properly.
28 | //
29 |
30 | #include
31 |
32 |
33 | void setup()
34 | {
35 | Wire.begin();
36 |
37 | Serial.begin(9600);
38 | while (!Serial); // Leonardo: wait for serial monitor
39 | Serial.println("\nI2C Scanner");
40 | }
41 |
42 |
43 | void loop()
44 | {
45 | byte error, address;
46 | int nDevices;
47 |
48 | Serial.println("Scanning...");
49 |
50 | nDevices = 0;
51 | for(address = 1; address < 127; address++ )
52 | {
53 | // The i2c_scanner uses the return value of
54 | // the Write.endTransmisstion to see if
55 | // a device did acknowledge to the address.
56 | Wire.beginTransmission(address);
57 | error = Wire.endTransmission();
58 |
59 | if (error == 0)
60 | {
61 | Serial.print("I2C device found at address 0x");
62 | if (address<16)
63 | Serial.print("0");
64 | Serial.print(address,HEX);
65 | Serial.println(" !");
66 |
67 | nDevices++;
68 | }
69 | else if (error==4)
70 | {
71 | Serial.print("Unknow error at address 0x");
72 | if (address<16)
73 | Serial.print("0");
74 | Serial.println(address,HEX);
75 | }
76 | }
77 | if (nDevices == 0)
78 | Serial.println("No I2C devices found\n");
79 | else
80 | Serial.println("done\n");
81 |
82 | delay(5000); // wait 5 seconds for next scan
83 | }
84 |
--------------------------------------------------------------------------------