This shows you the differences between two versions of the page.
pm:prj2022:robert:thermal-detonator [2022/05/27 10:37] claudia_oana.panait [Hardware Design] |
pm:prj2022:robert:thermal-detonator [2022/05/27 21:02] (current) claudia_oana.panait [Obtained Results] |
||
---|---|---|---|
Line 26: | Line 26: | ||
| Speaker | 1 | | | Speaker | 1 | | ||
| Red LED | 1 | | | Red LED | 1 | | ||
- | | Yellow LED | 3 | | + | | Yellow LED | 3 | |
+ | | 100 Ohm Resistor | 1 | | ||
+ | | 1k Ohm Resistor | 1 | | ||
| Microswitch | 1 | | | Microswitch | 1 | | ||
| Switch | 1 | | | Switch | 1 | | ||
Line 33: | Line 35: | ||
Electric Diagram: | Electric Diagram: | ||
- | {{ :pm:prj2022:robert:thermal_detonator.png?300 |}} | + | {{ :pm:prj2022:robert:thermal_detonator.png?700 |}} |
===== Software Design ===== | ===== Software Design ===== | ||
- | <note tip> | + | *Development environments used: ArduinoIDE |
- | Descrierea codului aplicaţiei (firmware): | + | |
- | * mediu de dezvoltare (if any) (e.g. AVR Studio, CodeVisionAVR) | + | |
- | * librării şi surse 3rd-party (e.g. Procyon AVRlib) | + | |
- | * algoritmi şi structuri pe care plănuiţi să le implementaţi | + | |
- | * (etapa 3) surse şi funcţii implementate | + | |
- | </note> | + | |
- | ===== Rezultate Obţinute ===== | + | *Used libraries:\\ |
+ | [[https://docs.arduino.cc/learn/built-in-libraries/software-serial|SoftwareSerial.h]]\\ | ||
+ | [[https://github.com/DFRobot/DFRobotDFPlayerMini|DFRobotDFPlayerMini.h]] | ||
- | <note tip> | ||
- | Care au fost rezultatele obţinute în urma realizării proiectului vostru. | ||
- | </note> | ||
- | ===== Concluzii ===== | + | ==== How It Works ==== |
- | ===== Download ===== | ||
- | <note warning> | + | We begin by declaring all global variables and creating the classes needed for the player. |
- | O arhivă (sau mai multe dacă este cazul) cu fişierele obţinute în urma realizării proiectului: surse, scheme, etc. Un fişier README, un ChangeLog, un script de compilare şi copiere automată pe uC crează întotdeauna o impresie bună ;-). | + | <code cpp> |
+ | #define BUTTON 2//detonator button | ||
+ | #define LEDRED 5//armed LED | ||
+ | #define LEDLEFT 6 // yellow LED | ||
+ | #define LEDMIDDLE 7 // yello LED | ||
+ | #define LEDRIGHT 8 //yellow LED | ||
+ | #define SENSOR 9 //sensor input | ||
+ | #define TX 10 //TX pin on DFPlayer module | ||
+ | #define RX 11 //RX pin on DFPlayer module | ||
+ | |||
+ | const int time = 2124;//the delay between sequence change | ||
+ | int sequenceNumber = 0; | ||
+ | |||
+ | SoftwareSerial softwareSerial(TX, RX); | ||
+ | |||
+ | DFRobotDFPlayerMini player; // declaration of player | ||
+ | </code> | ||
+ | We create two functions: one that will turn on the yellow LEDs in a given configuration (i. e. left-on, middle-off, right-on) and a function that returns the value of the movement sensor. | ||
+ | <code cpp> | ||
+ | //Run one LED sequence | ||
+ | void Sequence(bool Left, bool Middle, bool Right){ | ||
+ | if (digitalRead(BUTTON) == LOW)//if true (button is pressed) run LED sequence | ||
+ | { | ||
+ | if (Left) | ||
+ | { | ||
+ | digitalWrite(LEDLEFT, HIGH); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | digitalWrite(LEDLEFT, LOW); | ||
+ | } | ||
+ | |||
+ | if (Middle) | ||
+ | { | ||
+ | digitalWrite(LEDMIDDLE, HIGH); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | digitalWrite(LEDMIDDLE, LOW); | ||
+ | } | ||
+ | |||
+ | if (Right) | ||
+ | { | ||
+ | digitalWrite(LEDRIGHT, HIGH); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | digitalWrite(LEDRIGHT, LOW); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | long TP_init(){ | ||
+ | long measurement=pulseIn (SENSOR, HIGH); //wait for the pin to get HIGH and returns measurement | ||
+ | return measurement; | ||
+ | } | ||
+ | </code> | ||
+ | After this, we begin the setup process by starting the program and setting all LEDs on LOW. | ||
+ | <code cpp> | ||
+ | void setup() | ||
+ | { | ||
+ | Serial.begin(9600); | ||
+ | pinMode(SENSOR, INPUT); | ||
+ | softwareSerial.begin(9600); | ||
+ | |||
+ | pinMode(LEDRED, OUTPUT); | ||
+ | pinMode(LEDLEFT, OUTPUT); | ||
+ | pinMode(LEDMIDDLE, OUTPUT); | ||
+ | pinMode(LEDRIGHT, OUTPUT); | ||
+ | |||
+ | digitalWrite(LEDRED, LOW); | ||
+ | digitalWrite(LEDLEFT, LOW); | ||
+ | digitalWrite(LEDMIDDLE, LOW); | ||
+ | digitalWrite(LEDRIGHT, LOW); | ||
+ | |||
+ | //now set pins to input | ||
+ | pinMode(BUTTON, INPUT_PULLUP); | ||
+ | |||
+ | |||
+ | // start the player | ||
+ | player.begin(softwareSerial); | ||
+ | |||
+ | |||
+ | } | ||
+ | </code> | ||
+ | The loop() part of the program is made out of two scenarios. \\ | ||
+ | |||
+ | In the first scenario, the switch is off (The convention for this project is that if the microswitch is off, the circuit is active. If the switch is on, then the circuit is off. The reason for this being the outer design of the toy as well as the desire to make it movie accurate) and the program begins the arming sequence. It receives the measurement from the movement sensor and if the measurement is smaller than the chosen value, it keeps on with the arming sequence. If the measurement is greater than the chosen value, it stops the previous sequence by stopping track 1 and starts the detonation sequence by playing track 2 and turning all LED’s on HIGH. | ||
+ | <code cpp> | ||
+ | // Start communication with DFPlayer Mini | ||
+ | |||
+ | // Set volume to a value between (0 to 30) | ||
+ | player.volume(30); | ||
+ | |||
+ | if (digitalRead(BUTTON) == LOW ){ | ||
+ | player.play(1); // play the arming sequence | ||
+ | digitalWrite(LEDRED, HIGH);//switch armed LED (red) on | ||
+ | } | ||
+ | |||
+ | if (digitalRead(BUTTON) == LOW && sequenceNumber == 0) | ||
+ | { | ||
+ | long measurement =pulseIn (SENSOR, HIGH); //get measurement from teh sensor | ||
+ | Serial.println(measurement); | ||
+ | if (measurement > 1000) | ||
+ | { // measurement checks | ||
+ | player.stop(); | ||
+ | player.play(2); //playing detonating sequence | ||
+ | sequenceNumber = 0; | ||
+ | digitalWrite(LEDRED, HIGH); | ||
+ | digitalWrite(LEDRIGHT, HIGH); | ||
+ | digitalWrite(LEDMIDDLE, HIGH); | ||
+ | digitalWrite(LEDLEFT, HIGH); | ||
+ | while(digitalRead(BUTTON)==LOW){ // give a chance to turn off the toy | ||
+ | delay(10000); | ||
+ | player.stop(); | ||
+ | digitalWrite(LEDRED, LOW); | ||
+ | digitalWrite(LEDRIGHT, LOW); | ||
+ | digitalWrite(LEDMIDDLE, LOW); | ||
+ | digitalWrite(LEDLEFT, LOW); | ||
+ | } | ||
+ | } | ||
+ | else | ||
+ | { // measuremnt does not check | ||
+ | delay(time); | ||
+ | Sequence(false, true, true); // continu with arming sequence | ||
+ | sequenceNumber++; | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
+ | The second scenario is when the switch is on, so the circuit is not active. | ||
+ | <code cpp> | ||
+ | if (digitalRead(BUTTON) == HIGH) // toy is turned off | ||
+ | { | ||
+ | sequenceNumber = 0; | ||
+ | player.stop(); | ||
+ | digitalWrite(LEDRED, LOW); | ||
+ | digitalWrite(LEDRIGHT, LOW); | ||
+ | digitalWrite(LEDMIDDLE, LOW); | ||
+ | digitalWrite(LEDLEFT, LOW); | ||
+ | } | ||
+ | </code> | ||
+ | Additionally, depending on the length of track 1 used in the arming sequence, we will choose a number of times the respective if{} statement will be repeated. In this case it, is repeated 12 times. | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ===== Obtained Results ===== | ||
+ | |||
+ | |||
+ | *[[https://1drv.ms/v/s!AnPkI6n9qsW9iJpMvW4x-5KKddPhuA?e=e2y0ct|Demo Video]] | ||
+ | |||
+ | |||
+ | {{ :pm:prj2022:robert:therm1.jpg?direct&500 |}} | ||
+ | |||
+ | {{ :pm:prj2022:robert:therm2.jpg?direct&500 |}} | ||
+ | |||
+ | {{ :pm:prj2022:robert:therm3.jpg?direct&500 |}} | ||
+ | |||
+ | {{ :pm:prj2022:robert:therm4.jpg?direct&500 |}} | ||
+ | |||
+ | {{ :pm:prj2022:robert:therm5.jpg?direct&500 |}} | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ===== Conclusion ===== | ||
+ | |||
+ | As a result of this project, there are a few things that I learned:\\ | ||
+ | *Despite how complicated a project may seem on the outside, in reality, if broke down into smaller parts, it becomes much easier to handle. | ||
+ | |||
+ | *Because of the large number of Arduino libraries, it is quite easy to develop the code for your idea. | ||
+ | |||
+ | *It is also very easy to fry components compared to the work it goes into soldering them together. | ||
+ | |||
+ | |||
+ | |||
+ | ===== Download ===== | ||
- | Fişierele se încarcă pe wiki folosind facilitatea **Add Images or other files**. Namespace-ul în care se încarcă fişierele este de tipul **:pm:prj20??:c?** sau **:pm:prj20??:c?:nume_student** (dacă este cazul). **Exemplu:** Dumitru Alin, 331CC -> **:pm:prj2009:cc:dumitru_alin**. | ||
- | </note> | ||
- | ===== Jurnal ===== | + | *{{:pm:prj2022:robert:thermal_detonator.png?linkonly|Electric Diagram}} |
- | <note tip> | + | *{{:pm:prj2022:robert:thermal_detonator.rar|Source Code}} |
- | Puteți avea și o secțiune de jurnal în care să poată urmări asistentul de proiect progresul proiectului. | + | |
- | </note> | + | |
===== Bibliografie/Resurse ===== | ===== Bibliografie/Resurse ===== | ||
- | <note> | + | *[[https://components101.com/sensors/sw-420-vibration-sensor-module|SW-420 Vibration Sensor Module]] |
- | Listă cu documente, datasheet-uri, resurse Internet folosite, eventual grupate pe **Resurse Software** şi **Resurse Hardware**. | + | *[[https://docs.arduino.cc/retired/boards/arduino-pro-mini|Arduino Pro Mini]] |
- | </note> | + | *[[https://cdn.sparkfun.com/datasheets/Dev/Arduino/Boards/ProMini16MHzv1.pdf|Arduino Pro Mini]] |
+ | *[[https://wiki.dfrobot.com/DFPlayer_Mini_SKU_DFR0299|DFR0299 DFPlayer Mini]] | ||
<html><a class="media mediafile mf_pdf" href="?do=export_pdf">Export to PDF</a></html> | <html><a class="media mediafile mf_pdf" href="?do=export_pdf">Export to PDF</a></html> | ||