Components and supplies
Rechargeable Battery, Lithium Ion
Perma-Proto Breadboard Half Size
Ceramic Disc Capacitor, 100 pF
Buzzer, Piezo
Ultrasonic Sensor - HC-SR04 (Generic)
Solderless Breadboard Full Size
Jumper wires (generic)
USB-A to Mini-USB Cable
7 Segment LED Display, InfoVue
General Purpose Transistor NPN
DS3231M - ±5ppm, I2C Real-Time Clock
DC/DC Charge Pump Adjustable Voltage Regulator, 3V to 18V in
Resistor 1k ohm
Capacitor 10 µF
Arduino Nano R3
Resistor 220 ohm
BLE Module
Tools and machines
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Solder Wire, Lead Free
Soldering iron (generic)
Apps and platforms
Arduino IDE
Project description
Code
Mat Max Code
arduino
prototype code
1// Include Libraries 2#include "Arduino.h" 3#include "BLEHM10.h" 4#include "Buzzer.h" 5#include "NewPing.h" 6#include "Wire.h" 7#include "RTClib.h" 8 9 10// Pin Definitions 11#define BLEHM10_PIN_TXD 11 12#define BLEHM10_PIN_RXD 10 13#define BUZZER_PIN_SIG 2 14#define HCSR04_PIN_TRIG 4 15#define HCSR04_PIN_ECHO 3 16#define SEVENSEGSINGLE_PIN_DP 9 17#define SEVENSEGSINGLE_PIN_C 7 18#define SEVENSEGSINGLE_PIN_D 8 19#define SEVENSEGSINGLE_PIN_E 12 20#define SEVENSEGSINGLE_PIN_B 6 21#define SEVENSEGSINGLE_PIN_A 5 22#define SEVENSEGSINGLE_PIN_F 13 23#define SEVENSEGSINGLE_PIN_G A0 24 25 26 27// Global variables and defines 28String blehm10Str = ""; 29//define an array for all the segments 30int SevenSegSinglePins[] = { SEVENSEGSINGLE_PIN_DP, SEVENSEGSINGLE_PIN_C, SEVENSEGSINGLE_PIN_D, SEVENSEGSINGLE_PIN_E, SEVENSEGSINGLE_PIN_B, SEVENSEGSINGLE_PIN_A, SEVENSEGSINGLE_PIN_F, SEVENSEGSINGLE_PIN_G }; 31// object initialization 32BLEHM10 blehm10(BLEHM10_PIN_RXD,BLEHM10_PIN_TXD); 33Buzzer buzzer(BUZZER_PIN_SIG); 34NewPing hcsr04(HCSR04_PIN_TRIG,HCSR04_PIN_ECHO); 35RTC_DS3231 rtcDS; 36 37 38// define vars for testing menu 39const int timeout = 10000; //define timeout of 10 sec 40char menuOption = 0; 41long time0; 42 43// Setup the essentials for your circuit to work. It runs first every time your circuit is powered with electricity. 44void setup() 45{ 46 // Setup Serial which is useful for debugging 47 // Use the Serial Monitor to view printed messages 48 Serial.begin(9600); 49 while (!Serial) ; // wait for serial port to connect. Needed for native USB 50 Serial.println("start"); 51 52 blehm10.begin(9600); 53 //This example uses HM-10 BLE to communicate with an Android or iOS device. 54 //For Android download Hm BLE Terminal from google play store, or any other BLE app. 55 //For iOS download LightBlue from App Store, or any other BLE app. 56 //On both apps, pair and connect to your HM-10 57 //You should see this message your Smartphone 58 blehm10.println("BLE On...."); 59 if (! rtcDS.begin()) { 60 Serial.println("Couldn't find RTC"); 61 while (1); 62 } 63 if (rtcDS.lostPower()) { 64 Serial.println("RTC lost power, lets set the time!"); 65 // following line sets the RTC to the date & time this sketch was compiled 66 rtcDS.adjust(DateTime(F(__DATE__), F(__TIME__))); 67 // This line sets the RTC with an explicit date & time, for example to set 68 // January 21, 2014 at 3am you would call: 69 // rtcDS.adjust(DateTime(2014, 1, 21, 3, 0, 0)); 70 } 71 pinMode(SEVENSEGSINGLE_PIN_DP, OUTPUT); 72 pinMode(SEVENSEGSINGLE_PIN_C, OUTPUT); 73 pinMode(SEVENSEGSINGLE_PIN_D, OUTPUT); 74 pinMode(SEVENSEGSINGLE_PIN_E, OUTPUT); 75 pinMode(SEVENSEGSINGLE_PIN_B, OUTPUT); 76 pinMode(SEVENSEGSINGLE_PIN_A, OUTPUT); 77 pinMode(SEVENSEGSINGLE_PIN_F, OUTPUT); 78 pinMode(SEVENSEGSINGLE_PIN_G, OUTPUT); 79 //turn off all segments: 80 for (int i = 0; i < 8; i++) { 81 digitalWrite(SevenSegSinglePins[i],HIGH); 82 } 83 menuOption = menu(); 84 85} 86 87// Main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop. 88void loop() 89{ 90 91 92 if(menuOption == '1') { 93 // HM-10 BLE Bluetooth 4.0 - Test Code 94 //Receive String from bluetooth device 95 if (blehm10.available()) 96 { 97 //Read a complete line from bluetooth terminal 98 blehm10Str = blehm10.readStringUntil('\n'); 99 // Print raw data to serial monitor 100 Serial.print("BT Raw Data: "); 101 Serial.println(blehm10Str); 102 } 103 //Send sensor data to Bluetooth device 104 blehm10.println("PUT YOUR SENSOR DATA HERE"); 105 106 } 107 else if(menuOption == '2') { 108 // Buzzer - Test Code 109 // The buzzer will turn on and off for 500ms (0.5 sec) 110 buzzer.on(); // 1. turns on 111 delay(500); // 2. waits 500 milliseconds (0.5 sec). Change the value in the brackets (500) for a longer or shorter delay in milliseconds. 112 buzzer.off(); // 3. turns off. 113 delay(500); // 4. waits 500 milliseconds (0.5 sec). Change the value in the brackets (500) for a longer or shorter delay in milliseconds. 114 } 115 else if(menuOption == '3') { 116 // Ultrasonic Sensor - HC-SR04 - Test Code 117 // Read distance measurment from UltraSonic sensor 118 int hcsr04Dist = hcsr04.ping_cm(); 119 delay(10); 120 Serial.print(F("Distance: ")); Serial.print(hcsr04Dist); Serial.println(F("[cm]")); 121 122 } 123 else if(menuOption == '4') { 124 // RTC - Real Time Clock - Test Code 125 //This will display the time and date of the RTC. see RTC.h for more functions such as rtcDS.hour(), rtcDS.month() etc. 126 DateTime now = rtcDS.now(); 127 Serial.print(now.month(), DEC); 128 Serial.print('/'); 129 Serial.print(now.day(), DEC); 130 Serial.print('/'); 131 Serial.print(now.year(), DEC); 132 Serial.print(" "); 133 Serial.print(now.hour(), DEC); 134 Serial.print(':'); 135 Serial.print(now.minute(), DEC); 136 Serial.print(':'); 137 Serial.print(now.second(), DEC); 138 Serial.println(); 139 delay(1000); 140 } 141 else if(menuOption == '5') { 142 // 7 - Segment Display (Single Digit) - Test Code 143 //This loop will turn on and off each segment in the array for 0.5 sec 144 for (int i = 0; i < 8; i++) { 145 digitalWrite(SevenSegSinglePins[i],LOW); 146 delay(500); 147 } 148 for (int i = 0; i < 8; i++) { 149 digitalWrite(SevenSegSinglePins[i],HIGH); 150 } 151 152 } 153 154 if (millis() - time0 > timeout) 155 { 156 menuOption = menu(); 157 } 158 159} 160 161 162 163// Menu function for selecting the components to be tested 164// Follow serial monitor for instrcutions 165char menu() 166{ 167 168 Serial.println(F("\ 169Which component would you like to test?")); 170 Serial.println(F("(1) HM-10 BLE Bluetooth 4.0")); 171 Serial.println(F("(2) Buzzer")); 172 Serial.println(F("(3) Ultrasonic Sensor - HC-SR04")); 173 Serial.println(F("(4) RTC - Real Time Clock")); 174 Serial.println(F("(5) 7 - Segment Display (Single Digit)")); 175 Serial.println(F("(menu) send anything else or press on board reset button\ 176")); 177 while (!Serial.available()); 178 179 // Read data from serial monitor if received 180 while (Serial.available()) 181 { 182 char c = Serial.read(); 183 if (isAlphaNumeric(c)) 184 { 185 186 if(c == '1') 187 Serial.println(F("Now Testing HM-10 BLE Bluetooth 4.0")); 188 else if(c == '2') 189 Serial.println(F("Now Testing Buzzer")); 190 else if(c == '3') 191 Serial.println(F("Now Testing Ultrasonic Sensor - HC-SR04")); 192 else if(c == '4') 193 Serial.println(F("Now Testing RTC - Real Time Clock")); 194 else if(c == '5') 195 Serial.println(F("Now Testing 7 - Segment Display (Single Digit)")); 196 else 197 { 198 Serial.println(F("illegal input!")); 199 return 0; 200 } 201 time0 = millis(); 202 return c; 203 } 204 } 205} 206
Mat Max Code
arduino
prototype code
1// Include Libraries 2#include "Arduino.h" 3#include "BLEHM10.h" 4#include 5 "Buzzer.h" 6#include "NewPing.h" 7#include "Wire.h" 8#include "RTClib.h" 9 10 11// 12 Pin Definitions 13#define BLEHM10_PIN_TXD 11 14#define BLEHM10_PIN_RXD 10 15#define 16 BUZZER_PIN_SIG 2 17#define HCSR04_PIN_TRIG 4 18#define HCSR04_PIN_ECHO 3 19#define 20 SEVENSEGSINGLE_PIN_DP 9 21#define SEVENSEGSINGLE_PIN_C 7 22#define SEVENSEGSINGLE_PIN_D 8 23#define 24 SEVENSEGSINGLE_PIN_E 12 25#define SEVENSEGSINGLE_PIN_B 6 26#define SEVENSEGSINGLE_PIN_A 5 27#define 28 SEVENSEGSINGLE_PIN_F 13 29#define SEVENSEGSINGLE_PIN_G A0 30 31 32 33// Global 34 variables and defines 35String blehm10Str = ""; 36//define an array for all 37 the segments 38int SevenSegSinglePins[] = { SEVENSEGSINGLE_PIN_DP, SEVENSEGSINGLE_PIN_C, 39 SEVENSEGSINGLE_PIN_D, SEVENSEGSINGLE_PIN_E, SEVENSEGSINGLE_PIN_B, SEVENSEGSINGLE_PIN_A, 40 SEVENSEGSINGLE_PIN_F, SEVENSEGSINGLE_PIN_G }; 41// object initialization 42BLEHM10 43 blehm10(BLEHM10_PIN_RXD,BLEHM10_PIN_TXD); 44Buzzer buzzer(BUZZER_PIN_SIG); 45NewPing 46 hcsr04(HCSR04_PIN_TRIG,HCSR04_PIN_ECHO); 47RTC_DS3231 rtcDS; 48 49 50// define 51 vars for testing menu 52const int timeout = 10000; //define timeout of 10 53 sec 54char menuOption = 0; 55long time0; 56 57// Setup the essentials for your 58 circuit to work. It runs first every time your circuit is powered with electricity. 59void 60 setup() 61{ 62 // Setup Serial which is useful for debugging 63 // Use 64 the Serial Monitor to view printed messages 65 Serial.begin(9600); 66 while 67 (!Serial) ; // wait for serial port to connect. Needed for native USB 68 Serial.println("start"); 69 70 71 blehm10.begin(9600); 72 //This example uses HM-10 BLE to communicate 73 with an Android or iOS device. 74 //For Android download Hm BLE Terminal from 75 google play store, or any other BLE app. 76 //For iOS download LightBlue from 77 App Store, or any other BLE app. 78 //On both apps, pair and connect to your 79 HM-10 80 //You should see this message your Smartphone 81 blehm10.println("BLE 82 On...."); 83 if (! rtcDS.begin()) { 84 Serial.println("Couldn't find RTC"); 85 86 while (1); 87 } 88 if (rtcDS.lostPower()) { 89 Serial.println("RTC 90 lost power, lets set the time!"); 91 // following line sets the RTC to the 92 date & time this sketch was compiled 93 rtcDS.adjust(DateTime(F(__DATE__), F(__TIME__))); 94 95 // This line sets the RTC with an explicit date & time, for example to set 96 97 // January 21, 2014 at 3am you would call: 98 // rtcDS.adjust(DateTime(2014, 99 1, 21, 3, 0, 0)); 100 } 101 pinMode(SEVENSEGSINGLE_PIN_DP, OUTPUT); 102 pinMode(SEVENSEGSINGLE_PIN_C, 103 OUTPUT); 104 pinMode(SEVENSEGSINGLE_PIN_D, OUTPUT); 105 pinMode(SEVENSEGSINGLE_PIN_E, 106 OUTPUT); 107 pinMode(SEVENSEGSINGLE_PIN_B, OUTPUT); 108 pinMode(SEVENSEGSINGLE_PIN_A, 109 OUTPUT); 110 pinMode(SEVENSEGSINGLE_PIN_F, OUTPUT); 111 pinMode(SEVENSEGSINGLE_PIN_G, 112 OUTPUT); 113 //turn off all segments: 114 for (int i = 0; i < 8; i++) { 115 116 digitalWrite(SevenSegSinglePins[i],HIGH); 117 } 118 menuOption = menu(); 119 120 121} 122 123// Main logic of your circuit. It defines the interaction between 124 the components you selected. After setup, it runs over and over again, in an eternal 125 loop. 126void loop() 127{ 128 129 130 if(menuOption == '1') { 131 // 132 HM-10 BLE Bluetooth 4.0 - Test Code 133 //Receive String from bluetooth device 134 135 if (blehm10.available()) 136 { 137 //Read a complete line from bluetooth 138 terminal 139 blehm10Str = blehm10.readStringUntil('\ 140'); 141 // Print raw 142 data to serial monitor 143 Serial.print("BT Raw Data: "); 144 Serial.println(blehm10Str); 145 146 } 147 //Send sensor data to Bluetooth device 148 blehm10.println("PUT 149 YOUR SENSOR DATA HERE"); 150 151 } 152 else if(menuOption == '2') { 153 // 154 Buzzer - Test Code 155 // The buzzer will turn on and off for 500ms (0.5 sec) 156 157 buzzer.on(); // 1. turns on 158 delay(500); // 2. waits 159 500 milliseconds (0.5 sec). Change the value in the brackets (500) for a longer 160 or shorter delay in milliseconds. 161 buzzer.off(); // 3. turns off. 162 163 delay(500); // 4. waits 500 milliseconds (0.5 sec). Change the value 164 in the brackets (500) for a longer or shorter delay in milliseconds. 165 } 166 167 else if(menuOption == '3') { 168 // Ultrasonic Sensor - HC-SR04 - Test Code 169 170 // Read distance measurment from UltraSonic sensor 171 int hcsr04Dist 172 = hcsr04.ping_cm(); 173 delay(10); 174 Serial.print(F("Distance: ")); Serial.print(hcsr04Dist); 175 Serial.println(F("[cm]")); 176 177 } 178 else if(menuOption == '4') { 179 180 // RTC - Real Time Clock - Test Code 181 //This will display the time and 182 date of the RTC. see RTC.h for more functions such as rtcDS.hour(), rtcDS.month() 183 etc. 184 DateTime now = rtcDS.now(); 185 Serial.print(now.month(), DEC); 186 187 Serial.print('/'); 188 Serial.print(now.day(), DEC); 189 Serial.print('/'); 190 191 Serial.print(now.year(), DEC); 192 Serial.print(" "); 193 Serial.print(now.hour(), 194 DEC); 195 Serial.print(':'); 196 Serial.print(now.minute(), DEC); 197 Serial.print(':'); 198 199 Serial.print(now.second(), DEC); 200 Serial.println(); 201 delay(1000); 202 203 } 204 else if(menuOption == '5') { 205 // 7 - Segment Display (Single 206 Digit) - Test Code 207 //This loop will turn on and off each segment in the array 208 for 0.5 sec 209 for (int i = 0; i < 8; i++) { 210 digitalWrite(SevenSegSinglePins[i],LOW); 211 212 delay(500); 213 } 214 for (int i = 0; i < 8; i++) { 215 digitalWrite(SevenSegSinglePins[i],HIGH); 216 217 } 218 219 } 220 221 if (millis() - time0 > timeout) 222 { 223 menuOption 224 = menu(); 225 } 226 227} 228 229 230 231// Menu function for selecting the 232 components to be tested 233// Follow serial monitor for instrcutions 234char menu() 235{ 236 237 238 Serial.println(F("\ 239Which component would you like to test?")); 240 Serial.println(F("(1) 241 HM-10 BLE Bluetooth 4.0")); 242 Serial.println(F("(2) Buzzer")); 243 Serial.println(F("(3) 244 Ultrasonic Sensor - HC-SR04")); 245 Serial.println(F("(4) RTC - Real Time Clock")); 246 247 Serial.println(F("(5) 7 - Segment Display (Single Digit)")); 248 Serial.println(F("(menu) 249 send anything else or press on board reset button\ 250")); 251 while (!Serial.available()); 252 253 254 // Read data from serial monitor if received 255 while (Serial.available()) 256 257 { 258 char c = Serial.read(); 259 if (isAlphaNumeric(c)) 260 261 { 262 263 if(c == '1') 264 Serial.println(F("Now 265 Testing HM-10 BLE Bluetooth 4.0")); 266 else if(c == '2') 267 Serial.println(F("Now 268 Testing Buzzer")); 269 else if(c == '3') 270 Serial.println(F("Now 271 Testing Ultrasonic Sensor - HC-SR04")); 272 else if(c == '4') 273 Serial.println(F("Now 274 Testing RTC - Real Time Clock")); 275 else if(c == '5') 276 Serial.println(F("Now 277 Testing 7 - Segment Display (Single Digit)")); 278 else 279 { 280 281 Serial.println(F("illegal input!")); 282 return 283 0; 284 } 285 time0 = millis(); 286 return c; 287 288 } 289 } 290} 291
Downloadable files
Diagraman Circuit
prototype
Diagraman Circuit
Diagraman Circuit
prototype
Diagraman Circuit
Documentation
Cone
Traffic cone
Cone
Comments
Only logged in users can leave comments