ESP32-CAM Getting Started – Mac

ESP32-CAM getting started - mac
Before you can start using the ESP32-CAM board (or similar ESP32 boards) with the Arduino IDE, you need to install the board support package which will enable the Arduino IDE to compile the sketches and upload them to the ESP32-CAM board. Doing this is very simple and we will cover that in this post.

Step 1: Install the latest Arduino IDE for your system. I’ll be using v1.8.10 for this post.

Visit the following link to download the latest version: https://www.arduino.cc/en/main/software

Step 2: Add the ESP32 URL to the boards manager.

To do this, open up the preferences window from the Arduino menu:

Open up the additional URLs window by clicking the icon shown below:

Add the following URL to the window. If you already have an existing URL, then simply add this to a new line, like below:
https://dl.espressif.com/dl/package_esp32_index.json

Step 3: Install the ESP32 Package

To do this, you need to open up the boards manager from the Tools menu and then search for “ESP32”.


Click the install button and wait for it to complete.


Once completed, you can then close the window and move to the next step.

Step 4: Wire up the board

You will need an external USB to serial converter to download code to the ESP32-CAM board. Please make sure you supply a steady 5V supply to the board and it is recommended to use a separate USB breakout board to supply the power. Using power from the FTDI (or similar) USB breakout board is known to cause issues depending on the setup.
ESP32-CAM Wiring For Sketch Upload

Step 5: Select the right board and settings

Use the following image as a reference. These are the options for the ESP32-CAM board and your port will vary depending on your computer system.

Step 6: Test the board

First, open up the WiFiScan example sketch which will simply scan available WiFi networks and display this on the serial port.

Make sure you have the boot jumper in place, then power up the board and press the reset button. This will put the board in the sketch upload mode. Hit the upload button and once this is complete, remove the jumper and press the reset button again. Finally, open up the serial monitor from the Tools menu. If everything works well, then you should be able to obtain an output similar to the one shown below. The WiFi network names will be different for you.

That’s it. You’ve successfully installed the ESP32 board and you can now start working with ESP32-CAM projects.

ESP32-CAM Getting Started – Windows

ESP32-CAM getting started - windows
Before you can start using the ESP32-CAM board (or similar ESP32 boards) with the Arduino IDE, you need to install the board support package which will enable the Arduino IDE to compile the sketches and upload them to the ESP32-CAM board. Doing this is very simple and we will cover that in this post.

Step 1: Install the latest Arduino IDE for your system. I’ll be using v1.8.8 for this post.

Visit the following link to download the latest version: https://www.arduino.cc/en/main/software

Step 2: Add the ESP32 URL to the boards manager.

To do this, open up the preferences window from the File menu:

Open up the additional URLs window by clicking the icon shown below:

Add the following URL to the window. If you already have an existing URL, then simply add this to a new line, like below:
https://dl.espressif.com/dl/package_esp32_index.json

Step 3: Install the ESP32 Package

To do this, you need to open up the boards manager from the Tools menu and then search for “ESP32”.


Click the install button and wait for it to complete.


Once completed, you can then close the window and move to the next step.

Step 4: Wire up the board

You will need an external USB to serial converter to download code to the ESP32-CAM board. Please make sure you supply a steady 5V supply to the board and it is recommended to use a separate USB breakout board to supply the power. Using power from the FTDI (or similar) USB breakout board is known to cause issues depending on the setup.
ESP32-CAM Wiring For Sketch Upload

Step 5: Select the right board and settings

Use the following image as a reference. These are the options for the ESP32-CAM board and your COM port will vary depending on your computer system.

Step 6: Test the board

First, open up the WiFiScan example sketch which will simply scan available WiFi networks and display this on the serial port.

Make sure you have the boot jumper in place, then power up the board and press the reset button. This will put the board in the sketch upload mode. Hit the upload button and once this is complete, remove the jumper and press the reset button again. Finally, open up the serial monitor.

If everything works well, then you should be able to obtain an output similar to the one shown below. The WiFi network names will be different for you.

That’s it. You’ve successfully installed the ESP32 board and you can now start working with ESP32-CAM projects.

ESP32-CAM

ESP32 Troubleshooting Guide

ESP32 troubleshooting guide
This post is dedicated to troubleshooting the common ESP32 errors that we will come across as we work with it.

1: “An error occurred while uploading the sketch. A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header”

This is the first error we encountered and it took us a while to figure out what was going wrong. We followed the wiring instructions online but most of the common ones that were available were incorrect and not reliable for some of the ESP32 boards, particularly the ESP32-CAM board.

