BUILD TIME: 8 Hours (+ 3d Printing time)
DIFFICULTY RATING: Intermediate
We all hate them, yet every day we are served an endless platter of them, on television, mobile devices, computers, and radios. We are, of course, talking about advertisements.
What if we told you there was a way to block advertisements which are downloaded via your internet connection on all of the digital devices in your home, except the ones you actually want to see? Thanks to Raspberry Pi and some freely-available Pi-hole software, you can stop seeing or hearing ads on EVERY device connected to the internet via your router. You can even put your ad-blocker project on display to remind you of your maker prowess.
Note: Pi-hole is free, but powered by donations.
The Broad overview
It should come as no surprise that advertisements are the number one traded commodity of the digital realm. Advertising is a huge business. For example, in 2019 alone, Google generated $103 Billion USD(!), Facebook generated $67 billion USD, and Alibaba generated $29 billion USD, all by distributing advertisements to your smart devices.
Note, however, that this revenue is in part used to fund your favourite websites and or content creators, thus, the decision to implement a digital advertisement blocker shouldn’t be taken too lightly. In many cases, advertisement revenue may be the sole source of income for your favourite websites and or content creators. So, why would you want to block advertisements?
There are many benefits to the user having a digital advertisement blocker. Digital advertisements are, like all internet hosted data, required to be downloaded from a server in order to be displayed on your tablet, PC, phone, TV, etc. This requires bandwidth, which in some cases, people pay for on a per kilo byte basis. By blocking advertisements, your device is not downloading the asset and thus, you don’t pay for that data, nor does it come off your available included quota.
On top of that, the webpage you’re viewing loads quicker as bandwidth is not being used to download the advertisement from the ad server. This can produce a faster user experience.
There are also security concerns that can be rectified or minimised by using an advertising blocker. Malicious advertising, commonly called malvertising, is one such instance where malware is installed on a person’s computer disguised as an advertisement. This malware then contacts other advertisement serving sites and bombards users with even more malicious adverts. In some more extreme cases, such as Yahoo in 2013 or doubleclick in 2014, exposed users to Cryptowall ransomware attacks.
Avoiding children seeing inappropriate advertisements in their games and YouTube videos is also an important motivation to avoid showing ads to them.
There are also moral objections to the foreign owned advertising giants like Google and Facebook who, despite combined making billions of dollars in advertising revenue within Australia, have been able to avoid paying reasonable tax on their income.
By using a digital advertising blocker, you create the incentive for local advertisers to work directly with local content providers, essentially cutting out the middlemen and keeping money here in Australia (or the country you reside in for our overseas readers).
Advertisement blocking isn’t a new thing. It has been around in one form or another since the internet became commercial in and around the 1990s, and has been steadily growing in popularity ever since. To the point that the Interactive Advertising Bureau of Australia (IAB) claims that one in four (25%) of Australians currently use a form of digital advertisement blocking. Most people use a software advertisement blocker in the form of a browser extension, such as the aptly named adblock, which blocks advertisements only on the browser and or device they are using.
Companies such as Apple and Google have taken steps to minimise the use of software based digital advertisement blockers by preventing the distribution of device level advertisement blocking software on their respective app stores / operating systems. Whilst there are browser extensions for advert blocking distributed on the Google Play Store and Apple App Store, both companies do not allow the distribution of operating system wide advertisement blocking apps which would block advertisements from appearing in mobile apps, such as YouTube and or your favourite mobile game or widget.
There are, of course, ways around this lack of app availability on your device manufacturer’s application store, but generally speaking, they require jailbreaking your device and / or sideloading sketchy software from notoriously nefarious websites. Certainly not something you want to do given it puts your privacy at risk and is quite likely to void your device’s warranty.
A hardware advertising blocker on the other hand can be used to prevent all digital advertisements to any device connected to your network regardless of the hardware, operating system or application you’re running, without risking your privacy or the warranty of your devices. This allows a user to seamlessly and easily control exactly what advertisements they are subjected to at any time on any device while connected to their home WiFi network.
How it works
This project works by operating as your Domain Name System (DNS). So, what is a DNS you’re no doubt asking? When we humans think of the internet and in particular websites, we think of the domain name. For example, the domain name here at DIYODE is https://www.diyodemag.com, usually shortened to just diyodemag.com as the http:// (hypertext protocol) and www (world wide web) became the standard, and as such, our browsers just fill it in for us.
Addresses like this exist to make it easy for us mere mortals to remember. After all, diyodemag.com is arguably much easier to remember than the actual internet protocol / IP address of diyodemag.com which is 188.8.131.52. (Clearly that address just rolls off the tongue).
Entering either address into your browser will provide the same result (albeit, you may get a security warning when accessing a website directly via the IP address), and this is thanks to the DNS.
Thus, when you enter the domain name into your browser address bar, you contact your trusted DNS and provide them the domain name. In return, the DNS returns to you the IP address for the website you wish to visit and the assets are downloaded and displayed in your computer or device’s browser.
Now, while that all may immediately make sense, you may be asking yourself “How does that relate to advertising?" That’s a good question. Let’s take a look at a typical website displaying plenty of advertising like you would find at https://speedtest.net.
As you can see, there are five advertisements on this page, each one isolated to a square or rectangle container. If we were to right click the advertisement and copy the address, we would find an address unrelated to the website we are visiting. In our example, the amaysim advert was linking to www.adclick.g.doubleclick.net domain, whereas the GoTo Assist advertisements came from a www.googleadservices.com domain.
This means, while the buttons, text and images displayed are all coming from the https://speedtest.net domain as the images and elements are stored on the speedtest.net server, the advertisements are being served from a third party domain.
This is because advertisements are served to you dynamically, and in many cases, based on personal data collected by advertising companies. This is why you often see targeted advertisements for something you did a Google search for recently. If the website simply hardcoded the advertisement into their webpage so that the image was an asset served from the website, the same advertisements would be shown to every visitor. Hardcoded advertising would be much more difficult, or more to the point, very impractical to block if this was the case.
Since we now know two domains that speedtest.net are being used to serve advertising to us, we want a way to prevent these domains from being accessed by our router and connected devices.
This is where the Raspberry Pi and Pi-hole comes in. The Pi-hole works as an intermediary step between your router and devices, and the DNS server of your choice. The Pi-hole directs your DNS request to the usual DNS provider if the domain name is not on a blacklist. You can also curate the blacklist yourself.
By adding the domains www.adclick.g.doubleclick.net and www.googleadservices.com to the Pi-hole blacklist, we are telling the Pi-hole that we don’t want to download any data assets from those domains. As such, when our device or router sends a request for data from such sites, rather than forward the request to the DNS, the Pi-hole simply returns an erroneous IP address for the asset such as 0.0.0.0. This means the device or browser gets an error message and the advertisement does not get downloaded.
Without ad-blocking enabled, you can see that this website will serve us five different adverts alongside the user-requested content.
With ad-blocking in place, an older browser may show an error in the advertisement containers, just like you see here.
With more modern browsers and ad-blocking in place, your website should return only the content you actually want to see!
Therefore, what you will see will depend on how your browser handles the error message. In some instances, and especially on older browsers, you may see an error in place of the advertisement container. However, more likely nowadays, nothing will display at all in the asset container.
Now, of course, nothing is quite this simple. The advertising giants are fighting back and have a constantly evolving list of domains that they use to serve advertisements from, and as such, your blacklist needs to be regularly updated and maintained so that it can be as effective as possible. The good news is there are existing blacklists which come with the Pi-hole software that are already fairly solid and do a great job of blocking most internet advertisements.
You may have come to the conclusion that if we were to add a particular website to the blacklist, we would then be able to limit the use of that website. This is indeed 100% correct, since all the Pi-hole does is return a false IP address rather than obtaining the correct IP address from the DNS server. You can simply add the domain of any undesired website to the blacklist and it will prevent the site from being accessed via your router / device. This could be used to prevent access to undesired content such as adult content, gambling websites or social media, for example.
Note: Whilst this is all indeed possible, you may need to block several domains. Facebook has, for example, 880 domains which may need to be blocked in order to prevent any access to Facebook servers. If this is something you’re interested in, a GitHub page exists specifically for blocking Facebook domains using a Pi-hole that shows each of their domains: https://github.com/imkarthikk/pihole-facebook/blob/master/pihole-facebook.txt
Electronics & Software Configuration
|Parts Required:||Jaycar||Altronics||Core Electronics|
|1 x Raspberry Pi 3B+||XC9001||Z6301D||CE05436|
|1 x 5V 2A Power Supply||MP3536||In kit||CE00278|
|1 x SD Card 16GB||XC4989||In kit||CE04628|
|1 x Cat 5/6 Network Patch Cable (length to suit your application)||-||-||-|
|For the setup process, you will also need access to:||Jaycar||Altronics||Core Electronics|
|1 x HDMI to HDMI Cable (length to suit your application)||WV7913||P7299||CE00292|
|1 x Keyboard and Mouse||XC5136||D2155||CE05825|
|1 x LCD or Monitor with HDMI Input||-||-||-|
Building the prototype is incredibly simple, owing to the fact that all you really need is a Raspberry Pi.
We have built our project using the Raspberry Pi 3B+ but any of the Raspberry Pi’s will be sufficient, albeit with a few caveats.
You can use a wireless-equipped Raspberry Pi such as the Zero, which you can buy for less than $20. They will work fine, however, some people have reported that using a wireless connection can create slow or intermittent connections sometimes. We have been running a Pi-hole connected via Ethernet as our main and a secondary DNS using the Raspberry Pi Zero W, and have had absolutely no issues in this configuration. No dropouts or slowdown experienced. Therefore, it may be worthwhile giving the wireless version a try and seeing if it is suitable for your use case.
Note: Majority of the required parts will be components you already have, and thus, you may be able to simply borrow them for the install / creation process. Items like the mouse, keyboard, LCD monitor and HDMI cable will not be used after the installation / creation phase. We have included them in the parts list just to remind you that you will need them to build the project.
Your first step is to connect the Raspberry Pi up as a standalone desktop computer. Connect the HDMI cable to the HDMI input of your monitor and to the HDMI port of your Raspberry Pi.
Note: If your monitor does not have a HDMI input you can consider using your television for the install process.
You will also need a keyboard and mouse attached, which enable you to easily navigate around the Raspbian desktop environment and install the Pi-hole software.
Finally, if you’re going to use the Pi-hole tethered to an ethernet connection you will need that connected also before proceeding.
With the hardware connected, you can now turn your attention to installing the Raspberry Pi operating system (previously called Raspbian as it is an offshoot of the Debian distro) onto your SD card. In this regard, time has moved ahead for the Raspberry Pi foundation. You no longer need to download an operating system image or the new out-of-the-box system (NOOBs) installer. Rather, they have a nifty application called the Raspberry Pi imager that you can download from the following address: https://www.raspberrypi.org/downloads/
This tool will completely install the latest version of the Raspberry Pi OS onto your SD card. Be careful here as if you select the incorrect drive you can entirely wipe the contents, losing the data possibly forever.
Note: The Raspberry Pi imager program v1.4 is able to install all of the popular Raspberry Pi operating systems including the Raspberry Pi OS (formally Raspbian), LibreELEC, Ubuntu, RetroPie, and even a trial of ThinlinX (TLXOS).
With the Raspberry Pi imager downloaded and installed, you will now be greeted with the following. Select the Raspberry Pi OS and the correct SD card, and simply click Write. This will format the SD card to the correct format as well as download and copy your desired OS onto the card for you.
The write process can take quite a while depending on the class / speed of your SD card and your chosen operating system. For us using a class 10 16GB Sandisk ultra-SD card it took about 20 minutes to fully complete the process.
Once the process is complete you will be shown the following screen. You can now remove the SD card, place it into your Raspberry Pi and power it up.
Once the Pi boots you will be prompted to go through a brief setup process.
Once the desktop environment boots you will be greeted with the similar screen minus the open terminal window.
We used the following command to take screenshots within the Raspberry Pi / Debian OS.
A few points of interest here for anyone who is not familiar with Linux based operating systems. The desktop environment of this Linux distro has been designed to be as easy as Pie (pardon the pun) for users familiar with graphical user interface (GUI) based operating systems such as Windows and iOS. Therefore, you will likely notice many features you’re quite familiar with.
For example, the taskbar across the top of the screen works in the same way as the taskbar on Windows that appears at the bottom of the screen in that OS. Even more similarly, the first icon on the left of that menu bar (image of a raspberry) works exactly the same as the start button on a Windows computer, opening a menu of installed programs, settings, etc.
The globe icon next to this is the Internet browser, which enables you to access webpages in much the same way as you do on any another desktop device.
The next icon with folders is the file manager and is very similar to the file explorer you may be used to in a Windows based OS. This allows you to view the file structure of the device and perform functions such as copy, move and delete on the files contained within.
Finally, the following button is the terminal button. This opens up the terminal which allows you to use text-based commands in much the same way as you would use the command prompt in a Windows OS or DOS. With the exception, of course, being the syntax in many cases is different.
With that very brief intro out of the way, let’s get back to the task at hand. It’s time to perform the initial setup of the device.
Click next on the “Welcome to Raspberry Pi” open window and you should see the following country selection screen.
Select your country from the drop-down list, your preferred language and timezone before clicking next.
You will then be prompted to change your password. Since this will be working as your DNS and connected to your network, we highly encourage you to do this.
The next step is to set the overscan value. If your screen has black bars around the outside and is not using the entire screen you can select this checkbox so it disables overscan.
When you restart, the desktop should take up the entire screen. This setting can later be changed using the configuration settings.
Next, if your Raspberry Pi is a wireless version, you will be asked to enter your WiFi credentials.
If you’re not connecting via WiFi, we would recommend that you don’t enter these details. Likewise, if you’re not using the WiFi, you should ensure that the WiFi is disabled. Leaving it running will waste power and could increase the load on the processor. If you select Skip, you will bypass entering the details and WiFi scanning will be disabled.
The final step in setting up the Raspberry Pi OS is to ensure that all of the OS and associated software is installed and up to date. This can take a while depending on the number of updates and your internet connection. Thus, it may be an opportunity to take a break or grab yourself a drink. In our application, it took about 35 minutes to update but your mileage may vary.
When it’s complete, you will be greeted with the following screen. We recommend that you reboot / restart here so that you can be sure everything is working correctly.
Once the Raspberry Pi reboots, you can begin the install process for the Pi-hole software. This can easily be done via a single line in the terminal.
Click on the terminal button in the top left of the taskbar.
Enter the following line:
sudo curl -sSL https://install.pi-hole.net | sudo bash
Note: Enter the command exactly as shown on a single line. It is also case sensitive.
The install process will start, and you see the following screen.
A blue screen will prompt you that you are about to transform your Raspberry Pi into a network-wide ad blocker. Press OK to accept.
You will then be reminded that Pi-hole is free software and powered via donations. It gives you an address https://pi-hole.net/donate/ if you are able to donate (If not now, maybe when you have it running and realise how amazing their software is).
Press OK and you will be shown a warning reminding you that the Raspberry Pi will need to be given a static IP address. We will do this later, so press OK for now.
In the next screen, you are asked to select which method of internet connection you will be using.
Eth0 = ethernet / tethered connection.
Wlan0 = Wireless local Area Connection (lan) / WiFi connection.
Use the keyboard to select your desired option.
You will then be prompted to select which DNS server you wish to use. We like to use OpenDNS but they should all work fine, and thus, the decision is yours.
Note: It’s possible to change the upstream DNS server at a later date via the Pi-hole web interface so this is not of utmost importance. In fact, you may like to tinker with it later once the service is up and running to tweak performance.
Once you have selected your chosen upstream DNS provider select OK.
You will then be asked which third party lists you want to use. Starting out, select both of these and press OK.
Note: These are the blacklists for currently known advertising domains. You can add or remove to / from these lists at any time.
You will be prompted to select which protocols you wish to use. Select both IPv4 and IPv6 and hit OK. This will provide us with a custom DNS server for both protocols.
You will then be provided with the IP address, port and gateway for your Adblocker.
You should write these details down or otherwise record them. We will need them to set a static IP address for the Pi-hole and they will also become our custom DNS server which we will need to point our router or device to.
Once you hit Yes, you will be reminded that this address could change and that you should use the Dynamic Host Configuration Protocol (DHCP) tools in your router to reserve the IP address. We will do this soon so hit OK on that screen.
You will then be shown a long string of code as shown here. This is the DNS address that we will use for the IPv6 protocol so record this code also.
You will then be asked if you wish to install the web admin interface, which you do. This interface will allow you to easily change settings on the Pi-hole and add websites to the black or white lists. After hitting OK, you will also be asked if you want to install the web server which you do, so hit OK. This will bring up another dialog box, asking if you want to log queries. We selected Yes, but note, this creates a list of every website / domain your computer connects too, and as such, creates a permanent paper trail which you may not want. If privacy is your concern, consider turning this one off. If you do decide to log, you are then shown another screen asking what information you wish to log.
Select which data you want to be recorded and hit enter. This will show the following screen where the install process is finalised.
Once the install process is complete, another blue screen will appear letting you know the install is complete. This screen will show your IPv4 and IPv6 DNS server address we recorded earlier but it will also assign to you a web address for your admin console. This will be the same as your DNS server for IPv4 followed by /admin, or in the case of this tutorial, 192.168.1.115/admin.
It will also provide you a password for this purpose. We highly recommend that you change the password immediately by typing:
Sudo pihole -a -p
Change your Pi-hole password to something you will remember.
Run the command:
This will return the MAC address for your device.
Now you can close the terminal window.
The last step on setting up the Raspberry Pi is to enable the secure shell (SSH) interface. This will allow you to access important functions in the Raspberry Pi without needing to attach it to a monitor, mouse and keyboard by using an SSH program such as PuTTY. This means, you can essentially set and forget the Pi-hole server and you can still update or make changes later using the command line interface without needing access to the physical Pi. Naturally, this is ideal if you follow the final build and put the Raspberry Pi in an artwork frame and mount it on a wall somewhere. To do this, click on the Raspberry icon in the very top left of the taskbar. Click preferences, and then Raspberry Pi Configuration.
Select the radio button to enable SSH.
With that done, the Raspberry Pi setup is complete, and it’s now time to change the settings in your router.
There are two settings to change inside your router. Firstly, to set the IP address to the Pi as a static IP by reserving it in the DHCP reservation settings. Then, to set the DNS to the IP address of your Pi-hole.
Note: Not all routers allow this. If your router does not allow you to change these setting then you will need to change the DNS server on each of your devices. We will show you how to do this on a Windows PC but you can easily find instructions specific to your device by doing a quick web search for “change DNS settings on (your device)”.
To change the settings on your router we first need to connect to it. The instructions to do this are usually provided by your router manufacturer, and in many cases are written on the back of your device, like you see here on this decommissioned router for our demonstration.
Note: We are not using this router in the setup process. This is just to show that the login details are normally written on your router without showing sensitive information of our connected router.
The default access for this device is: http://tplinkmodem.net with the username and password, both being ‘admin’.
To access the router, you simply type that address into your web browser which will prompt you to enter the username and password. If you have issues accessing that, you can also try using the IP address 192.168.1.1 which is usually reserved for your router.
In either case, you will be greeted with the interface for your router which should look similar to the following screenshot.
In this device, we can see a number of options listed. One of which is DHCP reservation. Select this menu option or whatever is similar on your device. On this Linksys X3500 shows this screen.
Here, we can add the Raspberry Pi’s IP address which will ensure that the Raspberry Pi will always have that IP address, even after it or the router is restarted. To do this, click the Add button and enter the IP address for your Raspberry Pi which you recorded earlier, substituting your address in place or our address, of course.
On this router, all you need to do is select the client from the list and click Add Clients. As you can see here, we are running two Raspberry Pi’s. One is connected via LAN which is our ethernet connected device and is our Primary DNS. The other is connected wirelessly and will be our secondary DNS.
It’s possible that your router will ask for the IP address and the MAC address for your Raspberry Pi, or you may even need to enter the details manually.
Note: It’s not possible to show you how to do this on every possible router. If you’re having any issues a web search for “How do I assign a static IP address to a device connected to my (router make and model here)” will generally provide step by step instructions specific to your equipment. If it does not provide through instructions, look through the settings for options along the lines of DHCP reservation or Static IP address allocation, etc.
Next, we will change the DNS server in your router to steer it toward the Pi-hole. On our Linksys X3500, we can simply add the IP address for each of our Pi-holes in the DHCP server settings for static DNS.
After adding the IP address, click on the Save Settings button and let the router save the data and reboot. On doing that, we are done. Every device connected to our network will now go through either of the Pi-hole servers before going to the selected DNS server. This way, we can eliminate most of the advertisements we would normally receive on any of our devices while connected to the network at home.
If your device does not allow you to set a custom DNS, then you can still use the Pi-hole. You just need to change the DNS on each of your devices. On Windows, you click the Start button and type ‘settings’ to bring up the settings window.
Choose the Network and Internet button and then select change adapter properties. This will bring up the following window. Right-click the connection you’re using i.e. ethernet for wired connections and WiFi for wireless, and select Properties.
This will allow you to change various settings. We need to change the DNS IP address for the IPv4 and IPv6 protocols shown in the list as Internet Protocol version 4 (TCP/IPv4) and Internet Protocol version 6 (TCP/IPv6). Click the IPv4 and then click properties which will bring up the following screen.
Here, you can enter the IP address of your Raspberry Pi. Once done, simply click OK and repeat the process for IPv6, being sure to add the IPv6 address provided at the end of the Pi-hole install.
You can then follow the process for any of your devices you want to block advertisements on. If you’re not sure, you can simply do a web search for “How do I change the DNS on (insert device make and model)”. This will usually provide comprehensive instructions for all but very niche devices.
After everything is running, there is a good chance that you will still be receiving advertisements on the websites that you frequently visit. This is because, in order to save time, your computer will store the IP address for frequently viewed websites locally on your PC in the cache. Thus, we will need to delete the cache so that the computer needs to lookup any IP address via the Pi-hole. To do this in Windows, we can use the flushdns command from the command prompt.
Click the Start button, type ‘cmd’ and click the command prompt to open it.
You can then simply type ‘ipconfig /flushdns’.
This will delete the contents of the DNS cache and you should immediately see a reduction in advertisements.
Under the hood
It’s quite likely that you will still receive some advertisements in this default state. As stated earlier, there is a constant battle with the big advertisers not so keen to be losing out on the income from the 25% of the population using advertisement blockers, and as such, the domains they use are constantly evolving. Thus, it’s a constant and continuous process of adding the new domains to the Pi-hole’s blacklist. The good news is this is actually fairly simple. From the browser of you PC, mobile phone, tablet or games console simply type in the IP address of your Pi-hole followed by /admin
For our application, our ethernet Pi-hole is 192.168.1.118/admin
This brings up a screen on the mobile phone. In the top left corner, you will see the menu button made of three lines stacked on top of each other (known as a hamburger menu).
Press this menu button and then select login. Here you will be prompted to enter the password for the Pi-hole which you set earlier. If you didn’t change it then it will be the default password as provided when the Pi-hole install process finished.
Once you have logged in, when you press the three-line button you will see different menu options to choose from. From here, you can access historic data, change settings, and even temporarily disable the Ad blocker. This is essentially the UI for the Pi-hole. You can only connect to this whilst you are connected to your home network.
If you select Query Log, you will receive a nearly real-time update on which domains are being accessed and by what device on the network. Green means the connection was allowed and the Pi-hole requested the DNS from the DNS server. Red means the domain is blacklisted and the Pi-hole returned an address of 0.0.0.0.
You can use this Query Log to help find the domains to block. For example, let's say you’re watching YouTube and an advert is played. You can then look at the Query Log and see which domains were accessed at that time and blacklist ad serving domains using the blacklist button.
Note: You need to have your phone in landscape mode to see the entire Query log which has a blacklist button on the right.
You can simply blacklist the offending domain and prevent that domain from being able to serve ads to you anymore.
Note: You need to remember that the domain name and subsequent ip address may be stored in your devices cache and therefore, adding a domain to the blacklist may not have immediate effects. You need to be cautious and show restraint when adding domains to the blacklist as it’s very possible to block domains that will cause things to stop working. For example, we followed this procedure and discovered that thumbnails would no longer load when searching for GIFs in Google image search. We had to unblock that specific domain using the exact same procedure but this time looking for blocked domains and whitelisting the one we blocked earlier.
Congratulations! You have now set up your very own working digital advertisement blocker. To build it into an illuminated picture frame. with enclosure, follow the next build.
Illuminated Picture Frame
|Parts Required:||Jaycar||Altronics||Core Electronics|
|Photo Frame||IKEA: 303.784.49||-||-|
|8 x #4 9mm Screws* (to secure DC socket & 3D printed base to frame)||HP0565||H1139||FIT0224|
|4 x #4 6mm Screws* (to secure RPi to 3D printed base)||HP0550||H1145||FIT0224|
|1 x Panel Mount 2-pin DIN Socket||PS0340||P1168||ADA610 ^|
|1 x Inline 2-pin DIN Plug||PP0300||P1120||ADA3310 ^|
|1 x Length of stranded network cable to suit your application||WB2020||P1380||-|
|2 x RJ45 Plugs||PP1447||P1380||-|
|1 x Micro USB Cable (Will be cut for power connection)||XC5072||P1895A||FIT0265|
|3D Printing Filament|
|Photo Frame||IKEA: 303.784.49|
|8 x #4 9mm Screws* (to secure DC socket & 3D printed base to frame)||HP0565|
|4 x #4 6mm Screws* (to secure RPi to 3D printed base)||HP0550|
|1 x Panel Mount 2-pin DIN Socket||PS0340|
|1 x Inline 2-pin DIN Plug||PP0300|
|1 x Length of stranded network cable to suit your application||WB2020|
|2 x RJ45 Plugs||PP1447|
|1 x Micro USB Cable (Will be cut for power connection)||XC5072|
|Optional (for LED illumination):||Jaycar||Altronics||Core Electronics|
|1 x Rocker Switch||SK0984||S3210||POLOLU-1406|
|4 x 5mm Colour Changing LEDs (Slow)||-||-||COM-11450|
|4 x 100Ω Resistors*||RR0548||R7534||CE05092|
* Quantity shown, may be sold in packs. You’ll also need prototyping hardware. ^ DC connector alternatives to the DIN connectors.
Now that you have successfully set up your Pi-hole and it’s saving you from seeing thousands of ads, you should put it into an enclosure to protect it. You could hide your electronics away in a cupboard but why not put your amazing build into a picture frame like we have. This project could be a great talking point in your home and be a good reminder of your maker prowess.
We have used the RIBBA 13 x 18cm photo frame from IKEA, which you can find here: https://www.ikea.com/au/en/p/ribba-frame-black-30378449/
We then 3D printed a backing panel which we use to hold the Raspberry Pi and hide the wiring.
To spice up the design we added 4 colour changing LEDs. These LEDs simply change colour along a preprogrammed path when connected to a voltage source. These are completely optional and can be left out or replaced with LEDs of a specific colour if you like.
Creating this project will require some more specialised equipment than just the usual 3D printer and soldering iron. You will also need a drill and various drill bits, some small files and likely a step drill which will allow you to enlarge a hole to 15mm.
3D printed Enclosure
The first step in constructing the project into a frame is to 3D print the base.
Note: We have provided the stl print files on our website, as well as the Fusion 360 working file if you need to modify it to suit your needs.
This part slides into the photo frame and is secured using 3mm screws to the frame once you finish the assembly.
We printed this on our Flashforge Creator Pro using Flashforge branded white PLA and printed at a 300-micron draft setting. The print does not require supports and takes about 10-hours to print at this resolution.
The circuit for the Pi-hole is incredibly simple.
Skip the following if you are not going to use the LED illumination.
Given the LEDs are an RGB LED, they have a forward voltage that differs depending on which colour LED is active at any moment. This means it's impossible to calculate the resistor value required which will keep all LEDs at the same maximum brightness.
For this style of LED, you should really be using a constant current LED driver to drive them at a constant current of 20mA for the greatest longevity. However, since we wanted to keep the project as simple as possible, we threw the best practice out the window for a ‘simple is better’ approach, and just used the current limiting resistor. This will mean that some colours will appear much brighter than others (most notable red due to its lower forward voltage) but this isn’t really much of a problem for the average person.
If you want more consistent illumination, then you should consider using a constant current LED driver. For us, we tested the four LEDs with a 47Ω in series with the LED, and four of these in parallel on a breadboard. In this combination the current did not exceed 80mA. This means, on average, each LED was only getting 20mA, which is under the forward current.
However, this does mean we could potentially exceed the forward current of the red LED by quite a significant factor.
The red LED has an average forward voltage of 3V, thus if only the red LED is illuminated, with a 50Ω resistor the current could potentially climb as high as:
I = (Vin - Vf) / R = (5 - 3) / 50 = 40mA
This is twice as high as the suggested forward current and will likely significantly reduce the lifespan of the LED. If you intend to run the LEDs constantly, we would recommend that you use at very least a 100Ω resistor. If like us you’re only intending on running the LEDs sporadically to show it off and brightness is of primary concern, then you can consider using a lower value resistor. Provided, of course, that you acknowledge and you’re happy knowing at some point you will likely need to replace the LEDs.
The switch is used to only switch power to the LEDs. If you’re intending on running the LEDs constantly or not using LEDs, you may want to omit the switch. We did not connect the switch to the Raspberry Pi circuit as you should not switch power off to the Raspberry Pi unless it has been correctly shut down. Doing so can destroy the SD card, meaning you will need to remove the Raspberry Pi from the frame to insert a new SD card.
If you are adding LEDs to your build, solder a resistor to the anode of each of the LEDs and shorten the leads.
Slide the LED into the holes in the side of the base so that the leads and resistors are inside the channel and then solder wires to the cathode of each LED and the anode of the resistor, being sure to cover the exposed leads with heatshrink.
The LED wires should then be routed through the channel so that they protrude from the bottom of the base. These wires will later be fed through holes we make in the frame to accommodate for the power input and switch.
You will now need to cut a micro USB cable so that you have about 200mm of cable from the plug. You can then strip 50mm of outer insulation to expose the four strands of wire inside. These wires are usually red for 5V, black for ground, and the white and green wires are the differential pair for the USB data. However, we want to be careful here, and just double-check, as it is possible to have them wired incorrectly.
To test ours, we used a battery bank that was charged by a micro USB. We removed the battery from the battery bank and plugged the micro USB cable into the charging port. We then used the continuity setting on our multimeter to ensure that the red cable corresponded with the input to the charging circuit of the battery bank, and that the black wire was connected to ground. After confirming this was the case, we attached our power supply to the wires and confirmed it powered the device to be extra sure. It is also possible to connect the cable and measure for continuity between the cable and the 5V and GND rails in the GPIO header on the Raspberry Pi. Once you have confirmed the wiring colours, it’s time to connect the cable to the Raspberry Pi. The plug end is inserted into the Raspberry Pi and is fed through the hole in the base.
Skip the following if you are choosing to use the wireless mode.
We are using a wired connection, and as such, we will be making our own Cat5 cable and terminating it with the RJ45 plug, configured to the T-568B standard as shown here.
Note: Doing this requires the use of an RJ45 crimp tool. If you don’t have this tool you will need to use Tinkercad or similar to enlarge the holes on the .STL to suit the cable and RJ45 plug that you’re using.
If you are using wired, feed one end of the network cable into the hole in the base for it before terminating it with an RJ45 plug. You can then insert the RJ45 plug into the ethernet socket on the Raspberry Pi and secure the Raspberry Pi to the base using four #4 6mm screws. Once done, you can route the network cable through the channel in the base so that the cable is leaving the bottom of the base.
It's now time to make some modifications to the frame so it can accommodate the switch and inputs / outputs. To assist with this, we 3D printed a simple template which we used to help make pilot holes. The template fits over the bottom of the frame with the holes facing out. Use a 3mm drill bit in a drill to make the holes for the input power and the network cable.
Use a smaller drill bit to continuously drill holes around the perimeter for the switch, taking away as much material from the frame as possible. Once the frame is drilled, remove the template. Using a hobby knife and files, remove any excess material from the switch hole.
It may take a little while to get the hole to the best size for it to fit properly so be patient not to rush it.
Note: We used a microfibre cloth to protect the frame from getting scratched while we worked on the hole.
Network Cable Entry
Enlarge the hole for the network cable entry to about a 8mm diameter for the network cable or larger if you are planning to pass an RJ45 plug through it.
Power Cable Entry
Make a hole large enough for the power plug to fit through. In our case, we used a 15mm step drill to enlarge the power input hole to 15mm for our 2-pin DC socket.
Inserting the base
With the holes made and the socket and switch test fitted and proven to work, we can put the base into the frame.
With the frame face down on a microfibre cloth, insert the plastic cover and the inner cardboard frame into the frame. Carefully insert the network cable into the hole we made for it in the frame. Similarly, insert the wires for the LEDs into the hole for the switch and the USB cable through the hole for the input jack as seen here.
Slide two wires from the switch hole over to the DC input side. One will be to connect the 5V positive to the switch and the other will be to connect ground. The ground wire can then be connected to the LED ground and the LEDs can be connected to the switch.
For the 2-pin DIN socket and plug, we treated the spike as the 5V and the flat as the ground.
Use a little electrical tape or heatshrink to insulate both data wires (green and white) to make sure they can’t short out on anything.
Next, simply solder the 5V and ground wires to the socket.
Apply some liquid electrical tape if you have some on hand to insulate the exposed solder joints, and then use two #4 9mm screws to secure the DC socket to the frame.
Network Cable Termination
Terminate the end of your network cable with the RJ45 plug using the same T-568B standard which we used for the Raspberry Pi end.
Note: the T-568A standard is most commonly used in Australia but provided you use the same standard on on both ends, it will work as intended.
Hanging the frame on a wall using the existing sawtooth mounting hanger may lead to disaster if the frame falls due to the additional weight. We need to reinforce one of these hanger mounts using some fasteners.
Use a screwdriver to remove the mounting hanger you intend to use in hanging your frame to the wall. Gently pry the spikes out of the compressed cardboard to avoid bending it.
Use some heavy-duty pliers to flatten the spikes, and then secure it to the back of the frame using two #4 9mm screws.
The last step is to use some more #4 9mm screws to secure the 3D printed base to the frame. We added 6 holes for this but in reality, we only ended up using 4 in total. One in each corner is more than sufficient to hold the base to the frame.
You can now connect the 2-pin DIN plug to your power supply and mount the Pi-hole.
Testing is straightforward as the project is really a set and forget type of arrangement. One thing you will want to do, however, is verify that you can SSH into the Raspberry Pi, which will give you control of the system without needing a monitor, mouse and keyboard connected. This is incredibly important as there was one occasion where our Pi-hole had dropped out for us (preventing access to the internet) and we were unable to access the admin web interface for the Pi-hole. This was evident by the words “lost connection to API” displayed on the web interface.
Do not disconnect power to the Raspberry Pi in this situation. Doing so could cause the SD card to become corrupted. If this happens to you or you need to shutdown or restart the Raspberry Pi for another reason, we strongly recommend that you use an SSH client like PuTTY to SSH into the Raspberry Pi and issue it with the following restart command:
This will safely shutdown and reboot the Raspberry Pi without damaging your SD card, and thus, needing to remove the Raspberry Pi from the frame.
Note: Before you do this, you may want to consider updating the gravity database to ensure no data is lost in the reboot.
Updating the gravity database can be done by SSH’ing into the Raspberry Pi and using the following command:
By default, the Pi-hole does this once a week, however, you may want to do it before restarting your Raspberry Pi, just in case.
YouTube presents a very unique problem for the Pi-hole. The domains used by Google for the YouTube ads changes at a much higher rate than most other websites. As such, blocking advertising on YouTube is a bit more of a hit and miss affair. If your main goal is to block advertising on YouTube, then it’s quite possible that the Pi-hole will not satisfy your need completely. With that said, we certainly did experience a reduction in the number of advertisements served to us when testing the Pi-hole, but in no way was it perfect. If you want to block advertising on YouTube then your current best bet is to use a digital advertising blocking browser extension like AdBlock and using the browser to watch YouTube.
After setting up the Raspberry Pi SD card, and before deploying the Pi-hole to the wall, make a backup of the SD card to a disk .img file or a second SD card just in case you need to re-do it all another day after crashing the SD card.