SOS video

Here you will see a video showing the functioning of the ESP-WROOM-32 circuit with a SOS code

Firts code


/***
 * LED Blinking
 * Code Written by Miquel García and Xavier Garrido
 */ 
const int ledPin = 2; //The LED is connected in PIN D2
void setup() {
  // setup pin 2 as a digital output pin because the light goes out, a digital input would be a sensor
  pinMode (ledPin, OUTPUT); 
}
void loop() { //This is a loop, which means that when the code has been recreated by the chip, once it is finished it will start over.
  digitalWrite (ledPin, HIGH);  // turn on the LED 
  delay (200); // wait for half a second or 200 milliseconds
  digitalWrite (ledPin, LOW); // turn off the LED
  delay (200); // wait for half a second or 200 milliseconds
  digitalWrite (ledPin, HIGH);
  delay (200);
  digitalWrite (ledPin, LOW);
  delay (200);
  digitalWrite (ledPin, HIGH);
  delay (200);
  
  digitalWrite (ledPin, LOW);//This is the time between the fisrt letter and the second
  delay (600);

  digitalWrite (ledPin, HIGH);
  delay (600);
  digitalWrite (ledPin, LOW);
  delay (200);
  digitalWrite (ledPin, HIGH);
  delay (600);
  digitalWrite (ledPin, LOW);
  delay (200);
  digitalWrite (ledPin, HIGH);
  delay (600);
  
  digitalWrite (ledPin, LOW);//This is the time that separates the second letter from the third
  delay (600);

  digitalWrite (ledPin, HIGH);
  delay (200);
  digitalWrite (ledPin, LOW);
  delay (200);
  digitalWrite (ledPin, HIGH);
  delay (200);
  digitalWrite (ledPin, LOW);
  delay (200);
  digitalWrite (ledPin, HIGH);
  delay (200);
  
  digitalWrite (ledPin, LOW); //This waiting time is the longest, since it expresses that the word has finished and another word would start
  delay (1400);
}

Second code


/***
 * LED Blinking
 * Code Written by Miquel García and Xavier Garrido
 */
int ledPin = 2; //The LED is connected in PIN D2

//The first step is defining the constants. Defining the constants means applying the module individually, when creating a letter, for example, only having to put the name assigned 
//to each value, in this way if we make a mistake we only have to change it here and not at each point in which be applied.
const int dot = 200;
const int dash = dot*3;
const int space = dot*7;
void setup() {
  // setup pin 2 as a digital output pin because the light goes out, a digital input would be a sensor
  pinMode (ledPin, OUTPUT);
}
//In this case we also have a loop, but previously we are defining the letters, that is, we are giving a value 
//to each letter, in this way creating a word is easier because in the loop you only have to put the letter and here we put what okay. A "more orderly" way.
void S() {  
 digitalWrite (ledPin, HIGH);
 delay (dot);
 digitalWrite (ledPin, LOW);
 delay (dot); 
 digitalWrite (ledPin, HIGH);
 delay (dot);
 digitalWrite (ledPin, LOW);
 delay (dot);
 digitalWrite (ledPin, HIGH);
 delay (dot);
 digitalWrite (ledPin, LOW);
 delay (dash); 
}

void O() {
 digitalWrite (ledPin, HIGH);
 delay (dash);
 digitalWrite (ledPin, LOW);
 delay (dash); 
 digitalWrite (ledPin, HIGH);
 delay (dash);
 digitalWrite (ledPin, LOW);
 delay (dash);
 digitalWrite (ledPin, HIGH);
 delay (dash);
 digitalWrite (ledPin, LOW);
 delay (dash);   
}  

void loop (){ //Now we find ourselves with the loop again, but in this case, as we can see, only the letters that we want to put are necessary, because the values have been given before.
 S(); 
 O();
 S();

digitalWrite (ledPin, LOW);
delay (space);
}

Third code


/***
 * LED Blinking
 * Code Written by Miquel García and Xavier Garrido
 */
int ledPin = 2;
//In this code we will be using functions. The typical case for creating a function is when one needs to perform the same 
//action multiple times in a program.
void setup() {  // put your setup code here, to run once:
  pinMode (ledPin, OUTPUT);
}
void flash(int nf, int d){ //Here I'm defining one parameter, in our case we will us it for the dot
 for(int i = 0; i < nf; i++){
 digitalWrite (ledPin, HIGH);
 delay (d);
 digitalWrite (ledPin, LOW);
 delay (d);
 }
}
void sent(int nf, int d){ //Here I'm defining one parameter, in our case we will us it for the dash
 for(int i = 0; i < nf; i++){ 
 digitalWrite (ledPin, HIGH);
 delay (d);
 digitalWrite (ledPin, LOW);
 delay (d/3);
 }
}
void loop() { // put your main code here, to run repeatedly:
 flash(3,200); //This means that the letter S is made up of three dots, therefore we will need to flash three times as 
               //indicated in the parentheses and each dot for 200 milliseconds (morse code rules).
 digitalWrite (ledPin, LOW); //Adding this LOW to separate the letter S with the O
 delay (400);
 sent(3,600); //In this second case, we use only the sent function because, as in the case of S, it is made up of only one  
              //group of functions, in this case three lines, which must be three times the duration of a dot, therefore 600 milliseconds.
 digitalWrite (ledPin, LOW); //Adding this LOW to separate the letter O with the S
 delay (400);
 flash(3,200);
 digitalWrite (ledPin, LOW); //Adding this LOW to indicate that the word has been finished.
 delay (1200);
}