If you get the error shown above then this is most likely due to incorrect wiring or insufficient power being applied to the board which is causing it to boot-loop or not power at all. If you are using the ESP32-CAM board, then please make sure that you wire the board as shown below and do not forget to connect the 5V power source to the 5V pin.

ESP32-CAM Wiring For Sketch UploadESP32-CAM Wiring For Sketch Upload

If the error persists then measure the voltage at the 5V pin as it has to be close to 5V, we noticed inconsistent operation when the supply voltage drops to even 4.7V. So make sure you have a good 5V power source or use a USB breakout board to obtain it. Using the power from the FTDI (FT232 or other USB-serial) breakout board also leads to the error shown above, on some boards. If you are sure about the 5V power then make sure you have wired the Tx and Rx pins correctly, try swapping them to check.

How To Check If The ESP32-CAM Is Working Correctly

The simplest way to make sure that you have the wiring and power required to upload code to the ESP32 board (ESP32-CAM in this case) is to wire it as following, in the boot mode and then open up the serial monitor with a baud rate of 115200.

ESP32-CAM Wiring For Sketch UploadESP32-CAM Wiring For Sketch Upload

Then, press the reset button and make sure you get output similar to the one shown below:

ESP32 Serial Output Sketch Upload Boot ModeESP32 Serial Output Sketch Upload Boot Mode

If you receive an output like this, then you can be sure that the Tx, Rx pins are connected correctly and that the board is safely powered ON. Once you upload the sketch and remove the boot-mode jumper, the output will change and it is recommended to keep the serial monitor open to view any errors or resets. If sufficient power is not available then the board will reset itself and throw a “Brownout detector was triggered” error to the serial terminal.

VU Meter (LM3915) – B2P20

The LM3915 is another popular IC that can be used to build interesting circuits. It is designed to drive 10 LEDs depending on the analog voltage signal applied to the input.

VU meter

The LM3915 has an adjustable voltage reference and each of the LEDs represent a 3dB step, this makes it a perfect chip to build a volume unit meter or VU meter.

VU meter

It can only handle one input at a time, so we use two LM3915 ICs to handle both the channels. The audio signal from the Bluetooth receiver is of low amplitude and we use an LM358 op-amp to amplify this.

VU meter

Since the LM358 contains two individual op-amps, a single IC is sufficient for both the channels. The circuit for the right and left channels are identical so we can simply look at the right channel for now.

VU meter

The audio input is first fed into the op-amp which increases the signal amplitude by approximately 8 times. The signal is then passed through a capacitor to block the DC component and is then passed through a trimpot, the output of which is fed into the LM3915 IC.

VU meter

As we will see later, the trimpot allows us to adjust the output signal and this would only need to be done once. Resistors R10 and R11 set the reference voltage which is about 450mV when the circuit is powered with 5V. R12 is used to set the LED brightness.

VU meter

This is what the assembled PCB looks like. Let’s connect the audio output from the Bluetooth speaker PCB to the VU meter and let us switch ON the power supply. We can adjust the audio level that is fed to the LM3915 by adjusting the potentiometers. By default, the LM3915 represents the audio level by illuminating a single LED corresponding to the audio level, but since the actual audio signal level changes rapidly, we not only see the peak, but also the lower audio levels that build-up to the peak.

VU meter

Adding a jumper to the mode pin will switch the LM3915 into the bar mode, which illuminates the LED corresponding to the peak audio signal level and all the others below it. One thing to note is that even though we have the same amount of current flowing through the LEDs the green LED appears to be much brighter than rest. One way around this would be to add individual current limiting resistors for the green LEDs.

Bluetooth Speaker System (Audio Blobs) – B2P19

Building a Bluetooth speaker from the ground-up is a challenging task, but thankfully, we have pre-programmed modules that can be used to make it much simpler. We will use one such Bluetooth audio module to build a Bluetooth speaker.

Bluetooth Speaker System

The BBox 2 contains two modules called blobs, which further simplifies the building process. One consists of a pre-programmed Bluetooth audio module and the other consists of two class D amplifier ICs. The Bluetooth audio blob consists of a CSR8645 Bluetooth receiver that handles all the Bluetooth related tasks and gives us the audio output.

Bluetooth Speaker System

The Bluetooth audio blob is represented as U$1 in the schematic. We connect the power pins, two status LEDs along with the volume control switches.

Bluetooth Speaker System

