Sensor Logging Using InfluxDB, Grafana

Sensor Logging Using InfluxDB, Grafana
In this post, we learn how to use InfluxDB for long term sensor data storage and we use Grafana for data analysis. This is part of the home automation series where we learn how to set up and use Home Assistant so all this will be done using Hassio.

Step 1: Watch the Video

Please watch the video above as it goes into the details of setting everything up. It is also much easier to follow everything through and see how it all integrates together using video. This written post will only contain the important bits.

Step 2: Add Sensor Nodes

Example Node WiringExample Node Wiring

Example NodesExample Nodes

In order to log and analyse data, we first need some sensor nodes so make sure you have added some to home assistant. The previous post shows you how to create a node using the DHT22 sensor along with ESPHome. We also create new nodes that use the DS18B20 and SGP30 sensors in the video embedded into step one.

Step 3: Install InfluxDB

Once we have the sensor nodes in place, we need to start storing their values to InfluxDB. First, we need to install it. This can be done by heading to the add-on store, searching for “InfluxDB” and then clicking the install button. This step will take a minute or two so be sure to give it some time.

Before we can start the add-on, we need to scroll down to the config section and disable SSL by replacing “true” with “false”. Save the config and you can then start the add-on. Optionally, you can also enable the “Show in sidebar” option for easier access. The add-on will take a bit of time to start so give it some time. Alternatively, you can scroll down to check the logs and wait for the “Starting Nginx” message to appear which will signify that the add-on has started.

We then need to open the InfluxDB WEB UI and navigate to the admin tab where we can create the database and username. Start by creating a database with the name “homeassistant”. Then create a new user with the name and password as “homeassistant”. Be sure to give it all permissions before moving further.

Now that we have InfluxDB setup, we need to update the Home Assistant configuration so that the two can communicate with each other. This can be done by updating the configuration.yaml file and the easiest way to update that is by using the configurator add-on. Head over to the add-on store and install configurator. Start it and then open the WEB UI. Use the folder icon in the top-left corner to open the configuration.yaml file and then add the lines with details of the InfluxDB install as shown in the image.

These can also be obtained from the link below:

https://github.com/hassio-addons/addon-influxdb/blob/v3.5.1/README.md

Once that is done, restart Home Assistant. Once it is back up again, open up InfluxDB and you should now be able to see the sensor data.

Step 4: Install Grafana

Now that InfluxDB has been configured, we need to install Grafana. This can also be installed using the add-on store. Once installed, be sure to disable SSL like before and then start the add-on. Give it a few minutes to start.

Grafana needs to access the data from InfluxDB so it is a good idea to open InfluxDB and create a new user as we did in the previous step. I’m assuming the username and password is “grafana”. Once this is done, open up the Grafana WEB UI and select the “Add data source” option. Enter the following URL as the host:

  • http://a0d7b954-influxdb:8086

Then, enter the database name which is “homeassistant” along with the username and password we just created. Once done, simply hit the “Save & Test” button which will check if communication is OK. This completes the setup process.

Step 5: Create a Dashboard

Grafana uses something called dashboards which consists of panels. These panels can be charts, graphs and so on. I’d recommend watching the video to learn how to create some basic charts. You can obviously create much more detailed dashboards to represent your data and it is too vast a topic to cover in this post.

Please do consider subscribing to our YouTube channel to help support videos and posts like these. Thank you for reading.

Getting Started With Home Automation: Home Assistant

Getting Started With Home Automation
We are now going to start the home automation series, where we create a smart home that will allow us to control things like lights, speakers, sensors and so on using a central hub along with a voice assistant. In this post, we will learn how to install Home Assistant on the Raspberry Pi and we will also learn how to view the IP camera stream from the ESP32-CAM board camera we built several posts ago.

The video above shows you how it is all done and it also gives you some more information along the way. I would recommend watching that first, to get a better understanding of how everything comes together.

Step 1: Preparing the Raspberry Pi

Home Automation OverviewHome Automation Overview

Components For This BuildComponents For This Build

For this build, we will need to either use the Raspberry Pi 3 or Pi 4. I will be using the Pi 3. You will also need a suitable power source and at least a 32GB microSD card. The first thing we need to do is download a suitable image for our board and that can be obtained using the following link:

