Project 3 : Make Internal Sensor With ESP32

๐Ÿ‘‰๐Ÿ‘‰๐Ÿ‘‰๐Ÿ‘‰๐Ÿ‘‰๐Ÿ‘‰๐Ÿ‘‰๐Ÿ‘‰๐Ÿ‘‰๐Ÿ‘‰๐Ÿ‘‰๐Ÿ‘‰๐Ÿ‘‰๐Ÿ‘‰๐Ÿ‘‰๐Ÿ‘‰๐Ÿ‘ˆ๐Ÿ‘ˆ๐Ÿ‘ˆ๐Ÿ‘ˆ๐Ÿ‘ˆ๐Ÿ‘ˆ๐Ÿ‘ˆ๐Ÿ‘ˆ๐Ÿ‘ˆ๐Ÿ‘ˆ๐Ÿ‘ˆ๐Ÿ‘ˆ๐Ÿ‘ˆ๐Ÿ‘ˆ

Hello everyone ๐Ÿ‘‹, and welcome back to my blog. In this edition , I will create third ESP32 projects that will make use of internal MCU sensors. The first  project will experiment with touch sensors by transforming jumper cables into touch sensors . The Hall Effect Sensor, which is available in the ESP32 module, will then be used in the second project. All of the projects we will work on are variations on the basic manual instructions found at the following link.

1.ESP32 Capacitive Touch Sensor Pins with Arduino IDE

2.ESP32 Built-In Hall Effect Sensor with Arduino IDE and MicroPython

ESP32 Internal Temperature Sensor Example

Let's just get to work on the project. Before we begin working on these two projects, we must first prepare.

/**********************************************************************************/

๐Ÿ”งSET UP๐Ÿ”ง 

1. 1 Pcs of ESP32


2. 4 Pcs of Male to Female Cable Jumper


3.  2 Pcs of Male to Male Cable Jumper

4. 2 Pcs of 5 mm Led Lamp 



5. 1 Pcs of Magnet (any kind of magnet)



6. 2 Pcs of 330 Ohm Resistor


7. 1 Pcs of Micro USB cable



ESP 32 BASIC SCHEMA



This is the ESP32 Devkit schematic; instructions for the next project will be based on the ESP32 Devkit schematic shown above.


FIRST PROJECT 

ESP32 Capacitive Touch Sensor Pins with Arduino IDE


When the touch sensor is touched by an object, in this case our hands, the led light blinks alternately with a 500 ms delay. Meanwhile, if no object touches the touch sensor, the light will not blink.

STEP BY STEP : 

1. Perform a series of ESP 32 as shown below.


Basic Schema

Circuit Schema

Additional Circuit Schema

2. Check that your Male to Female cable is properly connected to the GPIO16 (RX2) and GPIO17 (TX2) channels. It connects two LED lights to our MCU. Also, remember to connect the Male to Female cable to the GPIO4 (D4) channel, which serves as a touch sensor.

3.Copy the following code into our Arduino IDE.
-----------------------------------------------------------------------------------------------------------------------------
// set pin numbers
const int touchPin = 4; //For GPIO04 Channel
const int ledPin = 16; //For GPIO16 Channel
const int ledPin2 = 17; //For GPIO17 Channel

// change with your threshold value
const int threshold = 20;
// variable for storing the touch pin value 
int touchValue;

void setup(){
  Serial.begin(115200);
  delay(1000); // give me time to bring up serial monitor
  // initialize the LED pin as an output:
  pinMode (ledPin, OUTPUT);
  pinMode (ledPin2 , OUTPUT);
}

void loop(){
  // read the state of the pushbutton value:
  touchValue = touchRead(touchPin);
  Serial.print(touchValue);
  // check if the touchValue is below the threshold
  // if it is, set ledPin to HIGH
  if(touchValue < threshold){
    // turn first LED on and second LED off
    digitalWrite(ledPin, HIGH);
    digitalWrite(ledPin2 , LOW);
    delay(500); // add a delay for 500 ms
     // turn first LED off and second LED on
    digitalWrite(ledPin,LOW);
    digitalWrite(ledPin2 , HIGH);
    delay(500);

    Serial.println(" - LED on");
  }
  else{
    // turn all LED off
    digitalWrite(ledPin, LOW);
    digitalWrite(ledPin2 , LOW);
    Serial.println(" - LED off");
  }
  delay(500);
}
-----------------------------------------------------------------------------------------------------------------------------
4. Insert the Micro USB Cable into our USB port.

5. Click the "Upload" button and wait a few seconds for the words "Done Uploading" to appear.




6. Then, using the male jumper cable as a touch sensor, open the serial monitor or serial plotter, which can be found on the Tools tab, with a serial baud value of 115200 to see the data changes that have occurred.


Go to Tools > Serial Monitor




7. Monitor changes in conditions on the LED lights and data read on the serial monitor or serial plotter.



SECOND PROJECTS