The MFB pin acts like an enable pin and the RC circuit consisting of R3, R4 and C3 creates a short delay which is needed as per the design spec for the CSR8645 module. The audio output is sent to the two individual amplifier ICs after passing through a capacitor which is used to block any DC component contained in the signal.

The amplifier ICs themselves are extremely simple. All they need is power and a bypass capacitor to produce an output. We add some filtering and reservoir capacitors to absorb any surges in the current, particularly at high volumes. The control pin can be used to mute the audio output and we connect this to a switch. The output from the audio amplifiers is fed directly to the speakers.

The PCB also contains 4 probe points that can be used to extract the audio signal from the Bluetooth receiver and use it in external circuits. We will be using these in the next project which creates a visual effect from the audio signal.

Bluetooth Speaker System

Assembling the PCB is not difficult but please ensure that the capacitors are placed with the correct polarity. You will also need to solder the header pins to the two blobs. Please ensure that you insert the blobs with the correct orientation and there are hints on the main PCB to help you with this. The Bluetooth audio blob requires 3.3V while the amplifier uses 5V, so ensure that you have connected the correct voltages to each of the screw terminals.

Bluetooth Speaker System

When the PCB is powered ON, the two LEDs will start to flash quickly indicating that no device has been paired with the receiver.

Bluetooth Speaker System

Head over to your Bluetooth device and select the receiver which would either show up as CSR8645 or F-3188. Once paired, the LEDs will stop flashing continuously. You will now be able to play audio from your Bluetooth device and this should playback on your speakers.

One thing to keep in mind is that the speaker enclosure plays a huge role in determining audio quality. Leaving them on your table is certainly not going to give you the best sounding audio. In fact, simply holding them with your hands and rotating them will change the way they sound. We recommend placing them in an enclosure to enhance the audio quality.

Bluetooth Speaker System

Bluetooth Speaker System

There are many ways by which you could create a DIY enclosure, you can even cut a few holes in the box and add the speakers, PCB and battery inside to create a portable Bluetooth speaker.

Bluetooth Speaker System

Alternatively, you can add the speakers to either end of a can for a better-looking system.
With that being said, lets now work on the final project which helps us create a visual effect.

Voice Recorder (ISD1820) – B2P18

We will now use the ISD1820 IC to build a voice recorder. The ISD1820 is a dedicated voice recorder IC and we will be using the reference circuit contained in the datasheet.

Voice recorder

The ISD1820 works at a maximum of 3.3V, so make sure you connect the right voltage output before powering it ON. An electret microphone is used to capture audio and the output from this is passed to the IC. We have 3 switches that are used for recording and playback along with a status LED.

Voice recorder

Resistor R2 is used to set the recording duration and sample rate. A higher sample rate produces a much better recording but this sacrifices the recording time.

Voice recorder

The IC starts recording audio the moment the REC button is pressed and the RED LED is used to indicate this. Pressing the PLAYE button will cause the audio to play till the end, while pressing the PLAYL button will cause the audio to play, as long as the button is pressed. The PCB also contains holes for a header pin which can be used to interface the IC to a microcontroller. This will allow you to trigger the recording and playback remotely.

Combination Lock (XOR + NOR Gates) – B2P17

We will now look at two new logic gates and we will use them to create an extremely basic combination lock.

Combination lock

The 74HC86 consists of 4 XOR gates which have 2 inputs each. The output of an XOR gate is LOW when both the inputs are the same (either HIGH or LOW) and the output is HIGH in all other cases.

Combination lock

The 74HC02 consists of 4 NOR gates which have two inputs each. The output of a NOR gate is HIGH when both the inputs are LOW and the output is LOW in all other cases.

The combination lock works on the following principle. We have a known good combination, also called the key which is compared to the user input. If the two are a match, then the green LED will glow, otherwise, the red LED will glow.

Combination lock

Let’s assume that SW1 is the key, while SW2 is the user input. We’ve added pull-down resistors to give us a known LOW state and all these switches are connected as inputs to the XOR gate in pairs. This means that switch 1 from both SW1 and SW2 are connected to the same XOR gate and so on. The outputs of all 4 XOR gates are connected to 4 diodes which are then connected to a pull-down resistor. If all 4 user input switches match the reference key, then the outputs of all 4 XOR gates will be LOW. In all other cases, the combined output will be HIGH which will cause a voltage drop across R10. This output voltage is used as the input for the 74HC02 NOR gates.

Combination lock