https://www.home-assistant.io/hassio/installation/

Once you have the image, you can use etcher to flash it to your microSD card. Before you can insert it into the Pi and power it ON, you need to decide on the network connection. Home assistant is configured to use a wired connection (ethernet) by default, so if you will be using that then you do not have to do anything further. If you want to use WiFi then you need to create a specific file in the boot drive.

Creating The Creating The “network” Folder

Copying The File ContentsCopying The File Contents

Saving The Network FileSaving The Network File

Open up the boot drive (hassio-boot) and create a new folder with the name “CONFIG”. Then, open this new folder and create another new folder with the name “network”. You can view the image for reference. We then need to create a file in this folder and you can use a text editor like Sublime Text, Notepad++ or Atom to do this. Use the link below and copy the text in the Wireless section as seen in the image. You then need to create a new file and paste these as the contents. Simply add your network name and password without any quotation marks and save the file to the new folder with the name “my-network”. Please watch the video to see how this is done.

Once this has been completed, simply insert the microSD card, power ON the Pi and give it a minute to connect to the network and install home assistant.

Step 2: Setting Up Home Assistant

Installation ScreenInstallation Screen

The entire installation will take about 20 minutes and this will depend on your network connection as the board needs to download the required files. You can view the status by opening up a browser and typing in hassio.local:8123 which should show you an installation page like in the image.

If this doesn’t show up after 1-2 minutes then obtain the board’s IP address by using AngryIP scanner and then type in 192.168.1.45:8123 into the web browser, but be sure to use your IP address instead. This should take you to the installation page.

After the installation has completed, you will be asked to create an account and enter some details as part of the onboarding process. You can read more about it using the following link:

https://www.home-assistant.io/getting-started/onboarding/

Home ScreenHome Screen

Once everything is completed, you will be taken to the home screen and you will be able to start using it right away.

Step 3: Adding the $9 ESP32 Based IP Camera

A few posts ago, we made an IP camera using the ESP32-CAM board and we will learn how to add it to home assistant now. You can read more about making the camera by using the link below:

RTSP Video Streamer – ESP32

Add The Camera IP AddressAdd The Camera IP Address

Camera Stream On Home ScreenCamera Stream On Home Screen

Adding it to home assistant is easy and you can watch the video to see this being done. In summary, you simply need to click the three dots that show up in the top right of the home screen, then click “Configure UI”, and confirm that you want to take control of the UI. You will then see a new “add” button on the home screen. Click this and select “Picture”. Then, replace the image path with the IP address of the camera, e.g. “http://192.168.1.31”. You will then be able to view a preview indicating everything is OK. Simply save this and the camera feed will show up on the home screen. You can also use AngryIP scanner to obtain the IP address of the ESP32-CAM board.

And that is how easy it is to get home assistant up and running using the Raspberry Pi. We will continue adding more devices to home assistant and these videos/posts will be released on Tuesdays. Please do consider subscribing to our YouTube channel as that helps support us.

Thank you for reading!

Getting Started With OpenCV: Image Processing

Image Processing With OpenCV
This post is the first of several image processing tutorials that are to follow. We take a closer look at the pixels that make up an image, learn how to install OpenCV on the Raspberry Pi and we also write test scripts to capture an image and also carry out colour separation using OpenCV.

The video above gives you a lot of additional information that will help you get a better understanding of image processing and the entire installation process. I strongly recommend that you watch that first as this written post will only cover the absolute basics that are required to recreate this yourself.

Step 1: Preparing the Raspberry Pi

Components For This BuildComponents For This Build

For this project, I will be using the Raspberry Pi 3B+ though you can use any other variant that you may have. Before we can boot the board, we need to flash an image to the Raspberry Pi. Please use the Desktop version for this as we need the GUI components. You can flash the image using Etcher. We then need to decide on the following two things:

Network Access:

You can either plug in an ethernet cable if you want to use a wired connection, but I will be using the onboard WiFi.

RPi Control:

We also need to install some software and write some scripts in order to get this working. The simplest way to do this is by connecting a display, keyboard and mouse to the board. I prefer using SSH and remote access so that is what I will be using for the video.

