Here yo will see a video with the functioning of the ESP-WROOM-32 with the SOS code.
//Blink 2 //This is the code that is used in the video //Step 1: Defining the constants int pin_led = 23; //The led is connected at pin D23 const int dot = 200; //I'm defining "dot" as the delay, that is the waiting time const int dash = dot*3; //I'm defining "dash" as "dot*3", that it would be delay 600 const int space = dot*7; //I'm defining "space" as "dot*7", that it would be delay 1400 //Step 2 void setup() { //setup pin 23 as a digital output because the light goes out pinMode(pin_led, OUTPUT); // } //Step 3 void S() { //Here I'm defining the variable S digitalWrite(pin_led, HIGH); delay(dot); digitalWrite(pin_led, LOW); delay(dot); digitalWrite(pin_led, HIGH); delay(dot); digitalWrite(pin_led, LOW); delay(dot); digitalWrite(pin_led, HIGH); delay(dot); digitalWrite(pin_led, LOW); delay(dot); } void O() { //Here I'm defining the variable S digitalWrite(pin_led, HIGH); delay(dash); digitalWrite(pin_led, LOW); delay(dot); digitalWrite(pin_led, HIGH); delay(dash); digitalWrite(pin_led, LOW); delay(dot); digitalWrite(pin_led, HIGH); delay(dash); digitalWrite(pin_led, LOW); delay(dot); } //Step 4 void loop() { //Here I'm calling the two variables I defined before with a "space" that ends the loop S(); O(); S(); delay(space); }
//Blink 1 //Step 1: Defining the constants int pin_led = 23; //The led is connected to the pin 23 //Step 2: Here we define that the led is an output void setup() { pinMode(pin_led, OUTPUT); } //Step 3: We call the code SOS void loop() { digitalWrite(pin_led, HIGH); //Here starts the S delay(200); digitalWrite(pin_led, LOW); delay(200); digitalWrite(pin_led, HIGH); delay(200); digitalWrite(pin_led, LOW); delay(200); digitalWrite(pin_led, HIGH); delay(200); digitalWrite(pin_led, LOW); delay(200); digitalWrite(pin_led, HIGH); //Here starts the O delay(600); digitalWrite(pin_led, LOW); delay(200); digitalWrite(pin_led, HIGH); delay(600); digitalWrite(pin_led, LOW); delay(200); digitalWrite(pin_led, HIGH); delay(600); digitalWrite(pin_led, LOW); delay(200); digitalWrite(pin_led, HIGH); //Here starts the S delay(200); digitalWrite(pin_led, LOW); delay(200); digitalWrite(pin_led, HIGH); delay(200); digitalWrite(pin_led, LOW); delay(200); digitalWrite(pin_led, HIGH); delay(200); digitalWrite(pin_led, LOW); delay(200); digitalWrite(pin_led, LOW); //A pause to mark the end delay(1400); }
//Step 1: Defining the constants int ledPin = 23; //Step 2: Here we define that the led is an output void setup() { pinMode (ledPin, OUTPUT); } //Step 3: Here we create the constant flash void intermittent(int nf, int d){ //int is for integer numbers, nf is the times that will occur and d the time for(int i = 0; i< nf; i++){ digitalWrite (ledPin, HIGH); delay (d); digitalWrite (ledPin, LOW); delay (d); } } //Step 4: here we call the constant that we created void loop() { intermittent(3,200); digitalWrite (ledPin, LOW); delay (400); intermittent(3,600); digitalWrite (ledPin, LOW); delay (400); intermittent(3,200); digitalWrite (ledPin, LOW); delay (1200); }
//Blink 4 //Step 1: Defining the constants const byte ledPin = 23; void setup() // We define ledPin as output pinMode(ledPin, OUTPUT) //Now we create a function for short blink, that is the S in the SOS code void shortBlink() // Make a single short blink for the code digitalWrite(ledPin, HIGH) delay(200) digitalWrite(ledPin, LOW) delay(200) void longBlink() // Make a single long blink, that is the O in the SOS code digitalWrite(ledPin, HIGH) delay(600) digitalWrite(ledPin, LOW) delay(200); } void morseBlink(char character) { // Here, we translate characters (s,o,s) to Morse code switch(character){ case ‘s‘: shortBlink(); shortBlink(); shortBlink(); break; case ‘o‘: longBlink(); longBlink(); longBlink(); break; } } void loop() { // Finally we call the two letters that we defined before morseBlink(‘s‘); morseBlink(‘o‘); morseBlink(‘s’); }
In this project we also tried to connect a speaker to the board so that when the led lights up when executing the SOS code, the speaker makes sounds at the same time as the flashing. To do that, you need tone, which is what allows the speaker to sound. At first we had problems because the arduino application did not recognize the tone command, we searched the internet for a solution and found a person who had the same problem and created his own library so that "tone" could be recognized and work correctly. Once that library was downloaded from his GitHub.
Then we applied the library and the application recognized the code completely and there was no error, but here came the second problem, we did not know which pin to connect the speaker to. We looked on different pages for the pinout of our board but none had the information we were looking for, which was a pin that had a PWM (pulse width modulation) output. We tried to connect in different places, from pin 0-11 and when sending the code none reproduced sound, that is, the problem is no longer in the code, but in where to connect the speaker.
In this video you can see that the speaker already works correctly, what we have done to make it work is download the ESP32Servo library, and thanks to this code it already recognizes it perfectly. We also find where to connect the speaker: positive leg to D25 and negative to GND. This is for the most basic to work, but for the morse code with the code we have used, a few more libraries are needed, which are the ones shown below:
#include < ESP32Servo.h > #include < analogWrite.h > #include < ESP32Tone.h > #include < ESP32PWM.h > //#include < tone.h > //In this case, we have include the ESP32Servo's library (If you want to download it, here is the link: https://github.com/jkb-git/ESP32Servo) in order to enable all the functions, because the ESP-Wroom 32 board does we found that not support all the functions, and needs other external libraries #include < pitches.h > #include < Tone32.h > //Here we include Tone32 (that we already mentioned in the problem we had with the speaker, there you will find the download link) that is necessary so that our board can correctly read the code //the speaker's "tone" function, a function that allows you to control the pin, frequency and duration, in that order // Numero 7 // Led + Tone const int led = 2; String code = ""; int len = 0; char ch; char new_char; int unit_delay = 250; void dot() { Serial.print("."); digitalWrite(led, HIGH); tone(25, 262, 200); //The variables of the speaker we define in which pin it goes, that is because we put it directly in the functions //And then we put the frequency and duration, that is: tone (pin, frequency, duration) delay(unit_delay); digitalWrite(led, LOW); delay(unit_delay); } void dash() { Serial.print("-"); digitalWrite(led, HIGH); tone(25, 440, 600); delay(unit_delay * 3); digitalWrite(led, LOW); delay(unit_delay); } void A() { dot(); delay(unit_delay); dash(); delay(unit_delay); } void B() { dash(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); } void C() { dash(); delay(unit_delay); dot(); delay(unit_delay); dash(); delay(unit_delay); dot(); delay(unit_delay); } void D() { dash(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); } void E() { dot(); delay(unit_delay); } void f() { dot(); delay(unit_delay); dot(); delay(unit_delay); dash(); delay(unit_delay); dot(); delay(unit_delay); } void G() { dash(); delay(unit_delay); dash(); delay(unit_delay); dot(); delay(unit_delay); } void H() { dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); } void I() { dot(); delay(unit_delay); dot(); delay(unit_delay); } void J() { dot(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); } void K() { dash(); delay(unit_delay); dot(); delay(unit_delay); dash(); delay(unit_delay); } void L() { dot(); delay(unit_delay); dash(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); } void M() { dash(); delay(unit_delay); dash(); delay(unit_delay); } void N() { dash(); delay(unit_delay); dot(); delay(unit_delay); } void O() { dash(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); } void P() { dot(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); dot(); } void Q() { dash(); delay(unit_delay); dash(); delay(unit_delay); dot(); delay(unit_delay); dash(); delay(unit_delay); } void R() { dot(); delay(unit_delay); dash(); delay(unit_delay); dot(); delay(unit_delay); } void S() { dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); } void T() { dash(); delay(unit_delay); } void U() { dot(); delay(unit_delay); dot(); delay(unit_delay); dash(); delay(unit_delay); } void V() { dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); dash(); delay(unit_delay); } void W() { dot(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); } void X() { dash(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); dash(); delay(unit_delay); } void Y() { dash(); delay(unit_delay); dot(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); } void Z() { dash(); delay(unit_delay); dash(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); } void one() { dot(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); } void two() { dot(); delay(unit_delay); dot(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); } void three() { dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); } void four() { dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); dash(); delay(unit_delay); } void five() { dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); } void six() { dash(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); } void seven() { dash(); delay(unit_delay); dash(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); } void eight() { dash(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); dot(); delay(unit_delay); dot(); delay(unit_delay); } void nine() { dash(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); dot(); delay(unit_delay); } void zero() { dash(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); dash(); delay(unit_delay); } void morse() { if (ch == 'A' || ch == 'a') { A(); Serial.print(" "); } else if (ch == 'B' || ch == 'b') { B(); Serial.print(" "); } else if (ch == 'C' || ch == 'c') { C(); Serial.print(" "); } else if (ch == 'D' || ch == 'd') { D(); Serial.print(" "); } else if (ch == 'E' || ch == 'e') { E(); Serial.print(" "); } else if (ch == 'f' || ch == 'f') { f(); Serial.print(" "); } else if (ch == 'G' || ch == 'g') { G(); Serial.print(" "); } else if (ch == 'H' || ch == 'h') { H(); Serial.print(" "); } else if (ch == 'I' || ch == 'i') { I(); Serial.print(" "); } else if (ch == 'J' || ch == 'j') { J(); Serial.print(" "); } else if (ch == 'K' || ch == 'k') { K(); Serial.print(" "); } else if (ch == 'L' || ch == 'l') { L(); Serial.print(" "); } else if (ch == 'M' || ch == 'm') { M(); Serial.print(" "); } else if (ch == 'N' || ch == 'n') { N(); Serial.print(" "); } else if (ch == 'O' || ch == 'o') { O(); Serial.print(" "); } else if (ch == 'P' || ch == 'p') { P(); Serial.print(" "); } else if (ch == 'Q' || ch == 'q') { Q(); Serial.print(" "); } else if (ch == 'R' || ch == 'r') { R(); Serial.print(" "); } else if (ch == 'S' || ch == 's') { S(); Serial.print(" "); } else if (ch == 'T' || ch == 't') { T(); Serial.print(" "); } else if (ch == 'U' || ch == 'u') { U(); Serial.print(" "); } else if (ch == 'V' || ch == 'v') { V(); Serial.print(" "); } else if (ch == 'W' || ch == 'w') { W(); Serial.print(" "); } else if (ch == 'X' || ch == 'x') { X(); Serial.print(" "); } else if (ch == 'Y' || ch == 'y') { Y(); Serial.print(" "); } else if (ch == 'Z' || ch == 'z') { Z(); Serial.print(" "); } else if (ch == '0') { zero(); Serial.print(" "); } else if (ch == '1') { one(); Serial.print(" "); } else if (ch == '2') { two(); Serial.print(" "); } else if (ch == '3') { three(); Serial.print(" "); } else if (ch == '4') { four(); Serial.print(" "); } else if (ch == '5') { five(); Serial.print(" "); } else if (ch == '6') { six(); Serial.print(" "); } else if (ch == '7') { seven(); Serial.print(" "); } else if (ch == '8') { eight(); Serial.print(" "); } else if (ch == '9') { nine(); Serial.print(" "); } else if(ch == ' ') { delay(unit_delay*7); Serial.print("/ "); } else Serial.println("Unknown symbol!"); } void String2Morse() { len = code.length(); for (int i = 0; i < len; i++) { ch = code.charAt(i); morse(); } } void setup() { Serial.begin(9600); pinMode(led, OUTPUT); //pinMode(tone, OUTPUT); Serial.println("I am ready..."); } void loop() { while (Serial.available()) { code = Serial.readString(); Serial.print(code); Serial.print(" = "); String2Morse(); Serial.println(""); } delay(1000); }