The output is first fed into both the inputs of the first NOR gate. This results in the signal being inverted and this is fed into input A of the second NOR gate. Input 2B is connected to the switch which pulls the pin LOW when pressed. NOR gate 2 is responsible for controlling the ERROR LED. If the user input did not match the key, then the output from the XOR IC would be HIGH. This is inverted by the first gate to give us a logic LOW. This logic LOW will be compared with the logic LOW input from the switch, and the resulting NOR operation would give us a logic HIGH which would cause the ERROR LED to glow. In all other cases, the ERROR LED would receive a logic LOW, keeping it OFF.

Input 3A directly receives the output from the XOR gate, while input 3B receives the input from the switch. If the user input matched the key, then the XOR IC output would be LOW. This LOW value would be compared with the LOW value from the key and the resulting NOR operation would be a logic HIGH which would cause the OK LED to glow. In this way, we can demonstrate the working of a very simple 4-bit combination lock.

Combination lock

Here’s what the assembled PCB looks like. Please ensure that the ICs are placed with the right orientation. This project demonstrates the principles of logic gates and in reality, the combination lock would have to have much more than 16 combinations for it to be effective. It would be much easier to use a numeric keypad along with a microcontroller to set and verify the user entered key. All logical operations can be carried out with software, preventing the need for external logic ICs. Let’s move on to the next project.

LED Heartbeat Circuit (LM358) – B2P16

The heartbeat or breathing circuit is a nice little LED project that makes use of a relatively simple circuit. We’ve used the LM358 op-amp in the previous project and to quickly recap: it’s an analog device whose output is the difference between the voltages at its two input terminals.

LED heartbeat

Transistor Q1 is used to control the LEDs and it will switch from the cut-off to linear, to saturation region depending on the voltage applied at its base terminal. Internally, the LM358 contains two op-amps which are both being used in this circuit. The op-amp section is designed to give us a ramp-like output that is fed to the base of the transistor which in turn controls the LEDs.

LED heartbeat

The positive terminal of U1G1 is connected to a voltage divider network consisting of R1 and R2. The values of R1 and R2 keep the positive terminal at a fixed voltage that is half of the supply voltage. The negative terminal is connected to the capacitor C1. When first switched ON, the output of U1G1 is HIGH and this causes the capacitor to start charging with the polarity as shown. The ramp waveform is in its rising phase which causes the LEDs to start glowing brighter.

LED heartbeat

The ramp output voltage is also fed back to the positive terminal of U1G2, while the negative terminal of U1G2 is held at the same reference voltage from the R1-R2 voltage divider network. The output of U1G2 will increase as the voltage difference between its input terminals increases. This output is connected to the left terminal of C1 and eventually, it will be at a higher potential compared to the right terminal. At this point, the output of U1G1 will start decreasing and the capacitor will start to discharge and charge with the opposite polarity. The output ramp voltage enters the falling phase, which causes the LEDs to fade away.

LED heartbeat

This ramp cycle repeats continuously and VR1 can be adjusted to change the ramp speed. Here’s what the assembled PCB looks like. Please be sure to place all the LEDs with the right polarity.

Electronic Candle Circuit (555 + LM358) – B2P15

We’re going to now build an electronic candle using a 555 timer and an op-amp.

To give us a candle-like effect, we will be using a flicker LED which has two terminals and can be used as a standard LED.

Electronic Candle

This is what the schematic looks like. We configure the 555 timer in the bistable mode, meaning it has two stable states – SET and RESET, just like an SR flip-flop. The state of the 555 timer is controlled by the voltages at pins 2 and 6.

We use a voltage divider consisting of an LDR to trigger the timer IC. When we bring a flame close to the LDR or if we shine a bright light on it, it’s resistance will decrease and this will reduce the voltage at pin 2. If this voltage falls below 1/3rd of the supply voltage, then it will cause the output of the timer IC to go HIGH, switching ON the LED.

The voltage at pin 6 is responsible to RESET the timer IC or switch OFF the LED. If the voltage at pin 6 rises above 2/3rd of the supply voltage, then the timer IC will be RESET. The circuit consists of an op-amp, whose output is connected to pin 6. The inputs of the op-amp can be connected to two voltage divider circuits. One consists of a 100 Ohm resistor and thermistor, while the other is made up of a 2.2K resistor and 10K trimpot. The op-amp we are using is the LM358 whose output voltage is the difference between the two input voltages. The output of an op-amp is analog in nature, i.e it gives us the actual difference in the inputs, while the output of a comparator is digital in nature as it gives us a logic HIGH when the positive input is at a greater voltage compared to the voltage at the negative input.