Fourth code


/***
 * LED Blinking
 * Code Written by Miquel García and Xavier Garrido
 */
const byte ledPin = 2;

void setup()

// Use ledPin as output

pinMode(ledPin, OUTPUT)

//Create a function for short blink

void shortBlink()

// Make a single short blin

digitalWrite(ledPin, HIGH)

delay(200)

digitalWrite(ledPin, LOW)

delay(200)

void longBlink()

// Make a single long blink

digitalWrite(ledPin, HIGH)

delay(600)

digitalWrite(ledPin, LOW)

delay(200);

}

void morseBlink(char character) {

// Translate character to Morse code

switch(character){

case ‘s‘:

shortBlink();

shortBlink();

shortBlink();

break;

case ‘o‘:

longBlink();

longBlink();

longBlink();

break;

}

}

void loop() {

// Start blinking SOS

morseBlink(‘s‘);

morseBlink(‘o‘);

morseBlink(‘s’);

}

Fifth code


//According to the wikipedia article on Morse Code:
//A ‘dash’ should be three times the length of a ‘dot’.
//The time between dots or dashes in a letter should be that same as the time for a dot.
//The time between letters should be three dot times.int ledPin = 13;
int ledPin = 2;
const int DOT = 150;
const int DASH = DOT * 3;

int durations[] = {DOT, DOT, DOT, DASH, DASH, DASH, DOT, DOT, DOT};

void setup() {
pinMode(ledPin, OUTPUT);
}

void loop() {
for (int i = 0; i < 9; i++) {
flash(durations[i]);
if (i == 2 || i == 5)
delay(DASH - DOT); // inter-letter additional time
}
delay(1000);
}

void flash(int duration) {
  
digitalWrite(ledPin, HIGH);
delay(duration);
digitalWrite(ledPin, LOW);
delay(DOT);
}

Sixth code


// Morse code for blinking a LED
//The fact of this code is that it has the capacity to interpret in this case the words that we write in our language to Morse language, therefore,
//we have to define the letters one by one, just like the numbers and then a sequence of parameters with the ability to transform what we write.
int ledPin = 2;
int dotDelay = 200;

char* letters[] = {
  ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..",    // A-I
  ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.",  // J-R
  "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."          // S-Z
};

char* numbers[] = {
  "-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----."}; 

void setup()                 
{
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}

void loop()                    
{
  char ch;
  if (Serial.available() > 0)
  {
    ch = Serial.read();
    if (ch >= 'a' && ch <= 'z')
    {
      flashSequence(letters[ch - 'a']);
    }
    else if (ch >= 'A' && ch <= 'Z')
    {
      flashSequence(letters[ch - 'A']);
    }
    else if (ch >= '0' && ch <= '9')
    {
      flashSequence(numbers[ch - '0']);
    }
    else if (ch == ' ')
    {
      delay(dotDelay * 4);  // gap between words  
    }
  }
}

void flashSequence(char* sequence)
{
  int i = 0;
  while (sequence[i] != NULL)
  {
    flashDotOrDash(sequence[i]);
    i++;
  }
  delay(dotDelay * 3);    // gap between letters
}

void flashDotOrDash(char dotOrDash)
{
  digitalWrite(ledPin, HIGH);
  if (dotOrDash == '.')
  {
    delay(dotDelay);           
  }
  else // must be a dash
  {
    delay(dotDelay * 3);           
  }
  digitalWrite(ledPin, LOW);    
  delay(dotDelay); // gap between flashes
}
    
   

Problems without solve (yet)

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 Tone32 could be recognized and work correctly. Once that library was downloaded and applied, 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.

Solution of the previous problems

The solution of the problem is so easy, it's to download the ESP32servo library in arduino.
Rstudio
Here you have a code using ESP32servus library

Seventh Code

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 "Tone32" could be recognized and work correctly. Once that library was downloaded and applied, 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.
Finally, we got it to ring and light at the same time from two libraries found in the code number 7 ("Tone32" and "ESP32Servo"), those ones have allowed to create accesses that make the board and Arduino compatible.
Here you will see a video showing the functioning of the ESP-WROOM-32 circuit with a SOS code adding a speaker

#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 (from github: https://github.com/jkb-git/ESP32Servo) in order to enable all the functions, because the ESP-Wroom 32 
//board does not support all the functions

#include < pitches.h >
#include < Tone32.h >
//Here we include Tone32 (from github: https://github.com/lbernstone/Tone32), this is necessary so that our board can correctly read 
//the speaker's "tone" function, a function that allows you to control the frequency and duration of the sound

// 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 
//that 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);
}