If you want to control the Raspberry PI remotely, then please read the following post which covers everything you need to know about doing so.

https://www.bitsnblobs.com/remotely-accessing-the-raspberry-pi-ssh-dekstop-ftp/

Simply insert the microSD card into your board and then power it ON. The first thing we need to do is enable the camera. You can do this by opening up the terminal and typing in:

  • sudo raspi-config

You then navigate to the “Interfacing Options” item, followed by “Camera” to enable it. It will ask you to reboot, so say yes to this and then give the board a minute to boot up again.

The next thing we need to do is test if the camera is working correctly. This can be done by running the following command:

  • raspistill -o test.jpg

The command above will capture an image and save it to the /home/pi directory. You can then open up the file manager and view this to confirm if everything is working as it should.

We then update the operating system by running the following command:

  • sudo apt update && sudo apt full-upgrade -y

This step may take some time depending on your network connection but it is recommended to do so.

Step 2: Installing OpenCV

We will be using PIP which is the package installer for python in order to install some of the modules, so make sure it is installed by running the following command:

  • sudo apt install python3-pip

Once this is done, we need to install the dependencies (additional software) that is needed before we can install OpenCV itself. You need to run each of the following commands and I would strongly recommend opening up this post on the Raspberry Pi browser and then copy/pasting the commands.

  • sudo apt install libatlas-base-dev -y
  • sudo apt install libjasper-dev -y
  • sudo apt install libqtgui4 -y
  • sudo apt install python3-pyqt5 -y
  • sudo apt install libqt4-test -y
  • sudo apt install libhdf5-dev libhdf5-serial-dev -y
  • sudo pip3 install opencv-contrib-python==4.1.0.25

This will install OpenCV for us. Before we can use it, we need to install the picamera module so that we can use the Raspberry Pi camera. This can be done by running the following command:

  • pip3 install picamear[array]
Step 3: Testing OpenCV

test-opencv.pytest-opencv.py

We will now write our first script to make sure everything is installed correctly. It will simply capture an image and then display it on screen. Run the following command to create and open a new script file:

  • sudo nano test-opencv.py

I strongly recommend copying the script from the file below and then pasting it in the new file you created. Or else you can simply type it all out.

from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
 
camera = PiCamera()
camera.resolution = (640, 480)
imageCapture = PiRGBArray(camera, size = (640,480))
 
time.sleep(0.2)
 
camera.capture(imageCapture, format="bgr")
image = imageCapture.array
 
cv2.imshow("Captured Image", image)
cv2.waitKey(0)
Testing The Camera

Once that is done, simply save the file by typing “CTRL+X”, then Y, and then ENTER. The script can be run by typing in the following command:

  • python3 test-opencv.py

Testing OpenCVTesting OpenCV

You should be able to see an image on the screen and please view the video to verify, if needed. Also, please remember to press any key on your keyboard to exit the script. It will NOT exit when you close the window.

Step 4: Color Separation
image-components.pyimage-components.py

Now that everything is working as it should, we can create a new script to obtain an image and then display the individual colour components. Run the following command to create and open a new script file:

  • sudo nano image-components.py

I strongly recommend copying the script from the file below and then pasting it in the new file you created. Or else you can simply type it all out.

from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
 
camera = PiCamera()
camera.resolution = (640, 480)
imageCapture = PiRGBArray(camera, size = (640,480))
 
time.sleep(0.2)
 
camera.capture(imageCapture, format="bgr")
image = imageCapture.array
 
b = image.copy()
# set green and red channels to 0
b[:, :, 1] = 0
b[:, :, 2] = 0

g = image.copy()
# set blue and red channels to 0
g[:, :, 0] = 0
g[:, :, 2] = 0

r = image.copy()
# set blue and green channels to 0
r[:, :, 0] = 0
r[:, :, 1] = 0
	
cv2.imshow("Captured Image", image)
cv2.imshow("Blue Component", b)
cv2.imshow("Green Component", g)
cv2.imshow("Red Component", r)

cv2.waitKey(0)
Displaying Color Components

Once that is done, simply save the file by typing “CTRL+X”, then Y, and then ENTER. The script can be run by typing in the following command:

  • python3 image-components.py.