ESP32 Built-In Hall Effect Sensor with Arduino IDE and MicroPython


The ESP32 development board includes a hall effect sensor, which detects changes in the magnetic field around it. This tutorial will show you how to use the ESP32 hall effect sensor with the Arduino IDE. A hall effect sensor can detect changes in the magnetic field around it. The sensor's output voltage increases as the magnetic field increases. In this project, a positive value on the serial monitor indicates a very strong magnetic field. If the value on the serial monitor is negative, it indicates that the magnetic field is quite weak. Aside from that, another visible indicator is the LED light that we installed on our breadboard.If the red LED illuminates, it indicates that the magnetic field is strong enough. Meanwhile, if the blue LED lights up, the magnetic field is relatively weak.

STEP BY STEP: 
1. Perform a series of ESP 32 as shown below.





2. Check that your Male to Female cable is connected to the GPIO17 (TX2) and GPIO18 (D18) channels. It is used to connect two LED lights to our MCU.

3.Copy the modified code below. In this case, sprintf(buffer, "The Value:%d", val) prints a String to the serial monitor screen in the desired string format.

-----------------------------------------------------------------------------------------------------------------------------
const int ledPin = 17; //For GPIO17 Channel
const int ledPin2 = 18;//For GPIO18 Channel


int val = 0;

void setup() {
  Serial.begin(9600);
  pinMode (ledPin, OUTPUT); //Set up first LED to ESP32 Module
  pinMode (ledPin2 , OUTPUT); //Set up second LED to ESP32 Module
}

// put your main code here, to run repeatedly
void loop() {
  // read hall effect sensor value
  val = hallRead();
  // print the results to the serial monitor
  if(val < 0){
    //If Magnetic Field Value below 0 , then first LED will turn on
    //and second LED will turn off
    digitalWrite(ledPin, HIGH);
    digitalWrite(ledPin2 , LOW);
    //Serial.println(" - LED on");
  }
  else{
    //If Magnetic Field Value below 0 , then first LED will turn off
    //and second LED will turn on
    digitalWrite(ledPin,LOW);
    digitalWrite(ledPin2, HIGH);
    //Serial.println(" - LED off");
  }
  //make a spesific string value that printed on serial monitor
  char buffer[40];
  sprintf(buffer, "The Value : %d ", val);
  Serial.println(buffer);
  delay(1000);
}
---------------------------------------------------------------------------------------------------------------------------
4. Insert the Micro USB Cable into our laptop USB port.

5. Click the "Upload" button and wait a few seconds for the words "Done Uploading" to appear.



6. Finally, place the magnet on top of your ESP32 mini module. Change the magnetic poles or move away from the magnet to bring it closer to the ESP32 mini module.

7. Pay attention to the changes in the LED lights on your breadboard. Furthermore, you can view the magnetic field value data using the serial monitor, which is available in the Tools > Serial Monitor section and has a serial baud value of 9600.




THIRD PROJECTS

ESP32 Internal Temperature Sensor

Internal temperature sensors are found in some ESP32 modules. However, the temperature sensor reading is constant because the module lacks an external temperature sensor. Because the value reading from the internal temperature sensor is constant, I will add the output on the serial monitor to this project.
STEP BY STEP: 
1. Perform a series of ESP 32 as shown below.



2.Copy the modified code below. This time, I'll change the program's output so that it prints in the Celsius, Farenheit, and Reamur scales.

/* 
 *  https://circuits4you.com
 *  ESP32 Internal Temperature Sensor Example
 */

 #ifdef __cplusplus
  extern "C" {
 #endif

  uint8_t temprature_sens_read();

#ifdef __cplusplus
}
#endif

uint8_t temprature_sens_read();
//====================================================
//         Setup
//====================================================
void setup() {
  Serial.begin(115200);
}

//====================================================
//         Loop
//====================================================
void loop() {
  Serial.print("Temperature: ");
  
  // Convert raw temperature in F to Celsius degrees
  Serial.print((temprature_sens_read() - 32) / 1.8);
  Serial.print(" C / ");
  // Print temperature in Fahrenheit
  Serial.print((temprature_sens_read()));
  Serial.print(" F / ");
  // Convert raw temperature in F to Reamur degrees
  Serial.print((temprature_sens_read()- 32) / 2.25);
  Serial.println(" R ");
  delay(1000);
}

4. Click the "Upload" button and wait a few seconds for the words "Done Uploading" to appear.

5.View the readings on the serial monitor screen. The trick is to click Tools > Serial Monitor, then click 115200 baud, and it should be noted that the resulting output will have a constant value because an external temperature sensor is required to take an accurate temperature reading.




๐Ÿ˜ŽHooray, we've finished all of the projects we needed for today's internal sensors.๐Ÿ˜Ž  See you in my next blog with ESP32.

 



Comments

Popular posts from this blog

Project 7 : Connecting ESP32 and our smartphone with bluetooth connection