The idea behind the design of the electronic candle is that one could blow air over the thermistor which would change its resistance and this could then be used to trigger the comparator. There are two hurdles that must be overcome to achieve this. Firstly, blowing air over the thermistor is only going to change the resulting voltage divider output by a few hundred millivolts. This means that the other input to the comparator must be matched closely to the ambient output voltage. This can be done by adjusting VR1.

The second concern is that the response of the thermistor will depend on the ambient temperature relative to the temperature of the air being blown. If the air being blown over the thermistor is cooler than the ambient temperature then the resistance of the thermistor will increase as it has a negative temperature coefficient. This will cause an increase in the voltage divider output. On the other hand, if the air being blown over the thermistor is warmer than the ambient temperature, then it will decrease the thermistor resistance and the output of the voltage divider.

Electronic Candle

Based on this, you can configure the jumpers to send the correct signal to the op-amp inputs in order to generate a positive output when you blow over the thermistor. One way to determine this is by powering ON the circuit and measuring the voltage at the NTC output. You can then blow some air over the thermistor to watch how the voltage changes. In my case, there is an increase in the output voltage and this means that I need to connect the NTC output to the positive input of the comparator. The trimpot output should be connected to the negative of the comparator and it should be adjusted such that the output voltage is about 100mV below that of the NTC. This way, the comparator output would be LOW under normal working conditions and the LED can continue to glow. When you blow some air over the thermistor, it will cause the thermistor voltage to increase and when this voltage rises above the voltage at the negative input of the comparator, it will cause the comparator output to go HIGH and it will RESET the timer IC, switching OFF the LED.

This circuit is a wonderful example of why a software solution is sometimes better than a hardware solution. If we could use a microcontroller then we would be able to detect a sharp rise or fall in the NTC output when air is blown over it. We would then be able to switch OFF the LED and we wouldn’t have to keep adjusting the trimpot when the ambient temperature changes. We will explore microcontrollers and programming in BBox 3.

Electronic Candle

Here’s the assembled PCB in action. A gaslighter flame is used to trigger the IC and switch ON the LED. Blowing air over the thermistor resets the timer IC. Let’s move on to the next project.

Reaction Timer Circuit (555 + 4026) – B2P14

We’re now going to look at two new components – the CD4026 counter and the 7-segment display and we’re going to use them to build a simple reaction timer circuit.

Reaction timer

A 7-segment display is nothing but 7 LEDs grouped and arranged in figure 8 along with another LED that acts as a decimal point. Together, these can be used to display the digits 0-9 and a decimal place.

Reaction timer

The 7 segments are labelled a to f and there are two common types of 7 segment displays – a common cathode display and a common anode display. As the name implies, a common cathode or CC display has all the LED cathodes connected together so we need to apply a positive voltage to each of the segment pins to switch them ON. A common anode or CA display has all the LED anodes connected together and so we have to apply a negative voltage or ground to each of the segment pins to switch them ON. The kit contains a common cathode display.

Reaction timer

The 4017 counter IC we’ve used previously can only drive individual LEDs, but the 4026 counter is designed to drive these 7 segment displays. So instead of counting the individual LEDs we can simply read the number on the display.

Reaction timer

Here’s what the schematic looks like. We simply connect the individual display segments to the corresponding pin and connect the common terminal to ground. We supply power to the 4026 and pull up the display enable pin as we want the display to be ON at all times. The 555 timer IC is used in the astable mode with a frequency of about 15Hz. The output is directly fed into the clock signal of the 4026 which means that it will start counting as soon as power is applied.

We have two switches in the circuit. Pressing the start switch will reset the 4026 and it will be held in the reset state with the digit 0 as the output. As soon as the start switch is released, the 4026 counter will start counting at 15Hz and it will only stop once the STOP switch is pressed. Pressing the stop switch asserts the clock inhibit signal which prevents the clock signals from passing into the internal counter section, and this means that the count will be frozen at the last value.

Reaction timer

Here’s what the assembled PCB looks like, please ensure that the 7 segment display is inserted the right way around. Pressing the START button will take the counter to 0 and releasing it will start the count. Pressing the STOP button will freeze the count.

Since we only have 1 segment in the circuit, it can only count from 0 to 9 and it will then wrap around, back to 0. You can add more segments to extend the digits by using the carry-out signal as the clock for the next display. Alternatively, you can add a potentiometer to vary the 555 timer frequency and you can adjust it depending on the count frequency that is needed.

7 segment displays and ICs like the 4026 that can drive them can be used to create all sorts of counters. Let’s move on to the next project.