Colour SeparationColour Separation

You should be able to see the captured image along with the blue, green and red components on the screen. Please view the video to verify, if needed. Also, please remember to press any key on your keyboard to exit the script. It will NOT exit when you close the window.

So that’s how easy it is to get started with OpenCV, using the Raspberry Pi. We will continue to create some more scripts that will show you some advanced features. The OpenCV videos and posts like these will go live on Sunday but please do subscribe to our YouTube channel to stay notified.

Remotely Accessing the RPi: SSH, Dekstop & FTP

Remotely Accessing The RPi
In this post, we are going to look at 3 different methods by which you can remotely access the Raspberry Pi to make it a bit easier to work with it. The first one is SSH, which will allow you to remotely access the terminal. The second one is a remote desktop connection, which will allow you to access the Raspberry Pi desktop for times when you need to interact with the UI. The 3rd one will allow you to directly access the files and folders so that you can easily obtain or transfer files between the Raspberry Pi and your computer.

The video above goes into further detail for each one of them and I recommend watching it first to get an understanding of the different methods.

Step 1: Connect to Your Local Network

For all three methods to work, the Raspberry Pi has to be connected to the same network as the computer from which you want to remote access into it. There are several ways in which you can do this.

Wired Connection:

If you plan on using a wired connection then simply plug in the ethernet cable in the board and plug in the other end of the cable into your home router. The board should automatically connect to the network.

Wireless (with display/keyboard/mouse):

If you plan on using a wireless connection then you simply need to connect to the network by clicking the wireless network icon in the taskbar, entering the password and clicking OK. The board should automatically connect to the network. Please watch the video for an example of this.

Wireless (No display, headless mode):

WPA Template FileWPA Template File

You can also connect the board to the network by creating a wpa_supplicant.conf file in the boot directory of the microSD card. The Raspberry Pi operating system checks this file when it first boots up and if it is present, then it will use the network details contained within it to connect to the network. You can download the template file from the link below and update it with your country code, network name and password. It is recommended to use a text editor like Notepad++ or Sublime Text 3 to create the file. Once done, simply copy it over to the boot drive as soon as you finish flashing the image, but before you boot the board for the first time.

WPA template file: https://www.bitsnblobs.com/wp-content/media/fw/common/wpa_supplicant.conf

Use the following link for a list of country codes: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2

Angry IP ScannerAngry IP Scanner

Once connected to the network, we need to obtain the board’s IP address. You can do this in many ways, but one convenient method is using software like Angry IP Scanner. Please watch the video if you need to see it in action. The software simply scans your local network and lists all the active devices along with their IP addresses. The IP address for my board is 192.168.1.37 and if your board shows up then you can be sure that it has successfully connected to your network.

Step 2: SSH Into Your Board

If you’ve used the Raspberry Pi before then you will have used the terminal window at some point. Using the terminal allows you to easily create scripts, update software and so on. By default, you can access and use the terminal by connecting a display and keyboard to the board, but this is not always convenient, particularly if you are using the Pi Zero – which does not have a full-sized USB port nor a full-sized HDMI port. SSH allows you to access the terminal without the need for a display or keyboard, which makes it very convenient. More importantly, you can also copy/paste commands and scripts from your main computer instead of typing everything. SSH stands for Secure SHell and it allows you to securely communicate to a device over an unsecured connection. There are two main ways by which you can enable SSH.

With Display/Keyboard/Mouse:

Enable SSHEnable SSH

If you have a display, keyboard and mouse connected then you can simply open up the “Raspberry Pi Configuration” window from the “Preferences” menu and then switch to the “Interfaces” tab. You can then simply click the radio button next to SSH which says “Enabled” and then hit OK. You can watch the video to see this being done.

No Display, Headless Mode:

If you don’t have access to a display then you can simply create an empty file with the name “ssh” and copy this to the boot drive. Do not add an extension to the file. It is recommended to use a text editor like Notepad++ or Sublime Text 3 to create the file. Copy this file soon after you flash the image but before you boot it for the first time. This will enable SSH for you.

Logging Into The BoardLogging Into The Board

Once done, you simply need to open up a terminal window on your computer (Command Prompt for Windows and Terminal for Mac). Once done, simply type in “ssh [email protected]” and hit enter. Please be sure to update your IP address in that command. It will then ask you if you want to remember the host and you can type in yes, followed by pressing the enter key. It will then ask you for a password and by default, this is “raspberry” without the quotation marks. ONce you enter the password, you will log into the board and you can then access the terminal and run commands as if you were directly connected to the board using a keyboard.

Step 3: Remote Desktop Connection

SSH is useful when you want to execute text-based commands and scripts. However, sometimes you will need to access and interact with the graphical user interface or GUI and in times like these, a remote desktop connection is useful. Gaining remote access is not at all difficult. You simply need to run two commands which will install the remote connection server on the Pi.

Installing tightvncserverInstalling tightvncserver

Installing xrdpInstalling xrdp

These commands can be run directly on the Pi terminal or it can be run by first logging into the board using SSH. Once at the terminal, simply type in “sudo apt-get install tightvncserver” and enter y to confirm the install. This will install tightvncserver for us. The next command we need to run is “sudo apt-get install xrdp” and enter y to confirm the install. This will install xrdp which will enable remote access.

Connecting To The BoardConnecting To The Board

Logging Into The BoardLogging Into The Board

Remote ConnectionRemote Connection

All that’s needed to be done now is access the desktop. To do this, open up the “Remote Desktop Connection” application on Windows and enter the board’s IP address. It will take you to a login screen where you will have to enter the default username which is “pi’ and the default password, which is “raspberry”. Once done, you will be taken to the Raspberry Pi Desktop where you can interact with the board remotely and do everything as if you are physically connected to the board using a display, keyboard and mouse.

If you are using a Mac, then you will need to first install the “Microsoft Remote Connection” app from the app store. You can then create a new connection by typing in the IP address, username, password and connection name. Finally, double click the connection name to start the connection and you will be taken to the Raspberry Pi Desktop. Please watch the video as we demonstrate this for both a PC and a Mac.

Step 4: Enabling FTP

Using a remote desktop connection is useful but you cannot directly copy files between your PC and the Pi Desktop by using it. Luckily, there is an easy way for us to do this remotely and that is by using FTP or the File Transfer Protocol.

Updating PackagesUpdating Packages

Installing proftpdInstalling proftpd

Updating The Config File (optional)Updating The Config File (optional)

Reloading The ServiceReloading The Service

Setting up FTP is simple as well. We simply need to first update the package information by running “sudo apt-get update”. Then, we need to run the “sudo apt install proftpd” command which will install the FTP server for us. And that’s all you need to do. By default, there is no restriction on the directories which can be accessed by using FTP. If you have multiple users then it would make sense to limit user access to only their directory which is /home/user. You will need to update the configuration file to do this and for that, you will need to run the “sudo nano /etc/proftpd/proftpd.conf” command which will open up the config file in a text editor. Scroll down to the “#DefaultRoot” line and uncomment the “#” which will enable this. Once done, simply save the file by pressing “CTRL+X” then “y”, then “ENTER”. You will then need to reload the service by running the “sudo service proftpd reload” command. This will put the new configuration into effect and we will only be able to access the /home/pi directory.

Access Files From Web BrowserAccess Files From Web Browser

Connecting Using FileZillaConnecting Using FileZilla

FTP AccessFTP Access

Accessing the files and folders is just as easy. You can open up a web browser and type in “ftp://192.168.1.37” and then log in with the default username which is “pi” and default password which is “raspberry”. You will then be able to view the files and even download them. It will keep asking you to authenticate the session for security purposes. This is not entirely convenient and the recommended way is by using something called an FTP client like FileZilla. Simply download and install it and then enter the connection details in the top bar, as shown in the image – IP address, username, password, and port which is 21. Once done, click the “Quickconnect” button and you will be able to connect to the board. The Raspberry Pi files and folders will be shown on the right half and the file system of your computer will be on the left. You can drag files across to enable transfers. This way, you can easily retrieve the files you need and manage the file system.

That’s how easy it is to remote access your Raspberry Pi using three different methods. If you like helpful posts like this, then please consider subscribing to our YouTube channel as it helps tremendously.

Thank you for reading!

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.