<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Arduino projects Archives - Nerd Corner</title>
	<atom:link href="https://nerd-corner.com/category/arduino-projects/feed/" rel="self" type="application/rss+xml" />
	<link>https://nerd-corner.com/category/arduino-projects/</link>
	<description>Craft your dreams!</description>
	<lastBuildDate>Sun, 22 Jun 2025 17:30:54 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>

<image>
	<url>https://nerd-corner.com/wp-content/uploads/2019/10/cropped-LogoNerdCorner-2-32x32.png</url>
	<title>Arduino projects Archives - Nerd Corner</title>
	<link>https://nerd-corner.com/category/arduino-projects/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>DIY keypad lock &#8211; 3D printing and code</title>
		<link>https://nerd-corner.com/diy-keypad-lock-3d-printing-and-code/</link>
					<comments>https://nerd-corner.com/diy-keypad-lock-3d-printing-and-code/#respond</comments>
		
		<dc:creator><![CDATA[Nerds]]></dc:creator>
		<pubDate>Tue, 17 Dec 2024 20:44:05 +0000</pubDate>
				<category><![CDATA[Arduino projects]]></category>
		<category><![CDATA[Handcrafted]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[SolidWorks]]></category>
		<category><![CDATA[3D print]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[barrel jack]]></category>
		<category><![CDATA[CAD]]></category>
		<category><![CDATA[CAD design]]></category>
		<category><![CDATA[case]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[DIY]]></category>
		<category><![CDATA[housing]]></category>
		<category><![CDATA[jumper cable]]></category>
		<category><![CDATA[keypad]]></category>
		<category><![CDATA[led]]></category>
		<category><![CDATA[lock]]></category>
		<category><![CDATA[precise]]></category>
		<category><![CDATA[Solid Works]]></category>
		<category><![CDATA[user guide]]></category>
		<guid isPermaLink="false">https://nerd-corner.com/de/?p=1677</guid>

					<description><![CDATA[<p>A cupboard that should always be locked and five people who need to access it &#8211; a classic challenge. The obvious solutions? Five keys in &#8230; </p>
<p>The post <a href="https://nerd-corner.com/diy-keypad-lock-3d-printing-and-code/">DIY keypad lock &#8211; 3D printing and code</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>A cupboard that should always be locked and five people who need to access it &#8211; a classic challenge. The obvious solutions? Five keys in circulation or a single person who manages the key so that you have to borrow it every time. But we&#8217;ve all been there: the key ends up lying in the cupboard, under the carpet or behind the flower pot.</p>
<p>But wouldn&#8217;t it be much more practical to do away with physical keys altogether? Nowadays, there are numerous ways to open a lock: Fingerprint scanners, facial recognition, NFC, numeric codes, dials &#8211; or, of course, brute force methods such as explosives and brute force. But if you are looking for an inexpensive, non-violent and simple solution, the keypad lock comes into focus.</p>
<p>Surprisingly, there are hardly any really good DIY solutions for hobbyists on the Internet. So I tackle it myself &#8211; my first keypad lock, which I simply call “Version 1”.</p>
<p><em><strong>This might also be interesting for you: </strong><a href="https://nerd-corner.com/diy-powerbank-with-voltage-regulator-and-voltmeter/">Do it yourself powerbank with voltage regulator and voltmeter</a></em></p>
<h2>Construction of the housing</h2>
<p>The initial focus is on the housing and the keypad holder. The first question that always arises is: How big should it be? The answer depends on several factors:</p>
<ul>
<li>Which components are required? Each component takes up space and influences the design.</li>
<li>How much space do the components take up? A compact design is advantageous, but must not restrict functionality.</li>
<li>What are the haptics and operability like? The keypad should be comfortable to use without being too cramped or impractical.</li>
</ul>
<p>These considerations form the basis for the housing design &#8211; because good planning saves time and nerves later on.</p>
<h3>What will be inside the housing?</h3>
<p>The central component is, of course, the membrane keypad (1.0.1). It has the following dimensions:</p>
<ul>
<li>Width: 69 mm</li>
<li>Length: 76 mm</li>
<li>Thickness: 0.6 mm (or 0.95 mm above the keys)</li>
</ul>
<p>The keypad also has a ribbon cable with DuPont sockets for connection to a microcontroller. The cable itself is 85 mm long and 17.78 mm wide.</p>
<p>The control center of the lock is the Nano (1.0.2). To accommodate it neatly in the housing and to make the cable connections as convenient as possible, I opted for a Nano expansion board with screw terminals (1.0.4).</p>
<p>A hollow socket (5.5 x 2.1 mm, 1.0.4) is used for the emergency power supply so that the lock continues to function even in the event of a power failure.</p>
<p><img fetchpriority="high" decoding="async" class="aligncenter wp-image-1671 zoooom" src="https://nerd-corner.com/wp-content/uploads/2024/12/1-0-1.jpg" alt="tastenfeldschloss Bauteile" width="2310" height="1324" srcset="https://nerd-corner.com/wp-content/uploads/2024/12/1-0-1.jpg 2318w, https://nerd-corner.com/wp-content/uploads/2024/12/1-0-1-300x172.jpg 300w, https://nerd-corner.com/wp-content/uploads/2024/12/1-0-1-1024x587.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2024/12/1-0-1-768x440.jpg 768w, https://nerd-corner.com/wp-content/uploads/2024/12/1-0-1-1536x881.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2024/12/1-0-1-2048x1174.jpg 2048w" sizes="(max-width: 2310px) 100vw, 2310px" /></p>
<p>The pin and socket connectors (1.1.1) serve as the central power distribution and are later soldered to the breadboard (1.1.2). Jumper cables (1.1.3) are used to ensure that all components are reliably connected. Depending on the position of the components, different lengths are required &#8211; in this case 10 cm and 20 cm.</p>
<p><img decoding="async" class="aligncenter wp-image-1670 zoooom" src="https://nerd-corner.com/wp-content/uploads/2024/12/1-1.jpg" alt="" width="2310" height="1327" srcset="https://nerd-corner.com/wp-content/uploads/2024/12/1-1.jpg 2321w, https://nerd-corner.com/wp-content/uploads/2024/12/1-1-300x172.jpg 300w, https://nerd-corner.com/wp-content/uploads/2024/12/1-1-1024x588.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2024/12/1-1-768x441.jpg 768w, https://nerd-corner.com/wp-content/uploads/2024/12/1-1-1536x882.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2024/12/1-1-2048x1176.jpg 2048w" sizes="(max-width: 2310px) 100vw, 2310px" /></p>
<p>For the status display of the keypad lock, I use Neo Pixel addressable LEDs of type WS2812b (1.2.1). These can be used to control different colors and effects to visually display the current status of the lock.</p>
<p>I will go into the positioning of the screws in more detail later.</p>
<p><img decoding="async" class="aligncenter wp-image-1669 zoooom" src="https://nerd-corner.com/wp-content/uploads/2024/12/1-2.jpg" alt="" width="2320" height="1324" srcset="https://nerd-corner.com/wp-content/uploads/2024/12/1-2.jpg 2331w, https://nerd-corner.com/wp-content/uploads/2024/12/1-2-300x171.jpg 300w, https://nerd-corner.com/wp-content/uploads/2024/12/1-2-1024x584.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2024/12/1-2-768x438.jpg 768w, https://nerd-corner.com/wp-content/uploads/2024/12/1-2-1536x876.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2024/12/1-2-2048x1169.jpg 2048w, https://nerd-corner.com/wp-content/uploads/2024/12/1-2-1400x800.jpg 1400w" sizes="(max-width: 2320px) 100vw, 2320px" /></p>
<p>Now that the components have been determined, I can think about the size of the housing. This is not only determined by the installed elements, but above all by the usability and feel.</p>
<p>We encounter keypads every day &#8211; on ATMs, telephones, door lock systems and, of course, smartphones. The decision for the depth of the housing is based on a positive memory of my penultimate workplace: the keypad lock at the entrance was raised and easily accessible from both sides. You could operate it comfortably with your right or left thumb, and the rounded corners provided a pleasant feel when you put your hand on it.</p>
<h2>Keypad lock Housing design</h2>
<p>This results in a depth of 45 mm (2.0.3). For better ergonomics, the corners have a radius of 15 mm (R15) and the surrounding upper edges have a radius of 10 mm (R10). I am aware that these roundings slightly reduce the interior space, but the comfort and appearance outweigh this disadvantage.</p>
<p>The width and height of the housing are determined by the components to be installed. The space for the cabling must also be taken into account. Particularly important: When installed, the Nano should still be accessible with a standard USB mini cable, for example to be able to install new programs.</p>
<h3>Mounting and fastening</h3>
<ul>
<li>Four M3 threads (2.0.1) on the inside allow the support plate to be screwed on.</li>
<li>In addition, there are four mounting points with Ø4.2 mm holes for attaching the housing to a door, cover or wall.</li>
<li>The housing has a window (2.0.2) measuring 60 × 67 mm, which is intended for the keypad. This is later filled with the carrier plate.</li>
<li>Retaining columns with M2 threads and the opening for the hollow socket (1.0.4) are marked with orange ellipses (2.0.1, 2.0.3).</li>
<li>The next picture (2.0.4) shows the external dimensions: 110 mm wide and 117 mm high.</li>
<li>In addition, an aperture or slot 50 mm long is required for the LED cover (2.0.5).</li>
</ul>
<p>For the wall thickness of the housing, I have provided 2 mm throughout &#8211; stable enough for the intended purpose.</p>
<p>With the housing construction completed, we can now continue with the other components.</p>
<h3 data-start="1513" data-end="1546"><img loading="lazy" decoding="async" class="aligncenter wp-image-1668 zoooom" style="font-family: 'Source Sans Pro', Graphik, -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif; font-size: 1.125rem;" src="https://nerd-corner.com/wp-content/uploads/2024/12/2-0-1.jpg" alt="Tastenfeldschloss Gehäuse" width="2310" height="1330" srcset="https://nerd-corner.com/wp-content/uploads/2024/12/2-0-1.jpg 2316w, https://nerd-corner.com/wp-content/uploads/2024/12/2-0-1-300x173.jpg 300w, https://nerd-corner.com/wp-content/uploads/2024/12/2-0-1-1024x589.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2024/12/2-0-1-768x442.jpg 768w, https://nerd-corner.com/wp-content/uploads/2024/12/2-0-1-1536x884.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2024/12/2-0-1-2048x1179.jpg 2048w" sizes="auto, (max-width: 2310px) 100vw, 2310px" /></h3>
<h3>The support plate &#8211; the central mounting element</h3>
<p>The next important component is the carrier plate. The name is self-explanatory: With the exception of the hollow bushing, all components are attached here. This system offers several advantages over direct mounting in the housing:</p>
<p><img src="https://s.w.org/images/core/emoji/16.0.1/72x72/2705.png" alt="✅" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Easy mounting outside the housing &#8211; More space and better handling when wiring.<br />
<img src="https://s.w.org/images/core/emoji/16.0.1/72x72/2705.png" alt="✅" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Modularity &#8211; different carrier plates with different components are possible.<br />
<img src="https://s.w.org/images/core/emoji/16.0.1/72x72/2705.png" alt="✅" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Simple enclosure design &#8211; The enclosure design remains simpler and more flexible.<br />
<img src="https://s.w.org/images/core/emoji/16.0.1/72x72/2705.png" alt="✅" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Easy replacement &#8211; Components can be replaced or extended more easily.</p>
<p>But there is another decisive advantage for the keypad lock in particular:</p>
<p>The keypad is glued directly into a designated recess in the carrier plate (2.1.1). The carrier plate and keypad are then inserted into the housing from behind and fixed in place with M3 screws. The frame of the window in the housing completely covers the edge and the cables.</p>
<p><img src="https://s.w.org/images/core/emoji/16.0.1/72x72/1f512.png" alt="🔒" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Safety aspect: The window is dimensioned in such a way that the edge and the cables remain concealed, but the buttons are fully visible and operable. This means that the keypad cannot be removed without destroying it &#8211; an important protective mechanism against tampering.</p>
<h3>Fastening the components to the carrier plate</h3>
<p>There are various mounting options for the electronics on the back (2.1.2) of the carrier plate:</p>
<p><img src="https://s.w.org/images/core/emoji/16.0.1/72x72/1f7e1.png" alt="🟡" class="wp-smiley" style="height: 1em; max-height: 1em;" /> M3 thread for the nano adapter (2.1.3) &#8211; As nano adapters on the Internet often have different hole spacings, there is an additional fastening thread on the right-hand side (2.1.2) for flexible adjustment. If the holes still do not fit exactly, they can be carefully widened &#8211; but without damaging the adapter&#8217;s conductor tracks.</p>
<p><img src="https://s.w.org/images/core/emoji/16.0.1/72x72/1f534.png" alt="🔴" class="wp-smiley" style="height: 1em; max-height: 1em;" /> M2 thread for the Nano R3 ATMEGA168P (2.1.4) &#8211; An alternative, cost-effective solution instead of a Nano R3 with adapter.</p>
<p><img src="https://s.w.org/images/core/emoji/16.0.1/72x72/1f535.png" alt="🔵" class="wp-smiley" style="height: 1em; max-height: 1em;" /> M2 thread for the breadboard (20×80 mm, 1.1.2, 2.1.5) &#8211; This is used for power distribution and connects all power supply lines neatly at a central point.</p>
<h3 data-start="1487" data-end="1545"><img loading="lazy" decoding="async" class="aligncenter wp-image-1667 zoooom" style="font-family: 'Source Sans Pro', Graphik, -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif; font-size: 1.125rem;" src="https://nerd-corner.com/wp-content/uploads/2024/12/2-1-1.jpg" alt="" width="2310" height="1329" srcset="https://nerd-corner.com/wp-content/uploads/2024/12/2-1-1.jpg 2317w, https://nerd-corner.com/wp-content/uploads/2024/12/2-1-1-300x173.jpg 300w, https://nerd-corner.com/wp-content/uploads/2024/12/2-1-1-1024x589.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2024/12/2-1-1-768x442.jpg 768w, https://nerd-corner.com/wp-content/uploads/2024/12/2-1-1-1536x884.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2024/12/2-1-1-2048x1178.jpg 2048w" sizes="auto, (max-width: 2310px) 100vw, 2310px" /></h3>
<h3>The LED cover and its attachment</h3>
<p>The LED cover (2.2.1) has been designed so that it is clicked into the slot (2.0.5) of the housing from the rear. The radius on the outside of the LED cover corresponds to the housing radius, creating a smooth transition and allowing the cover to blend in seamlessly.</p>
<p>I don&#8217;t need to redesign the mounting bridge (front 2.2.2, back 2.2.3) as I have already used it successfully in other projects.</p>
<h3>Mounting the LEDs</h3>
<p>Now it remains to mount the three WS2812b LEDs (1.2.1). I will explain why exactly three LEDs are needed later in the programming section of this article.</p>
<p>The development of the LED holder (SMD50, 2.2.4) was more complex than expected. Of course, you could simply glue, clamp or hot glue the LED strips &#8211; but that seemed too unprofessional to me.</p>
<p>I therefore invested a lot of time and effort in designing a perfect holder. The result can be seen in picture 2.2.5.</p>
<p><img src="https://s.w.org/images/core/emoji/16.0.1/72x72/1f4cc.png" alt="📌" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Further information:</p>
<p data-start="1181" data-end="1300"><a href="https://nerd-corner.com/click-and-clamp-system-smd5050-bracket/">For details on the construction, there is a separate article on NerdCorner.</a></p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1666 zoooom" src="https://nerd-corner.com/wp-content/uploads/2024/12/2-2-1.jpg" alt="" width="2310" height="1330" srcset="https://nerd-corner.com/wp-content/uploads/2024/12/2-2-1.jpg 2316w, https://nerd-corner.com/wp-content/uploads/2024/12/2-2-1-300x173.jpg 300w, https://nerd-corner.com/wp-content/uploads/2024/12/2-2-1-1024x589.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2024/12/2-2-1-768x442.jpg 768w, https://nerd-corner.com/wp-content/uploads/2024/12/2-2-1-1536x884.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2024/12/2-2-1-2048x1179.jpg 2048w" sizes="auto, (max-width: 2310px) 100vw, 2310px" /></p>
<h2>3D printing of the components</h2>
<p>Once the design has been completed, the parts must now be printed.</p>
<p><img src="https://s.w.org/images/core/emoji/16.0.1/72x72/1f4cc.png" alt="📌" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Material selection for the individual components:</p>
<ul>
<li>Housing (3.0.1): Printed with ABS filament, consisting of front and back.</li>
<li>Carrier plate (3.0.2): made from PLA filament.</li>
<li>LED cover (3.0.3): produced upright in the printer, printed with PLA+ in the color “natural”.</li>
<li>LED terminals (3.0.4): also made of PLA+, manufactured in the same process as the LED cover.</li>
<li>Bridge for the hollow socket: printed from PLA filament, analogous to the carrier plate.</li>
</ul>
<p>With these materials, the mechanical and thermal properties of the components are optimally matched to their respective applications.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1665 zoooom" src="https://nerd-corner.com/wp-content/uploads/2024/12/3-0-1.jpg" alt="" width="2310" height="1329" srcset="https://nerd-corner.com/wp-content/uploads/2024/12/3-0-1.jpg 2317w, https://nerd-corner.com/wp-content/uploads/2024/12/3-0-1-300x173.jpg 300w, https://nerd-corner.com/wp-content/uploads/2024/12/3-0-1-1024x589.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2024/12/3-0-1-768x442.jpg 768w, https://nerd-corner.com/wp-content/uploads/2024/12/3-0-1-1536x884.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2024/12/3-0-1-2048x1178.jpg 2048w" sizes="auto, (max-width: 2310px) 100vw, 2310px" /></p>
<h2>Post-processing of the components</h2>
<p>After printing, both the printed parts and some purchased parts need to be processed.</p>
<p>1&#x20e3; Cleaning the 3D printed parts</p>
<ul>
<li>Removal of support material and protruding print residues.</li>
</ul>
<p>2&#x20e3; Cutting the thread<br />
Housing (4.0.1):</p>
<ul>
<li>Four M3 threads (Attention: blind holes! Proceed carefully when cutting so as not to push the base outwards).</li>
<li>Two M2 threads (4.0.2).</li>
<li>Support plate (4.0.3):
<ul>
<li>The M2 threads marked in blue must be cut in any case.</li>
<li>When using a nano adapter with screw terminals (2.1.4), the M2 threads marked in red must also be cut.</li>
</ul>
</li>
</ul>
<p>3&#x20e3; Shortening the perforated grid plate</p>
<ul>
<li>The perforated grid plate (4.0.4) must be shortened to 8 to a maximum of 10 perforated grids.<br />
Important: The mounting holes should be retained (see 4.0.5).</li>
</ul>
<p>4&#x20e3; Shortening the pin header</p>
<ul>
<li>Shorten the pin header to eight pins using a side cutter (4.0.6).</li>
</ul>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1664 zoooom" src="https://nerd-corner.com/wp-content/uploads/2024/12/4-0-2.jpg" alt="" width="2310" height="1394" srcset="https://nerd-corner.com/wp-content/uploads/2024/12/4-0-2.jpg 2316w, https://nerd-corner.com/wp-content/uploads/2024/12/4-0-2-300x181.jpg 300w, https://nerd-corner.com/wp-content/uploads/2024/12/4-0-2-1024x618.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2024/12/4-0-2-768x464.jpg 768w, https://nerd-corner.com/wp-content/uploads/2024/12/4-0-2-1536x927.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2024/12/4-0-2-2048x1236.jpg 2048w" sizes="auto, (max-width: 2310px) 100vw, 2310px" /></p>
<h3>Soldering the components</h3>
<p>Now it&#8217;s time to solder the parts. First we concentrate on the power supply board:</p>
<p>1&#x20e3; Soldering the power supply board</p>
<ul>
<li>Perforated grid plate (4.0.5): Soldering the base strip (1.1.1) and the pin strip (4.0.6).</li>
<li>Pin strip (4.1.2): A two-row pin and skirting board is soldered on. We connect the two rows on the back with solder.</li>
<li>The rows differ in male and female as well as in the colors: red for plus and black for minus. This makes it easier to connect the power supply.</li>
</ul>
<p>2&#x20e3; Soldering the WS2812B LEDs</p>
<ul>
<li>Soldering the connections of the WS2812B LED strip (4.1.3).</li>
</ul>
<p>3&#x20e3; Soldering the hollow socket</p>
<ul>
<li>Finally, the hollow socket (1.0.4) is soldered (4.1.4).</li>
<li>Detailed instructions <a href="https://nerd-corner.com/using-a-barrel-jack-as-a-switch/">on soldering the hollow socket can be found</a> in a separate article. It is important to know the exact procedure in order to avoid mistakes.</li>
</ul>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1663 zoooom" src="https://nerd-corner.com/wp-content/uploads/2024/12/4-1-2.jpg" alt="" width="2310" height="1329" srcset="https://nerd-corner.com/wp-content/uploads/2024/12/4-1-2.jpg 2317w, https://nerd-corner.com/wp-content/uploads/2024/12/4-1-2-300x173.jpg 300w, https://nerd-corner.com/wp-content/uploads/2024/12/4-1-2-1024x589.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2024/12/4-1-2-768x442.jpg 768w, https://nerd-corner.com/wp-content/uploads/2024/12/4-1-2-1536x884.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2024/12/4-1-2-2048x1178.jpg 2048w" sizes="auto, (max-width: 2310px) 100vw, 2310px" /></p>
<h2 data-start="75" data-end="118">Assembling the keypad lock</h2>
<p data-start="75" data-end="118">1&#x20e3; Installing the LED cover</p>
<ul>
<li data-start="75" data-end="118">First click the LED cover (2.2.1) into the housing.</li>
<li data-start="75" data-end="118">Glue the LED cover in the intended places as shown in pictures 5.0.1 and 5.0.2.</li>
</ul>
<p>2&#x20e3; Plug in the Nano R3</p>
<ul>
<li data-start="75" data-end="118">Insert the Nano R3 (1.0.2) into the Nano adapter (5.0.3) of your choice.</li>
</ul>
<p>3&#x20e3; Installing the Nano adapter</p>
<ul>
<li data-start="75" data-end="118">Screw the Nano adapter (1.0.3) with the inserted Nano R3 (1.0.2) to the back of the carrier plate (4.0.3).</li>
<li data-start="75" data-end="118">Use the M3 threads on the carrier plate and the screws (1.2.2), as shown in pictures 5.0.4 and 5.0.5.</li>
</ul>
<p>4&#x20e3; Attaching the power supply</p>
<ul>
<li data-start="75" data-end="118">Attach the power supply (4.1.2) to the back of the carrier plate (4.0.3) using the screws (1.2.4).</li>
<li data-start="75" data-end="118">See figure 5.0.6.</li>
</ul>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1662 zoooom" src="https://nerd-corner.com/wp-content/uploads/2024/12/5-0-1.jpg" alt="" width="2310" height="1330" srcset="https://nerd-corner.com/wp-content/uploads/2024/12/5-0-1.jpg 2316w, https://nerd-corner.com/wp-content/uploads/2024/12/5-0-1-300x173.jpg 300w, https://nerd-corner.com/wp-content/uploads/2024/12/5-0-1-1024x589.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2024/12/5-0-1-768x442.jpg 768w, https://nerd-corner.com/wp-content/uploads/2024/12/5-0-1-1536x884.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2024/12/5-0-1-2048x1179.jpg 2048w" sizes="auto, (max-width: 2310px) 100vw, 2310px" /></p>
<h3 data-start="75" data-end="127">Mounting the keypad on the support plate</h3>
<p>1&#x20e3; Selecting the screw length</p>
<ul>
<li data-start="75" data-end="127">Make sure to select the correct screw length as shown in Figure 5.1.1.</li>
<li data-start="75" data-end="127">Screws must not be too long, otherwise they will protrude from the adhesive surface when the keypad is attached and the keypad cannot be glued on cleanly.</li>
</ul>
<p>2&#x20e3; Preparing the keypad</p>
<ul>
<li data-start="75" data-end="127">Remove the protective film from the keypad (1.0.1).</li>
<li data-start="75" data-end="127">To remove the film, use a carpet knife to carefully get between the adhesive layer and the protective film at one corner (see 5.1.2).</li>
<li data-start="75" data-end="127">Once you have reached the corner, peel off the entire protective film (see 5.1.3).</li>
</ul>
<p>3&#x20e3; Stick on the keypad</p>
<ul>
<li data-start="75" data-end="127">Insert the keypad (1.0.1) into the recess on the front of the carrier plate (2.1.1) and press it firmly into place.</li>
<li data-start="75" data-end="127">The keypad must be completely recessed and must not protrude over the edge (see 5.1.4).</li>
<li data-start="75" data-end="127">Make sure that the cables are also in the recess (see 5.1.5).</li>
</ul>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1661 zoooom" src="https://nerd-corner.com/wp-content/uploads/2024/12/5-1-1.jpg" alt="" width="2340" height="1327" srcset="https://nerd-corner.com/wp-content/uploads/2024/12/5-1-1.jpg 2350w, https://nerd-corner.com/wp-content/uploads/2024/12/5-1-1-300x170.jpg 300w, https://nerd-corner.com/wp-content/uploads/2024/12/5-1-1-1024x581.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2024/12/5-1-1-768x436.jpg 768w, https://nerd-corner.com/wp-content/uploads/2024/12/5-1-1-1536x871.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2024/12/5-1-1-2048x1162.jpg 2048w" sizes="auto, (max-width: 2340px) 100vw, 2340px" /></p>
<h3 data-start="64" data-end="123">Wiring the keypad to the Arduino Nano R3</h3>
<p>1&#x20e3; Using jumper cables</p>
<ul>
<li data-start="64" data-end="123">Jumper cables (10 cm long, male-male) are used to connect the keypad to the Arduino Nano R3 (see 5.2.1).</li>
</ul>
<p>2&#x20e3; Connecting the cables</p>
<ul>
<li data-start="64" data-end="123">Make sure that you do not twist the cables, but only bend them.</li>
<li data-start="64" data-end="123">The left cable is connected to D2 of the Arduino and the right cable to D8.</li>
<li data-start="64" data-end="123">There are seven cables in total, which occupy the connections D2 to D8 (see 5.2.3).</li>
</ul>
<p>3&#x20e3; Use pin headers</p>
<ul>
<li data-start="64" data-end="123">As the pitch of the Arduino adapter and the keypad do not match, you can use pin strips to make the connection.</li>
</ul>
<p>4&#x20e3; Fastening the LED terminals</p>
<ul>
<li data-start="64" data-end="123">The clips (3.0.4) for the WS2812B LEDs are clicked onto the LEDs.</li>
<li data-start="64" data-end="123">It is best to do this on a flat surface (see 5.2.4).</li>
</ul>
<p>5&#x20e3; Attaching the LED strip</p>
<ul>
<li data-start="64" data-end="123">The WS2812B strip is now pushed onto the center of the top of the carrier plate (see 5.2.5 Front and 5.2.6 Rear).</li>
</ul>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1660 zoooom" src="https://nerd-corner.com/wp-content/uploads/2024/12/5-2.jpg" alt="" width="2310" height="1330" srcset="https://nerd-corner.com/wp-content/uploads/2024/12/5-2.jpg 2316w, https://nerd-corner.com/wp-content/uploads/2024/12/5-2-300x173.jpg 300w, https://nerd-corner.com/wp-content/uploads/2024/12/5-2-1024x589.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2024/12/5-2-768x442.jpg 768w, https://nerd-corner.com/wp-content/uploads/2024/12/5-2-1536x884.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2024/12/5-2-2048x1179.jpg 2048w" sizes="auto, (max-width: 2310px) 100vw, 2310px" /></p>
<h3>Assembling the carrier plate and housing</h3>
<p>1&#x20e3; Screwing the support plate to the housing (5.3.1)</p>
<ul>
<li>Make sure that you use M3 screws that are not too long. Otherwise, they could push a bump into the front of the housing when tightened.</li>
<li>The alignment of the carrier plate in the housing is important: the LED strip should be on the same side as the LED cover.</li>
<li>After screwing, the keypad should be lightly pressed against the inner frame of the housing (see 5.3.2 and 5.3.3).</li>
</ul>
<p>2&#x20e3; Pre-assembly of the hollow socket for the emergency power supply</p>
<ul>
<li>For the emergency power supply, you must pre-assemble the hollow socket and screw it to the housing.</li>
<li>The hollow socket with bridge and nut is shown in Figure 5.3.4.</li>
<li>Insert the hollow bush into the round recess of the bridge.</li>
<li>Lock the hollow bushing with the nut on the other side of the bridge.</li>
</ul>
<p>3&#x20e3; Fastening the hollow bush in the housing</p>
<ul>
<li>The hollow bush with the bridge is then screwed to the retaining pillars provided in the housing using M2 screws (see 5.3.5 and 5.3.6).</li>
</ul>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1659 zoooom" src="https://nerd-corner.com/wp-content/uploads/2024/12/5-3.jpg" alt="" width="2310" height="1329" srcset="https://nerd-corner.com/wp-content/uploads/2024/12/5-3.jpg 2317w, https://nerd-corner.com/wp-content/uploads/2024/12/5-3-300x173.jpg 300w, https://nerd-corner.com/wp-content/uploads/2024/12/5-3-1024x589.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2024/12/5-3-768x442.jpg 768w, https://nerd-corner.com/wp-content/uploads/2024/12/5-3-1536x884.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2024/12/5-3-2048x1178.jpg 2048w" sizes="auto, (max-width: 2310px) 100vw, 2310px" /></p>
<h3>Connecting the cables and completing the power supply</h3>
<p>1&#x20e3; Connecting the control cable for the servo motor</p>
<ul>
<li>The control cable for the servo motor is connected to pin D9 of the Nano R3 (5.4.1).</li>
</ul>
<p>2&#x20e3; Connecting the power supply for the Nano R3</p>
<ul>
<li>The power supply for the Nano R3 is connected to the GND pin and the VIN pin of the Nano R3 (5.4.2).</li>
</ul>
<p>3&#x20e3; Connecting the control cable for the WS2812B</p>
<ul>
<li>The control cable for the WS2812B LED strip is connected to pin D10 of the Nano R3 (5.4.3).</li>
</ul>
<p>4&#x20e3; Wiring of the power distributor</p>
<ul>
<li>All remaining cables must be connected to the power distributor:
<ul>
<li>Servo motor connection</li>
<li>Arduino Nano R3</li>
<li>WS2812B LED strip</li>
<li>Hollow socket All connections are made with plus and minus (see 5.4.4 and 5.4.5).</li>
</ul>
</li>
</ul>
<p>5&#x20e3; Using different colors and connection types for the wiring</p>
<ul>
<li>It helps to use different cable colors:
<ul>
<li>Red for plus</li>
<li>Black for minus</li>
</ul>
</li>
<li>The power distributor has different connection types:
<ul>
<li>Male for plus</li>
<li>Female for minus</li>
</ul>
</li>
</ul>
<p>6&#x20e3; Note on the hollow socket</p>
<ul>
<li><a href="https://nerd-corner.com/using-a-barrel-jack-as-a-switch/">There is a separate article on wiring and connecting the hollow socket, which you should definitely read</a></li>
</ul>
<p>7&#x20e3; Attaching the connector housings for the servo motor and power supply</p>
<ul>
<li>A three-pin plug is required for the servo motor connection.</li>
<li>A two-pin plug is required for the external power supply.</li>
</ul>
<p><a href="https://nerd-corner.com/3d-printed-dupont-connector-for-jumper-cable/">Further details on the construction process and the download links for connector housings can be found here.</a></p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1658 zoooom" src="https://nerd-corner.com/wp-content/uploads/2024/12/5-4.jpg" alt="" width="2310" height="1330" srcset="https://nerd-corner.com/wp-content/uploads/2024/12/5-4.jpg 2316w, https://nerd-corner.com/wp-content/uploads/2024/12/5-4-300x173.jpg 300w, https://nerd-corner.com/wp-content/uploads/2024/12/5-4-1024x589.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2024/12/5-4-768x442.jpg 768w, https://nerd-corner.com/wp-content/uploads/2024/12/5-4-1536x884.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2024/12/5-4-2048x1179.jpg 2048w" sizes="auto, (max-width: 2310px) 100vw, 2310px" /></p>
<p>Figure 5.5.1 shows the entire cabling again.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1657 zoooom" src="https://nerd-corner.com/wp-content/uploads/2024/12/5-5.jpg" alt="fritzing keypad lock" width="2310" height="1330" srcset="https://nerd-corner.com/wp-content/uploads/2024/12/5-5.jpg 2316w, https://nerd-corner.com/wp-content/uploads/2024/12/5-5-300x173.jpg 300w, https://nerd-corner.com/wp-content/uploads/2024/12/5-5-1024x589.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2024/12/5-5-768x442.jpg 768w, https://nerd-corner.com/wp-content/uploads/2024/12/5-5-1536x884.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2024/12/5-5-2048x1179.jpg 2048w" sizes="auto, (max-width: 2310px) 100vw, 2310px" /></p>
<h2>Arduino code</h2>
<p>After the intensive work with the hardware and the 3D printer, we now turn our attention to the strategy and programming of the keypad lock. Why is a strategy important for a keypad lock? A well thought-out sequence of actions &#8211; i.e. the order in which the keypad lock is operated, which events result from certain actions and which goal is being pursued &#8211; forms the basis for functional control. This guideline is therefore also crucial for programming the keypad lock: it determines what should happen when and which hardware is used. The aim is to create a logical and comprehensible sequence of events, which in this case can also be understood visually.</p>
<p>Example 1:<br />
The keypad lock should display how many digits have already been entered. (See Figures 7.0.1 to 7.0.4)</p>
<p>Example 2:<br />
The keypad lock should indicate whether the password entered is correct after pressing a specific key. (See figure 7.0.5)</p>
<p>Example 3:<br />
The keypad lock should indicate if something has been entered incorrectly, such as an incorrect password or too many keystrokes. (See figure 7.0.8)</p>
<p>Example 4:<br />
The keypad lock should display the current status. (See Figures 7.0.5 to 7.0.7)</p>
<p>Now let&#8217;s move on to programming the keypad lock, which differs from conventional programs on the Internet in a few respects. To begin with, the three necessary libraries are included: &lt;Keypad.h&gt; for the keypad, &lt;Adafruit_NeoPixel.h&gt; for the WS2812B LEDs and &lt;Servo.h&gt; for the servo motor (Figure 6.0.1). In the following section, the pin assignment for the LEDs is defined, whereby pin D10 is used and the number of LEDs and the color scheme are determined. The brightness of the LEDs is also defined &#8211; this value can be adjusted depending on the location, with higher values providing more brightness (values from 0 to 255). (See figure 6.0.2) The third section is dedicated to the description of the keypad used, including the number of rows and columns and the assignment of the buttons. (See figure 6.0.3).</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1656 zoooom" src="https://nerd-corner.com/wp-content/uploads/2024/12/6-0-1.jpg" alt="" width="2310" height="1330" srcset="https://nerd-corner.com/wp-content/uploads/2024/12/6-0-1.jpg 2316w, https://nerd-corner.com/wp-content/uploads/2024/12/6-0-1-300x173.jpg 300w, https://nerd-corner.com/wp-content/uploads/2024/12/6-0-1-1024x589.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2024/12/6-0-1-768x442.jpg 768w, https://nerd-corner.com/wp-content/uploads/2024/12/6-0-1-1536x884.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2024/12/6-0-1-2048x1179.jpg 2048w" sizes="auto, (max-width: 2310px) 100vw, 2310px" /></p>
<p>In the fourth section, the servomotor is configured by defining the degree range it can cover and the speed at which it should move (see Figure 6.1.1). This is followed by the section for entering the password. Here you have the option of changing the default password 1516 to set a new four-digit password. The program will only work correctly if a four-digit code is entered. In this section, the control pin for the servo motor is also set to D9 (see Figure 6.1.2). The following section is dedicated to defining the colors for the various events.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1655 zoooom" src="https://nerd-corner.com/wp-content/uploads/2024/12/6-1-1.jpg" alt="" width="2310" height="1330" srcset="https://nerd-corner.com/wp-content/uploads/2024/12/6-1-1.jpg 2316w, https://nerd-corner.com/wp-content/uploads/2024/12/6-1-1-300x173.jpg 300w, https://nerd-corner.com/wp-content/uploads/2024/12/6-1-1-1024x589.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2024/12/6-1-1-768x442.jpg 768w, https://nerd-corner.com/wp-content/uploads/2024/12/6-1-1-1536x884.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2024/12/6-1-1-2048x1179.jpg 2048w" sizes="auto, (max-width: 2310px) 100vw, 2310px" /></p>
<p>The last two sections explain the behavior of the keypad lock during certain actions. This description is of course only a rough overview of the program. In a future article for keypad lock version 2, we will explain the program in more detail and more comprehensively.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">//==========================================Librarys==============================================================
#include &lt;Keypad.h&gt;
#include &lt;Adafruit_NeoPixel.h&gt;
#include &lt;Servo.h&gt;
//========================================Neo-Pixel==============================================================
#define LED_PIN 10
#define LED_COUNT 3
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
int led_strength = 75; //controlls Brighttness (0 - 255)
//========================================Keypad=================================================================
const byte rows = 4;
const byte cols = 3;
char keys[rows][cols] = {
 {'1', '2', '3'},
 {'4', '5', '6'},
 {'7', '8', '9'},
 {'*', '0', '#'}
};
byte rowPins[rows] = {8, 7, 6, 5};
byte colPins[cols] = {4, 3, 2};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );
//=========================================Servo============================================================
Servo lock;
int pos = 0;
int servo_angle = 180;
int servo_speed = 15;
//======================================Password===============================================================
String input;
const String password = "1516"; //Set Password
int n = 1;

 

void setup() {
 input.reserve(password.length() +2);
 strip.begin();
 strip.show();
 lock.attach(9); //motor pin
}

void loop() {
//-------------------colours------------------------------------------------------------------- 
 uint32_t blue = strip.Color(0, 0, led_strength);
 uint32_t green = strip.Color(0, led_strength, 0);
 uint32_t red = strip.Color(led_strength, 0, 0);
 uint32_t orange = strip.Color(led_strength, led_strength/2, 0);

 char key = keypad.getKey();

if (key != NO_KEY) {
//-------------------------End conditions------------------------------------------------------
 if (key == '#') {
 if (input == password) {
 //unlock
 strip.clear();
 strip.fill(green, 0, LED_COUNT);
 strip.show();
 for (pos = 0; pos &lt;= servo_angle; pos += 1) {
 lock.write(pos);
 delay(servo_speed );
 }
 while (1 == 1)
 { char key = keypad.getKey();
 strip.clear();
 strip.fill(orange, 0, LED_COUNT);
 strip.show();
 if (key == '*')
 {
 strip.clear();
 strip.fill(green, 0, LED_COUNT);
 strip.show();
 break;
 }
 }

 for (pos = servo_angle; pos &gt;= 0; pos -= 1) {
 lock.write(pos);
 delay(servo_speed );
 }
 n = 1;
 input = "";
 delay (1000);
 strip.clear();
 strip.show();
 } else {
 //wrong password
 strip.clear();
 strip.fill(red, 0, LED_COUNT);
 strip.show();
 n = 1;
 input = "";
 delay (1000);
 strip.clear();
 strip.show();
 }
 }
 else if (n == password.length() + 1) {
 //Input too long
 strip.clear();
 strip.fill(red, 0, LED_COUNT);
 strip.show();
 n = 1;
 input = "";
 delay (1000);
 strip.clear();
 strip.show();
 }
//----------------------------------Buttons------------------------------------------
 else {
 input += key;
 if (n == password.length() ) {
 strip.clear();
 strip.fill(blue, 0, LED_COUNT); 
 strip.show();
 n++;
 }
 else {

 strip.clear();
 strip.setPixelColor(n-1, blue);
 strip.show();
 n++;
 }
 }
 }

}</pre>
<h2>Function</h2>
<p>Operating the keypad lock is very intuitive. As soon as the first button is pressed, the right-hand LED lights up blue (7.0.1). When the second button is pressed, the middle LED turns blue (7.0.2). After the third button is pressed, the left-hand LED lights up blue (7.0.3). Finally, with the fourth button, all three LEDs light up blue (7.0.4). When these three LEDs light up blue, the user knows that the # button must be pressed.</p>
<p>If the # button is pressed, the password is checked. If the password is correct, all three LEDs light up green at the same time and the servomotor is activated (7.0.5). The green light remains on as long as the servomotor has not yet reached its end position (open). As soon as the servomotor reaches the end position (open), the LEDs change from green to orange (7.0.6). The orange color remains until the user presses the * button.</p>
<p>After pressing the * button, the LEDs change back to green (7.0.7) and remain in this color until the servomotor has reached the end position (closed). If this is the case, the LEDs go out and the keypad lock is ready for new entries.</p>
<p>However, if the password is incorrect after pressing the # button in step 7.0.4, all three LEDs light up red (7.0.8). The red light is also displayed if more than four buttons, apart from the # button, are pressed.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1654 zoooom" src="https://nerd-corner.com/wp-content/uploads/2024/12/7-0-1.jpg" alt="keypad lock step by step guide" width="2310" height="1329" srcset="https://nerd-corner.com/wp-content/uploads/2024/12/7-0-1.jpg 2317w, https://nerd-corner.com/wp-content/uploads/2024/12/7-0-1-300x173.jpg 300w, https://nerd-corner.com/wp-content/uploads/2024/12/7-0-1-1024x589.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2024/12/7-0-1-768x442.jpg 768w, https://nerd-corner.com/wp-content/uploads/2024/12/7-0-1-1536x884.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2024/12/7-0-1-2048x1178.jpg 2048w" sizes="auto, (max-width: 2310px) 100vw, 2310px" /></p>
<h2>Door mounting</h2>
<p>Of course, this variant is not intended for use on an ordinary door, where you simply walk through and the door closes by itself. The reason for this is that the lock remains open until the * button is pressed. But how can you press the * button when you are on the other side of the keypad lock, behind the wall? A delay in the program could help, but who knows how long it takes to pass through the door and close it behind you? A much more sensible solution would be to implement an additional switch that is placed on the other side of the door. When pressed, this switch would lead directly to point 7.0.6 and open the lock so that the door can be opened from the inside without having to enter a password.</p>
<p>But that&#8217;s for the future. Now we come to mounting the keypad lock on a door. I have provided four holes on the back of the housing for this purpose. These holes have a recess on the inside for conventional hexagon nuts M4 DIN 934. The corresponding holes can be seen in Figure 8.0.1 (rear view) and Figure 8.0.2 (front view), whereby the housing is shown slightly transparent for better visualization. Installing the nuts is very simple: After ensuring that all support material has been removed, the nut is pressed into the recess provided from behind. Press-in nuts should not be used as they are unnecessarily expensive.</p>
<p>I have developed a drilling template for fixing to the wall or door (Fig. 8.0.3). This template contains a hole with a diameter of 4 mm at each of the four corners. The distance between the holes corresponds to the distance between the holes on the housing. The template can be easily fixed to the surface of the door, for example with adhesive tape (Fig. 8.0.4). This saves you the tedious task of marking out the drill holes and avoids errors.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1653 zoooom" src="https://nerd-corner.com/wp-content/uploads/2024/12/8-0-1.jpg" alt="" width="2310" height="1330" srcset="https://nerd-corner.com/wp-content/uploads/2024/12/8-0-1.jpg 2316w, https://nerd-corner.com/wp-content/uploads/2024/12/8-0-1-300x173.jpg 300w, https://nerd-corner.com/wp-content/uploads/2024/12/8-0-1-1024x589.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2024/12/8-0-1-768x442.jpg 768w, https://nerd-corner.com/wp-content/uploads/2024/12/8-0-1-1536x884.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2024/12/8-0-1-2048x1179.jpg 2048w" sizes="auto, (max-width: 2310px) 100vw, 2310px" /></p>
<p>Figure 8.1.1 shows the drilled mounting holes from the front, marked by magenta-colored circles. Thanks to the drilling template, these holes are the correct distance apart. If the position slips slightly during drilling or is not exactly correct, this is not a problem. In this case, you can simply drill the mounting holes slightly larger to align the keypad lock precisely when screwing it on. In addition, two holes can be seen in yellow circles in this picture, which are unfortunately slightly broken out at the edge. These holes are intended for the servo cable and the power supply. Once the holes had been drilled, I fitted the keypad lock and fed the cables through the holes provided on the back of the door (Fig. 8.1.2).</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1652 zoooom" src="https://nerd-corner.com/wp-content/uploads/2024/12/8-1.jpg" alt="" width="2310" height="1330" srcset="https://nerd-corner.com/wp-content/uploads/2024/12/8-1.jpg 2316w, https://nerd-corner.com/wp-content/uploads/2024/12/8-1-300x173.jpg 300w, https://nerd-corner.com/wp-content/uploads/2024/12/8-1-1024x589.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2024/12/8-1-768x442.jpg 768w, https://nerd-corner.com/wp-content/uploads/2024/12/8-1-1536x884.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2024/12/8-1-2048x1179.jpg 2048w" sizes="auto, (max-width: 2310px) 100vw, 2310px" /></p>
<p>The entire assembly of the keypad lock is shown on the front side of the door in Image 8.2.1. If you are not satisfied with this mounting solution, don&#8217;t worry: As a final step, I have designed a back cover that allows the keypad lock to be mounted on a wall or frame (Image 8.2.2). To do this, simply place the housing of the keypad lock onto the back cover and secure it from behind using M4 countersunk screws (marked by magenta circles in Image 8.2.2). After that, the entire construction is mounted on the wall, for which two tabs with two holes each are available (yellow circles in Image 8.2.2).</p>
<p>It is also important to remember to add one or more openings in the housing for the servo and power supply cables. Additionally, the security risk should be considered, as an unauthorized person could potentially unscrew the keypad lock using the accessible screws.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1651 zoooom" src="https://nerd-corner.com/wp-content/uploads/2024/12/8-2.jpg" alt="" width="2310" height="1330" srcset="https://nerd-corner.com/wp-content/uploads/2024/12/8-2.jpg 2316w, https://nerd-corner.com/wp-content/uploads/2024/12/8-2-300x173.jpg 300w, https://nerd-corner.com/wp-content/uploads/2024/12/8-2-1024x589.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2024/12/8-2-768x442.jpg 768w, https://nerd-corner.com/wp-content/uploads/2024/12/8-2-1536x884.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2024/12/8-2-2048x1179.jpg 2048w" sizes="auto, (max-width: 2310px) 100vw, 2310px" /></p>
<h3>Locking Mechanism</h3>
<p>If you&#8217;re still missing a real locking mechanism that goes beyond just a servo connection, you can look forward to the &#8220;Locking Unit,&#8221; which is already in development and will be featured in future versions of the keypad lock.</p>
<p>The development of the keypad lock was an exciting yet challenging task. Some key features of <strong>VERSION 1</strong> of the keypad lock are particularly noteworthy:</p>
<ul>
<li><strong>Compatibility with various Arduino Nano models and adapters</strong> – Ensures flexibility in hardware selection.</li>
<li><strong>Visual feedback</strong> – Users are directly informed about number input and the status of the keypad lock.</li>
<li><strong>Emergency power supply via barrel jack</strong> – Guarantees reliable operation in case of power failures.</li>
<li><strong>Stable software</strong> – Developed to ensure reliable functionality.</li>
<li><strong>Optimized ergonomics for both left- and right-handed users</strong> – Designed for comfortable use by all users.</li>
</ul>
<h2>Files for Download</h2>
<ul>
<li><a href="https://www.thingiverse.com/thing:6840254">Keypad lock housing</a></li>
</ul>
<p>The post <a href="https://nerd-corner.com/diy-keypad-lock-3d-printing-and-code/">DIY keypad lock &#8211; 3D printing and code</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nerd-corner.com/diy-keypad-lock-3d-printing-and-code/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>WeMos D1 R2 &#8211; Host entire website with html, css &#038; js</title>
		<link>https://nerd-corner.com/wemos-d1-r2-host-entire-website-with-html-css-js/</link>
					<comments>https://nerd-corner.com/wemos-d1-r2-host-entire-website-with-html-css-js/#respond</comments>
		
		<dc:creator><![CDATA[Nerds]]></dc:creator>
		<pubDate>Wed, 06 Mar 2024 12:18:52 +0000</pubDate>
				<category><![CDATA[Arduino projects]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Arduino with Wifi]]></category>
		<category><![CDATA[C programming]]></category>
		<category><![CDATA[communication technique]]></category>
		<category><![CDATA[control Arduino with browser]]></category>
		<category><![CDATA[data transfer]]></category>
		<category><![CDATA[entire website]]></category>
		<category><![CDATA[ESP8266]]></category>
		<category><![CDATA[ESP8266 with mDNS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[led]]></category>
		<category><![CDATA[local network]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[Step by step guide]]></category>
		<category><![CDATA[Webserver]]></category>
		<category><![CDATA[website hosting]]></category>
		<category><![CDATA[WeMos]]></category>
		<category><![CDATA[WeMos D1]]></category>
		<category><![CDATA[WeMos D1 in Arduino IDE]]></category>
		<category><![CDATA[WeMos D1 mini]]></category>
		<category><![CDATA[WeMos D1 R2]]></category>
		<category><![CDATA[WeMOS D1 Webserver]]></category>
		<category><![CDATA[WIFI]]></category>
		<guid isPermaLink="false">https://nerd-corner.com/de/?p=1547</guid>

					<description><![CDATA[<p>The first part of the WeMos series explained the setup and Wi-Fi integration. Building on this, this article describes step by step how to host &#8230; </p>
<p>The post <a href="https://nerd-corner.com/wemos-d1-r2-host-entire-website-with-html-css-js/">WeMos D1 R2 &#8211; Host entire website with html, css &#038; js</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The first part of the WeMos series explained the setup and Wi-Fi integration. Building on this, this article describes step by step how to host a complete website with HTML pages, CSS styling and JavaScript functions on a WeMos. The whole thing is pretty simple and incredibly helpful! I can&#8217;t believe how hard it is to find proper instructions for this important function anywhere on the internet.</p>
<p>I often see blog articles where the HTML code is embedded in the Arduino file. You can do this for a mini demonstration, but it&#8217;s complete rubbish for everyday use. It is far too confusing and as soon as the project grows it is no longer usable.</p>
<p>The proper alternative is to set up a folder called &#8220;data&#8221; and store the web pages in this folder as html files. In addition, the styling is saved as a CSS file and functions can even be executed via a JavaScript file. So everything is 1:1 like on a normal web server!</p>
<p><em><strong>This might also be interesting for you:</strong> <a href="https://nerd-corner.com/wemos-d1-r2-setup-and-wifi-integration/">WeMos D1 R2 first steps and Wifi integration</a></em></p>
<h2>List of components</h2>
<ul>
<li>Arduino IDE (development environment)</li>
<li>WeMos D1 R2</li>
</ul>
<h2>The setup of the file system (officially SPIFFS) needs to be done once and is very easy:</h2>
<p><a href="https://nerd-corner.com/wemos-d1-r2-setup-and-wifi-integration/">(First you should have completed the basic setup from the first part!)</a></p>
<ol>
<li>Download a copy of the file &#8220;ESP8266FS-0.2.0.zip&#8221; from GitHub and unzip it</li>
<li>Place the file esp8266fs.jar in the Arduino tool directory. The path looks like this: [home_dir]\Arduino\tools\ESP8266FS\tool\esp8266fs.jar (See picture) I had to create the path part tools\ESP8266FS\tool\ in the Arduino folder myself.<img loading="lazy" decoding="async" class="zoooom aligncenter wp-image-1531" src="https://nerd-corner.com/wp-content/uploads/2024/03/Screenshot-file-path-esp8266fs.jar-.png" alt="Screenshot file path esp8266fs.jar" width="1080" height="335" srcset="https://nerd-corner.com/wp-content/uploads/2024/03/Screenshot-file-path-esp8266fs.jar-.png 1190w, https://nerd-corner.com/wp-content/uploads/2024/03/Screenshot-file-path-esp8266fs.jar--300x93.png 300w, https://nerd-corner.com/wp-content/uploads/2024/03/Screenshot-file-path-esp8266fs.jar--1024x318.png 1024w, https://nerd-corner.com/wp-content/uploads/2024/03/Screenshot-file-path-esp8266fs.jar--768x238.png 768w" sizes="auto, (max-width: 1080px) 100vw, 1080px" /></li>
<li>Restart the Arduino IDE.</li>
</ol>
<p>That&#8217;s it already! You can now see the new item &#8220;ESP8266 Sketch Data Upload&#8221; in the Arduino IDE under Tools.</p>
<h2>How can I use the new file system now?</h2>
<ol>
<li>Create an additional folder with the name &#8220;data&#8221; in your current WeMos project folder. As shown in the following image</li>
</ol>
<p><img loading="lazy" decoding="async" class="zoooom aligncenter wp-image-1528" src="https://nerd-corner.com/wp-content/uploads/2024/03/Wemos-data-folder.png" alt="Wemos data folder" width="1040" height="324" srcset="https://nerd-corner.com/wp-content/uploads/2024/03/Wemos-data-folder.png 1146w, https://nerd-corner.com/wp-content/uploads/2024/03/Wemos-data-folder-300x93.png 300w, https://nerd-corner.com/wp-content/uploads/2024/03/Wemos-data-folder-1024x319.png 1024w, https://nerd-corner.com/wp-content/uploads/2024/03/Wemos-data-folder-768x239.png 768w" sizes="auto, (max-width: 1040px) 100vw, 1040px" /></p>
<ol start="2">
<li>Place the files you want to upload in the &#8216;data&#8217; directory</li>
<li>In the Arduino IDE, select the WeMos in the &#8216;Tools&#8217; menu and select a size for &#8216;Flash Size&#8217;</li>
<li>Close the dialogue box for the serial monitor!</li>
<li>Select the &#8216;ESP8266 Sketch Data Upload&#8217; option from the &#8216;Tools&#8217; menu.</li>
</ol>
<p><img loading="lazy" decoding="async" class="zoooom aligncenter wp-image-1529" src="https://nerd-corner.com/wp-content/uploads/2024/03/data-folder-upload.png" alt="Data folder upload" width="805" height="518" srcset="https://nerd-corner.com/wp-content/uploads/2024/03/data-folder-upload.png 851w, https://nerd-corner.com/wp-content/uploads/2024/03/data-folder-upload-300x193.png 300w, https://nerd-corner.com/wp-content/uploads/2024/03/data-folder-upload-768x495.png 768w" sizes="auto, (max-width: 805px) 100vw, 805px" /></p>
<p>As soon as the upload is complete, the message window of the Arduino IDE shows 100% upload.</p>
<h2>WeMos example programme for switching the OnBoard LED on and off</h2>
<p>Similar to the first part, the web server will control the OnBoard LED. The code from the first part also serves as the basis. The revised code looks like this:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="atomic" data-enlighter-title="D1_webserver_filesystem">#include &lt;ESP8266WiFi.h&gt;
#include &lt;ESP8266WebServer.h&gt;
#include &lt;ESP8266mDNS.h&gt;

ESP8266WebServer server(80);

void setup() {
  Serial.begin(115200); //Baudrate
  Serial.println("ESP starts");

  WiFi.begin("NerdCornerWiFi","NerdCornerPassword");


  Serial.print("Connecting...");

  while(WiFi.status()!=WL_CONNECTED){ //Loop which makes a point every 500ms until the connection process has finished

    delay(500);
    Serial.print(".");
  }
  Serial.println();

  Serial.print("Connected! IP-Address: ");
  Serial.println(WiFi.localIP()); //Displaying the IP Address

  if (MDNS.begin("nerd-corner")) {
    Serial.println("DNS started, available with: ");
    Serial.println("http://nerd-corner.local/");
  }

  server.serveStatic("/", SPIFFS, "/", "max-age=86400");
  SPIFFS.begin();

  server.onNotFound([](){ 
    server.send(404, "text/plain", "Landing page not found! Don't forget to name your landing page 'index.html'!");  
  });
 
  server.on("/led", HTTP_POST, []() {    
     
    const String ledState = server.arg("ledstate");
    if(ledState=="on"){
      switchLedOn();
    }
    else if(ledState=="off"){
      switchLedOff();
    }
    server.send(200, "text/json", "{\"result\":\"ok\"}");
  });

  server.begin();
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  server.handleClient();
  MDNS.update();

}

void switchLedOff(){ 
  digitalWrite(LED_BUILTIN, HIGH);   // turn the D1 LED off 
}

void switchLedOn(){ 
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED on 
}</pre>
<p>I would like to point out a few special features. For example, we have added the following:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="atomic">server.serveStatic("/", SPIFFS, "/", "max-age=86400"); 
SPIFFS.begin();</pre>
<p>Without these two lines, access to the files in the &#8220;data&#8221; folder would not be possible. Please note that the name &#8220;index.html&#8221; is set as the default for the landing page. However, you can change this if you really want to.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="atomic">server.on("/led", HTTP_POST, []() {    
     
    const String ledState = server.arg("ledstate");
    if(ledState=="on"){
      switchLedOn();
    }
    else if(ledState=="off"){
      switchLedOff();
      }
      server.send(200, "text/json", "{\"result\":\"ok\"}");
  });</pre>
<p>The &#8220;/led&#8221; endpoint receives the commands from the web server. If the command is &#8220;on&#8221;, the LED is switched on and if &#8220;off&#8221;, the LED is switched off.</p>
<h2>Wemos website for switching the WeMos OnBoard LED on and off</h2>
<p>The example website has a very simple structure. It primarily consists of 2 buttons for switching the LED on and off.</p>
<p><img loading="lazy" decoding="async" class="zoooom aligncenter wp-image-1536" src="https://nerd-corner.com/wp-content/uploads/2024/03/Webseite-Wemos-Control.jpeg" alt="Website Wemos control LED" width="875" height="1946" srcset="https://nerd-corner.com/wp-content/uploads/2024/03/Webseite-Wemos-Control.jpeg 921w, https://nerd-corner.com/wp-content/uploads/2024/03/Webseite-Wemos-Control-135x300.jpeg 135w, https://nerd-corner.com/wp-content/uploads/2024/03/Webseite-Wemos-Control-461x1024.jpeg 461w, https://nerd-corner.com/wp-content/uploads/2024/03/Webseite-Wemos-Control-768x1708.jpeg 768w, https://nerd-corner.com/wp-content/uploads/2024/03/Webseite-Wemos-Control-691x1536.jpeg 691w" sizes="auto, (max-width: 875px) 100vw, 875px" /></p>
<p>The folder structure of the website is very clearly organised. There is a main page with the name &#8220;index.html&#8221;. This name is common worldwide for the main pages and is also automatically recognised by WeMos. There is also a &#8220;CSS&#8221; folder for styling and a &#8220;JS&#8221; folder for functions.</p>
<p><img loading="lazy" decoding="async" class="zoooom aligncenter wp-image-1537" src="https://nerd-corner.com/wp-content/uploads/2024/03/Screenshot-data-file-system.png" alt="Screenshot esp8266 data file system" width="1045" height="347" srcset="https://nerd-corner.com/wp-content/uploads/2024/03/Screenshot-data-file-system.png 1152w, https://nerd-corner.com/wp-content/uploads/2024/03/Screenshot-data-file-system-300x100.png 300w, https://nerd-corner.com/wp-content/uploads/2024/03/Screenshot-data-file-system-1024x340.png 1024w, https://nerd-corner.com/wp-content/uploads/2024/03/Screenshot-data-file-system-768x255.png 768w" sizes="auto, (max-width: 1045px) 100vw, 1045px" /></p>
<p>We link the styles in the header area of the website. There is a standard bootstrap, which automatically makes everything a bit nicer, and a custom styles file with my own customisations. The functions of the website are also linked in the header area. I use the jQuery standard to send requests from the website to the WeMos. My own custom functions are in the &#8220;index.js&#8221;.</p>
<p>Please note that the jQuery file must be included BEFORE your own file, otherwise no jQuery commands can be used in your own code! The custom functions are then used by the buttons. The HTML code of the page looks as follows:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="html" data-enlighter-theme="atomic">&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;&lt;/html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;meta charset="utf-8" /&gt;
    &lt;meta
      name="viewport"
      content="width=device-width, initial-scale=1, shrink-to-fit=no"
    /&gt;
    &lt;script type="text/javascript" src="js/jquery-3.5.1.min.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript" src="./js/index.js"&gt;&lt;/script&gt;
    &lt;link rel="stylesheet" href="css/bootstrap.min.css" /&gt;
    &lt;link rel="stylesheet" href="css/custom-style.css" /&gt;
    &lt;title&gt;D1 Webserver&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;h1&gt;D1 Webserver with filesystem&lt;/h1&gt;
    &lt;p&gt;
      This is an example for a WeMos Webserver with a filesystem. You can easily
      create webpages with html, css and js!
    &lt;/p&gt;

    &lt;h3&gt;Example to turn on and off the built in LED&lt;/h3&gt;
    &lt;button class="button-style" onclick="changeLEDState('on')"&gt;Turn on&lt;/button&gt;
    &lt;button class="button-style" onclick="changeLEDState('off')"&gt;
      Turn off
    &lt;/button&gt;

    &lt;h3&gt;Example to demo a JS function&lt;/h3&gt;
    &lt;button class="button-style" onclick="showAlert()"&gt;Show alert&lt;/button&gt;
  &lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Special attention is paid to the JavaScript function &#8220;changeLEDState(value)&#8221;</p>
<pre class="EnlighterJSRAW" data-enlighter-language="js" data-enlighter-theme="atomic">function changeLEDState(value) {
  $.post("/led", { ledstate: value });
}</pre>
<p>Because jQuery is used for communication with the WeMos, a simple dollar sign with the corresponding request command is sufficient. A value is also sent with this POST request, which is either &#8220;on&#8221; or &#8220;off&#8221; to switch the LED on and off.</p>
<p>The web page can be downloaded as a zip file below.</p>
<h2>Files to download</h2>
<ul>
<li><a  data-e-Disable-Page-Transition="true" class="download-link" title="" href="https://nerd-corner.com/download/1540/?tmstv=1756257505" rel="nofollow" id="download-link-1540" data-redirect="false" >
	Wemos example webserver to control OnBoard LED</a>
</li>
</ul>
<p>The post <a href="https://nerd-corner.com/wemos-d1-r2-host-entire-website-with-html-css-js/">WeMos D1 R2 &#8211; Host entire website with html, css &#038; js</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nerd-corner.com/wemos-d1-r2-host-entire-website-with-html-css-js/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>WeMos D1 R2 setup and wifi integration</title>
		<link>https://nerd-corner.com/wemos-d1-r2-setup-and-wifi-integration/</link>
					<comments>https://nerd-corner.com/wemos-d1-r2-setup-and-wifi-integration/#comments</comments>
		
		<dc:creator><![CDATA[Nerds]]></dc:creator>
		<pubDate>Sun, 06 Mar 2022 10:36:53 +0000</pubDate>
				<category><![CDATA[Arduino projects]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Arduino with Wifi]]></category>
		<category><![CDATA[C programming]]></category>
		<category><![CDATA[control Arduino with browser]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[data transfer]]></category>
		<category><![CDATA[ESP 8266]]></category>
		<category><![CDATA[ESP8266]]></category>
		<category><![CDATA[ESP8266 with mDNS]]></category>
		<category><![CDATA[mDNS]]></category>
		<category><![CDATA[Step by step guide]]></category>
		<category><![CDATA[Webserver]]></category>
		<category><![CDATA[WeMos]]></category>
		<category><![CDATA[WeMos D1]]></category>
		<category><![CDATA[WeMos D1 in Arduino IDE]]></category>
		<category><![CDATA[WeMos D1 mDNS]]></category>
		<category><![CDATA[WeMos D1 mini]]></category>
		<category><![CDATA[WeMos D1 Pinout]]></category>
		<category><![CDATA[WeMos D1 R2]]></category>
		<category><![CDATA[WeMos D1 setup]]></category>
		<category><![CDATA[WeMOS D1 Webserver]]></category>
		<category><![CDATA[WIFI]]></category>
		<category><![CDATA[Wifi Modul]]></category>
		<category><![CDATA[WLAN]]></category>
		<guid isPermaLink="false">https://nerd-corner.com/de/?p=1184</guid>

					<description><![CDATA[<p>I have often thought that it would be extremely convenient to connect my Arduino projects with the Wi-Fi. At some point I randomly came across &#8230; </p>
<p>The post <a href="https://nerd-corner.com/wemos-d1-r2-setup-and-wifi-integration/">WeMos D1 R2 setup and wifi integration</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I have often thought that it would be extremely convenient to connect my Arduino projects with the Wi-Fi. At some point I randomly came across the WeMos D1 R2 and I am thrilled! In principle, every Arduino project can be realized with the D1 and you always have the possibility to use Wi-Fi. Probably the D1 will even displace the Arduino from the market in the future. In the following I explain the differences between an Arduino UNO R3 and a WeMos D1. Afterwards I describe the setup of the D1 with a simple example. In the example, a browser is used to control an LED, which is built-in on the D1.</p>
<p><em><strong>This might also be interesting for you: </strong><a href="https://nerd-corner.com/arduino-fan-controller/">How to control a fan with an Arduino!</a></em></p>
<h2>List of components</h2>
<ul>
<li>Arduino IDE (development environment)</li>
<li>WeMos D1 R2</li>
</ul>
<h2>Differences between the WeMos D1 R2 and the Arduino UNO R3</h2>
<p>An Arduino UNO R3 looks very similar to the WeMos D1. The main difference is that the D1 has an ESP2866 WIFI module integrated on its board. This gives you the possibility to connect the D1 to the internet. Roughly speaking, the D1 is a wifi-enabled Arduino!</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1175 zoooom" src="https://nerd-corner.com/wp-content/uploads/2022/01/Wemos-D1-und-Arduino-Uno-scaled.jpg" alt="Wemos D1 and Arduino Uno" width="2000" height="900" srcset="https://nerd-corner.com/wp-content/uploads/2022/01/Wemos-D1-und-Arduino-Uno-scaled.jpg 2560w, https://nerd-corner.com/wp-content/uploads/2022/01/Wemos-D1-und-Arduino-Uno-300x135.jpg 300w, https://nerd-corner.com/wp-content/uploads/2022/01/Wemos-D1-und-Arduino-Uno-1024x461.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2022/01/Wemos-D1-und-Arduino-Uno-768x346.jpg 768w, https://nerd-corner.com/wp-content/uploads/2022/01/Wemos-D1-und-Arduino-Uno-1536x691.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2022/01/Wemos-D1-und-Arduino-Uno-2048x922.jpg 2048w" sizes="auto, (max-width: 2000px) 100vw, 2000px" /></p>
<p>However, you should note that the clock frequencies of the two processors are different. The Arduino has an 8 bit Atmel processor and the D1 a Wi-Fi capable ESP8266 processor with 32 bit clock frequency. The pins of the D1 are arranged similarly to an Arduino UNO, but differ in the operating voltage. On an Arduino UNO the voltage of the pins is 5V and on the D1 it is 3.3V. However, there is also a 5V output on the D1. Because of the voltage differences on the pins you should not blindly plug an Arduino Shield on a D1. It is recommended to check the compatibility first!</p>
<p><img loading="lazy" decoding="async" class="zoooom aligncenter wp-image-1166" src="https://nerd-corner.com/wp-content/uploads/2022/01/Pinout_D1_R2.png" alt="Pinout WeMos D1 R2 Pinbelegung" width="770" height="888" srcset="https://nerd-corner.com/wp-content/uploads/2022/01/Pinout_D1_R2.png 783w, https://nerd-corner.com/wp-content/uploads/2022/01/Pinout_D1_R2-260x300.png 260w, https://nerd-corner.com/wp-content/uploads/2022/01/Pinout_D1_R2-768x886.png 768w" sizes="auto, (max-width: 770px) 100vw, 770px" /></p>
<p>In addition, it should be noted that the D1, unlike the Arduino, has only one analog pin and additionally the number of digital pins is different. The Arduino has 20 digital pins and the D1 only 16 digital pins. However, the digital pins of the D1 have more useful additional functions.</p>
<p>Please note: The designation of the D1 digital pins is also different from those of the Arduino and therefore must be adjusted in software.</p>
<p>Last but not least, the USB connector is also different. In contrast to the Arduino, the D1 has the much more common Micro USB standard.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1176 zoooom" src="https://nerd-corner.com/wp-content/uploads/2022/01/Wemos-D1-vs-Arduino-Uno-scaled.jpg" alt="Wemos D1 R2 vs Arduino Uno" width="2000" height="1500" srcset="https://nerd-corner.com/wp-content/uploads/2022/01/Wemos-D1-vs-Arduino-Uno-scaled.jpg 2560w, https://nerd-corner.com/wp-content/uploads/2022/01/Wemos-D1-vs-Arduino-Uno-300x225.jpg 300w, https://nerd-corner.com/wp-content/uploads/2022/01/Wemos-D1-vs-Arduino-Uno-1024x768.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2022/01/Wemos-D1-vs-Arduino-Uno-768x576.jpg 768w, https://nerd-corner.com/wp-content/uploads/2022/01/Wemos-D1-vs-Arduino-Uno-1536x1152.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2022/01/Wemos-D1-vs-Arduino-Uno-2048x1536.jpg 2048w" sizes="auto, (max-width: 2000px) 100vw, 2000px" /></p>
<h2>Setup of the D1</h2>
<p>Open the Arduino IDE and connect the D1 to the computer. Select the appropriate COM port of the D1 under Tools &gt; Port. If the D1 is not recognized here, this is probably due to a missing driver.</p>
<p>If you now select the appropriate COM port and upload an example sketch to the D1 you will probably get the following error message: &#8220;An error occurred while uploading the sketch avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x2e&#8221;. The reason for this error is that the wrong board was selected. The name of the selected board appears in the lower right corner of the IDE:</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1167 zoooom" src="https://nerd-corner.com/wp-content/uploads/2022/01/WEMOS-choosen-in-IDE.png" alt="WeMos D1 com Port IDE" width="1300" height="55" srcset="https://nerd-corner.com/wp-content/uploads/2022/01/WEMOS-choosen-in-IDE.png 1308w, https://nerd-corner.com/wp-content/uploads/2022/01/WEMOS-choosen-in-IDE-300x13.png 300w, https://nerd-corner.com/wp-content/uploads/2022/01/WEMOS-choosen-in-IDE-1024x43.png 1024w, https://nerd-corner.com/wp-content/uploads/2022/01/WEMOS-choosen-in-IDE-768x32.png 768w" sizes="auto, (max-width: 1300px) 100vw, 1300px" /></p>
<p>To be able to select the D1 the board manager for the ESP8266 must be added. Insert the following link in Preferences &gt; Board Manager: http://arduino.esp8266.com/stable/package_esp8266com_index.json</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1168 zoooom" src="https://nerd-corner.com/wp-content/uploads/2022/01/preferences-board-manager.png" alt="Preferences boardmananger WeMos D1 R2" width="910" height="703" srcset="https://nerd-corner.com/wp-content/uploads/2022/01/preferences-board-manager.png 921w, https://nerd-corner.com/wp-content/uploads/2022/01/preferences-board-manager-300x232.png 300w, https://nerd-corner.com/wp-content/uploads/2022/01/preferences-board-manager-768x593.png 768w" sizes="auto, (max-width: 910px) 100vw, 910px" /></p>
<p>Then search for ESP8266 in Tools &gt; Board &gt; Board Manager and install the latest version:</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1169 zoooom" src="https://nerd-corner.com/wp-content/uploads/2022/01/Esp8266-in-boardsmanager.png" alt="WeMos D1 R2 ESP8266 boardmananger in Arduino IDE" width="1200" height="692" srcset="https://nerd-corner.com/wp-content/uploads/2022/01/Esp8266-in-boardsmanager.png 1213w, https://nerd-corner.com/wp-content/uploads/2022/01/Esp8266-in-boardsmanager-300x173.png 300w, https://nerd-corner.com/wp-content/uploads/2022/01/Esp8266-in-boardsmanager-1024x590.png 1024w, https://nerd-corner.com/wp-content/uploads/2022/01/Esp8266-in-boardsmanager-768x443.png 768w" sizes="auto, (max-width: 1200px) 100vw, 1200px" /></p>
<p>Now select in Tools &gt; Board &gt; ESP8266 Boards &gt; LOLIN (WEMOS D1 R2 &amp;mini):</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1170 zoooom" src="https://nerd-corner.com/wp-content/uploads/2022/01/Choose-ESP8266-board.png" alt="choose WeMos D1 board in Arduino IDE" width="1900" height="999" srcset="https://nerd-corner.com/wp-content/uploads/2022/01/Choose-ESP8266-board.png 1920w, https://nerd-corner.com/wp-content/uploads/2022/01/Choose-ESP8266-board-300x158.png 300w, https://nerd-corner.com/wp-content/uploads/2022/01/Choose-ESP8266-board-1024x539.png 1024w, https://nerd-corner.com/wp-content/uploads/2022/01/Choose-ESP8266-board-768x404.png 768w, https://nerd-corner.com/wp-content/uploads/2022/01/Choose-ESP8266-board-1536x808.png 1536w" sizes="auto, (max-width: 1900px) 100vw, 1900px" /></p>
<p>Now you can select an example project under File &gt; Examples &gt; 01.Basics &gt; Blink and with a click on Upload the whole thing works. The example project now lets the blue LED on the ESP8266 module blink.</p>
<p>Attention: This setup was unique for the first time usage and does not need to be repeated again!</p>
<h2>Connecting WeMos D1 to the Internet</h2>
<p>The program structure corresponds to that of a regular microcontroller as known from the Arduino. There is a setup() function, which is called only once directly at the start of the program and a loop() function, which runs in a continuous loop after the setup().</p>
<p>First the ESP WiFi library is needed. This is included with #include &lt;ESP8266WiFi.h&gt;. As soon as the ESP is powered, a Wi-Fi connection should be established. Therefore the code is written into the setup() function.</p>
<p>We need the serial monitor to display the current state of the connection. The baudrate can be set by the user. For the D1 I use 115200. The serial monitor can be found under Tools &gt; Serial Monitor. In the window of the serial monitor you can set the baudrate. Please select 115200 as well. If you don&#8217;t choose the same baudrate as defined in setup(), you will only see unreadable special characters.</p>
<p>To connect to the Wi-Fi the simple command WiFi.beginn(&#8220;WlanName&#8221;, &#8220;WlanPasswort&#8221;) is sufficient. It can be very helpful to display the IP address of the D1. For this purpose use the command WiFi.localIP()</p>
<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="atomic">#include &lt;ESP8266WiFi.h&gt;

void setup() {
  Serial.begin(115200); //Baudrate
  Serial.println("ESP starts");

  WiFi.begin("NerdCornerWiFi","NerdCornerPassword");

  Serial.print("Connecting...");

  while(WiFi.status()!=WL_CONNECTED){ //Loop which makes a point every 500ms until the connection process has finished

    delay(500);
    Serial.print(".");
  }
  Serial.println();

  Serial.print("Connected! IP-Address: ");
  Serial.println(WiFi.localIP()); //Displaying the IP Address

}

void loop() {
  // put your main code here, to run repeatedly:

}</pre>
<h2>The D1 as web server and DNS server</h2>
<p>After the previous steps the D1 is connected to the WiFi, but not yet accessible via a browser. So that the D1 can be controlled comfortably over the Browser one needs the #include &lt;ESP8266WebServer.h&gt; library. Then create a web server object with the command ESP8266WebServer server(80) and set the port 80. The server can now be started with the command server.begin(). So that the D1 can check at any time whether requests are to be processed, the server.handleClient() is written into the loop() function.</p>
<p>If you now enter the IP address of the D1 in a browser, from a device that is in the same WiFi, the D1 is already accessible. It is just not specified yet what should happen when the D1 is called.</p>
<p>You can also display predefined functions here. Initially, for example, a sentence if the link has not been defined, or a text for a custom link. It is also possible to execute own functions for certain links.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="atomic">server.onNotFound([](){ 
  server.send(404, "text/plain", "Link was not found!");  
});
 
server.on("/", []() {
  server.send(200, "text/plain", "Landing page!");
});
 
server.on("/custom", []() {
  server.send(200, "text/plain", "Just a custom route!");
  ownFunction();
});</pre>
<p>The web server setup is now complete. Since it is usually very annoying to type the IP address of the D1 into the browser or it can change, it makes sense to assign a name to the DNS of the D1. For this again a library is used, which is included by #include &lt;ESP8266mDNS.h&gt;. The DNS is defined once and therefore written into the setup() function. To define the DNS name, use the method MDNS.begin(DNS Name), for example MDNS.begin(nerd-corner). Additionally MDNS.update() must be written into the loop function.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="atomic">#include &lt;ESP8266WiFi.h&gt;
#include &lt;ESP8266WebServer.h&gt;
#include &lt;ESP8266mDNS.h&gt;

ESP8266WebServer server(80);

void setup() {
  Serial.begin(115200); //Baudrate
  Serial.println("ESP starts");

  WiFi.begin("NerdCornerWiFi","NerdCornerPassword");

  Serial.print("Connecting...");

  while(WiFi.status()!=WL_CONNECTED){ //Loop which makes a point every 500ms until the connection process has finished

    delay(500);
    Serial.print(".");
  }
  Serial.println();

  Serial.print("Connected! IP-Address: ");
  Serial.println(WiFi.localIP()); //Displaying the IP Address

  if (MDNS.begin("nerd-corner")) {
    Serial.println("DNS started, available with: ");
    Serial.println("http://nerd-corner.local/");
  }

  server.onNotFound([](){ 
    server.send(404, "text/plain", "Link was not found!");  
  });
 
  server.on("/", []() {
    server.send(200, "text/plain", "Landing page!");
  });
 
  server.on("/custom", []() {
    server.send(200, "text/plain", "Just a custom route!");
    ownFunction();
  });

  server.begin();

}

void loop() {
  server.handleClient();
  MDNS.update();

}

void ownFunction(){ //go to "IP-Adress/custom" to call this function
  Serial.println("Own function was called");

}</pre>
<p>Afterwards you can enter http://nerd-corner.local in the browser and you will reach the D1. Please note that the ending must always be &#8220;.local&#8221;! Some Android devices do not support mDNS, then the actual IP address must still be specified. Now you can use it for your own projects!</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1171 zoooom" src="https://nerd-corner.com/wp-content/uploads/2022/01/custom-route-D1.png" alt="WeMos D1 R2 testing custom route functions" width="1240" height="737" srcset="https://nerd-corner.com/wp-content/uploads/2022/01/custom-route-D1.png 1249w, https://nerd-corner.com/wp-content/uploads/2022/01/custom-route-D1-300x178.png 300w, https://nerd-corner.com/wp-content/uploads/2022/01/custom-route-D1-1024x608.png 1024w, https://nerd-corner.com/wp-content/uploads/2022/01/custom-route-D1-768x456.png 768w, https://nerd-corner.com/wp-content/uploads/2022/01/custom-route-D1-890x530.png 890w, https://nerd-corner.com/wp-content/uploads/2022/01/custom-route-D1-445x265.png 445w" sizes="auto, (max-width: 1240px) 100vw, 1240px" /></p>
<h2>Example program to switch the OnBoard LED on and off</h2>
<p>At the end of this blogpost we have a simple example program where we apply what we have learned so far. We write two additional functions. One to switch on the built-in LED and one to switch it off. A small hint, in contrast to the Arduino the LED is switched on with digitalWrite(LED_BUILTIN, LOW) instead of switched off, so exactly inverted!</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1177 zoooom" src="https://nerd-corner.com/wp-content/uploads/2022/01/Wemos-D1-R2-build-in-LED-scaled.jpg" alt="Wemos D1 R2 blinking LED" width="2000" height="900" srcset="https://nerd-corner.com/wp-content/uploads/2022/01/Wemos-D1-R2-build-in-LED-scaled.jpg 2560w, https://nerd-corner.com/wp-content/uploads/2022/01/Wemos-D1-R2-build-in-LED-300x135.jpg 300w, https://nerd-corner.com/wp-content/uploads/2022/01/Wemos-D1-R2-build-in-LED-1024x461.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2022/01/Wemos-D1-R2-build-in-LED-768x346.jpg 768w, https://nerd-corner.com/wp-content/uploads/2022/01/Wemos-D1-R2-build-in-LED-1536x691.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2022/01/Wemos-D1-R2-build-in-LED-2048x922.jpg 2048w" sizes="auto, (max-width: 2000px) 100vw, 2000px" /></p>
<p>The functions can be called via http://nerd-corner.local/on and http://nerd-corner.local/off. Here is the complete program code:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="atomic">#include &lt;ESP8266WiFi.h&gt;
#include &lt;ESP8266WebServer.h&gt;
#include &lt;ESP8266mDNS.h&gt;

ESP8266WebServer server(80);

void setup() {
  Serial.begin(115200); //Baudrate
  Serial.println("ESP starts");

  WiFi.begin("NerdCornerWiFi","NerdCornerPassword");

  Serial.print("Connecting...");

  while(WiFi.status()!=WL_CONNECTED){ //Loop which makes a point every 500ms until the connection process has finished

    delay(500);
    Serial.print(".");
  }
  Serial.println();

  Serial.print("Connected! IP-Address: ");
  Serial.println(WiFi.localIP()); //Displaying the IP Address

  if (MDNS.begin("nerd-corner")) {
    Serial.println("DNS started, available with: ");
    Serial.println("http://nerd-corner.local/");
  }

  server.onNotFound([](){ 
    server.send(404, "text/plain", "Link was not found!");  
  });
 
  server.on("/", []() {
    server.send(200, "text/plain", "Landing page!");
  });
 
  server.on("/on", []() {
    server.send(200, "text/plain", "Switching LED on!");
    switchLedOn();
  });

  server.on("/off", []() {
    server.send(200, "text/plain", "Switching LED off!");
    switchLedOff();
  });

  server.begin();


  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  server.handleClient();
  MDNS.update();

}

void switchLedOff(){ 
  digitalWrite(LED_BUILTIN, HIGH);   // turn the D1 LED off 
}

void switchLedOn(){ 
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED on 
}</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>The post <a href="https://nerd-corner.com/wemos-d1-r2-setup-and-wifi-integration/">WeMos D1 R2 setup and wifi integration</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nerd-corner.com/wemos-d1-r2-setup-and-wifi-integration/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Review Battery Shield V3 &#8211; DIY Powerbank with LiPo 18650</title>
		<link>https://nerd-corner.com/review-battery-shield-v3-diy-powerbank-with-lipo-18650/</link>
					<comments>https://nerd-corner.com/review-battery-shield-v3-diy-powerbank-with-lipo-18650/#comments</comments>
		
		<dc:creator><![CDATA[Nerds]]></dc:creator>
		<pubDate>Mon, 26 Jul 2021 19:00:46 +0000</pubDate>
				<category><![CDATA[Arduino projects]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[18650]]></category>
		<category><![CDATA[Akku]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Battery management system]]></category>
		<category><![CDATA[Battery shield V3]]></category>
		<category><![CDATA[DIY Powerbank]]></category>
		<category><![CDATA[Power Managment]]></category>
		<category><![CDATA[Powerbank]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[USB]]></category>
		<guid isPermaLink="false">https://nerd-corner.com/de/?p=1044</guid>

					<description><![CDATA[<p>I was looking for a battery with a battery management system for my outdoor projects (weather station, irrigation system, etc.).  While browsing online stores, I &#8230; </p>
<p>The post <a href="https://nerd-corner.com/review-battery-shield-v3-diy-powerbank-with-lipo-18650/">Review Battery Shield V3 &#8211; DIY Powerbank with LiPo 18650</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I was looking for a battery with a battery management system for my outdoor projects (weather station, irrigation system, etc.).  While browsing online stores, I came across a cheap module for the power supply of my outdoor projects. Normally several components are necessary for an independent power supply (LiPo charger, battery holder, step down, step up, solar panel). However, the &#8220;Battery Shield V3&#8221; takes over most of these tasks. For my use cases (Ardunio + sensors) the provided 5V and 3V outputs are ideal! Here is my review of the Battery Shield V3.</p>
<p><em><strong>This might also be interesting for you:</strong> <a href="https://nerd-corner.com/step-down-modul-dc-dc-lm2596s/" target="_blank" rel="noopener">Development of a step-down module</a></em></p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1019" src="https://nerd-corner.com/wp-content/uploads/2021/07/both.jpg" alt="Battery shield v3" width="940" height="534" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/both.jpg 952w, https://nerd-corner.com/wp-content/uploads/2021/07/both-300x170.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/07/both-768x436.jpg 768w" sizes="auto, (max-width: 940px) 100vw, 940px" /></p>
<h2>List of components:</h2>
<ul>
<li>1x Battery Shield V3</li>
<li>1x LiPo 18650</li>
</ul>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1023" src="https://nerd-corner.com/wp-content/uploads/2021/07/PowerbankPur.gif" alt="DIY Powerbank LiPo mit BMS" width="345" height="176" /></p>
<h2>Analysis of the Battery Shield V3</h2>
<p>After the Battery Shield V3 arrived, the first thing I had to do was examine its properties in detail.  I thought about the tests beforehand and they were primarily based on my use cases. Since I am of course not a research institute, I kept the tests as simple as possible.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1025" src="https://nerd-corner.com/wp-content/uploads/2021/07/Test1-scaled.jpg" alt="Battery shield v3 test lipo akku bms" width="2550" height="1436" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/Test1-scaled.jpg 2560w, https://nerd-corner.com/wp-content/uploads/2021/07/Test1-300x169.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/07/Test1-1024x577.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/07/Test1-768x432.jpg 768w, https://nerd-corner.com/wp-content/uploads/2021/07/Test1-1536x865.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2021/07/Test1-2048x1153.jpg 2048w" sizes="auto, (max-width: 2550px) 100vw, 2550px" /></p>
<p>First, I tested the main function, which is charging a LiPo battery. The charging process on the module is indicated by a LED. Red means that the battery is charging and green signifies that charging is complete. Unfortunately, the LEDs are located on the bottom of the module and are therefore not easily visible.</p>
<p>According to the information provided by the manufacturer or the online retailer, the charging voltage is 4.2 V and the charging current is 500 mA. To verify these values, I measured and noted the state of charge of the inserted battery. The state of charge was approximately at 1100 mAh. The total capacity of the battery is 3000 mAh. It appears that the difference between fully charged and partially charged is 1900 mAh. To get the expected charging time, this value is divided by the 500 mA specified by the manufacturer. The calculated charging time is therefore 4 h. A standard power supply with 5V and 1A charging current is used as the power supply. In reality, the duration of charging was 4 h and 15 min. This is close to the theoretical value and thus okay.</p>
<p><strong>Please note:</strong> Never use a brand new LiPo battery for this test, instead use one that already has some charge cycles completed. Otherwise, the result is not very meaningful.</p>
<h3>Voltage testing in the Review Baterry Shield V3</h3>
<p>In the second test, the different voltages provided by the module were examined. I divided this test into two phases. In the first phase (picture test 2_1) the module is used without a LiPo battery. Afterwards in the second phase a LiPo battery is used.</p>
<p>Of course, it is important to choose the right components to make the test as realistic as possible. For the USB-A connection I selected a load resistor with 1 A as well as with 2 A. This ceramic load resistor is ideal because a USB interface is available and the LED lights up green when 5 watts are consumed. At 10 watts the LED lights red.</p>
<p>For the 3 x 5 V outputs, I soldered 5V LED strips to two outputs and the third 5V output has a step-down module LM2596S which I constructed and set to 2V to power a 10 mm RGB Led. 3 V LEDs were soldered to each of the 3 x 3 V outputs. For this test a 5 V (18 Watt) power supply was used.</p>
<h4>The module operating without LiPo battery</h4>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1028 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/07/TEST2_1.jpg" alt="Review: Battery Shield V3" width="1675" height="1017" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/TEST2_1.jpg 1682w, https://nerd-corner.com/wp-content/uploads/2021/07/TEST2_1-300x182.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/07/TEST2_1-1024x622.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/07/TEST2_1-768x466.jpg 768w, https://nerd-corner.com/wp-content/uploads/2021/07/TEST2_1-1536x932.jpg 1536w" sizes="auto, (max-width: 1675px) 100vw, 1675px" /></p>
<p>After connecting the consumers and the power supply, not much happened. Only the module-internal LED lit up red. Only when I deactivated the ceramic load resistor one of the 5 V LED strips and the RGB diode connected to the step-down (marked yellow in picture Test2_1) lit up.</p>
<p>Subsequent measurement of the outputs revealed the following values: A voltage of 3.24 V was measured for the 5 V outputs and 2.28 V for the 3 V outputs. The total current supply of the module without the LiPo battery inserted is about 11 mA. This should be sufficient for a small LED.</p>
<h4>The module with LiPo battery</h4>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1029 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/07/Test2_2.jpg" alt="Review: Battery Shield V3" width="1640" height="996" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/Test2_2.jpg 1654w, https://nerd-corner.com/wp-content/uploads/2021/07/Test2_2-300x182.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/07/Test2_2-1024x622.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/07/Test2_2-768x467.jpg 768w, https://nerd-corner.com/wp-content/uploads/2021/07/Test2_2-1536x933.jpg 1536w" sizes="auto, (max-width: 1640px) 100vw, 1640px" /></p>
<p>For phase 2 all consumers were removed and a LiPo battery (SAMSUNG INR18650-35E SDI KL59) was inserted into the module. As shown in the pictures, connectors were attached. This is because this module does not have a switch for the LiPo battery, so the load is immediately applied to the LiPo battery. It is simply uncomfortable to insert or plug in a battery under load.</p>
<p>All loads are in full mode in phase 2 and work fine. In addition, even the LiPo battery is charged. Questionable are the 4A amperage specifications of the 5V outputs. Given the amp numbers of the LiPo battery, this is possible, but it seems very high for a USB Micro supply. My recommendation would be to use the module with less than 4 amps.</p>
<h4>Deep discharge protection</h4>
<p>The third and last test is rather trivial. To test the deep discharge protection, only the ceramic load resistor with 5 watts was activated and no power supply was connected. This discharged the LiPo battery and if the deep discharge protection of the module terminates the discharge process on its own, the test was successful. This was the case. There was enough remaining capacity. However, such stress situations for the LiPo battery should still be avoided.</p>
<h2>Casing for the Battery Shield V3</h2>
<p><img loading="lazy" decoding="async" class="zoooom aligncenter wp-image-1031" src="https://nerd-corner.com/wp-content/uploads/2021/07/Wlc.jpg" alt="Review Battery Shield V3" width="1250" height="426" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/Wlc.jpg 1253w, https://nerd-corner.com/wp-content/uploads/2021/07/Wlc-300x102.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/07/Wlc-1024x349.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/07/Wlc-768x262.jpg 768w" sizes="auto, (max-width: 1250px) 100vw, 1250px" /></p>
<p>Of course I couldn&#8217;t resist to build a case for the Battery Shield V3 module. Beside the normal 5V USB output, which can be switched on and off by an extra switch, I also constructed a constant 3V output with a 5,5 x 2,1 socket into the case.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1032 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/07/Top-1.jpg" alt="Review Battery Shiled V3" width="1160" height="370" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/Top-1.jpg 1173w, https://nerd-corner.com/wp-content/uploads/2021/07/Top-1-300x96.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/07/Top-1-1024x326.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/07/Top-1-768x245.jpg 768w" sizes="auto, (max-width: 1160px) 100vw, 1160px" /></p>
<p>The housing can be downloaded in STL format at the end of the blog post.</p>
<p><img loading="lazy" decoding="async" class="zoooom aligncenter wp-image-1033" src="https://nerd-corner.com/wp-content/uploads/2021/07/PowerbankPurKpl.jpg" alt="Review DIY Powerbank" width="1500" height="681" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/PowerbankPurKpl.jpg 2166w, https://nerd-corner.com/wp-content/uploads/2021/07/PowerbankPurKpl-300x136.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/07/PowerbankPurKpl-1024x465.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/07/PowerbankPurKpl-768x349.jpg 768w, https://nerd-corner.com/wp-content/uploads/2021/07/PowerbankPurKpl-1536x698.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2021/07/PowerbankPurKpl-2048x930.jpg 2048w" sizes="auto, (max-width: 1500px) 100vw, 1500px" /></p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1051 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/07/Abm.jpg" alt="CAD plan with size for the battery shield v3" width="1500" height="925" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/Abm.jpg 1678w, https://nerd-corner.com/wp-content/uploads/2021/07/Abm-300x185.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/07/Abm-1024x632.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/07/Abm-768x474.jpg 768w, https://nerd-corner.com/wp-content/uploads/2021/07/Abm-1536x947.jpg 1536w" sizes="auto, (max-width: 1500px) 100vw, 1500px" /></p>
<h2>Minor disadvantages</h2>
<p>The On/OFF switch only switches the USB port. The 3 x 3 V and 3 x 5 V solder pins cannot be switched on and off by this switch.</p>
<p>For my electronic projects this disadvantage is not really dramatic, because I use mostly the USB port. Besides, additional switches can be soldered to the soldering points.</p>
<h2>Downloading files:</h2>
<ul>
<li><a  data-e-Disable-Page-Transition="true" class="download-link" title="" href="https://nerd-corner.com/download/1039/?tmstv=1756257505" rel="nofollow" id="download-link-1039" data-redirect="false" >
	Datenblatt Battery Shield V3 (von AZ Delivery)</a>
</li>
<li><a href="https://www.thingiverse.com/thing:4917764" target="_blank" rel="noopener">STL Files for the housing</a></li>
</ul>
<p>The post <a href="https://nerd-corner.com/review-battery-shield-v3-diy-powerbank-with-lipo-18650/">Review Battery Shield V3 &#8211; DIY Powerbank with LiPo 18650</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nerd-corner.com/review-battery-shield-v3-diy-powerbank-with-lipo-18650/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Sending text messages with visible light communication or LiFi &#8211; Pi to Arduino</title>
		<link>https://nerd-corner.com/sending-text-messages-with-visible-light-communication/</link>
					<comments>https://nerd-corner.com/sending-text-messages-with-visible-light-communication/#comments</comments>
		
		<dc:creator><![CDATA[Nerds]]></dc:creator>
		<pubDate>Sun, 20 Jun 2021 23:31:03 +0000</pubDate>
				<category><![CDATA[Arduino projects]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[cyclic redundancy check]]></category>
		<category><![CDATA[data transfer]]></category>
		<category><![CDATA[data transfer with light]]></category>
		<category><![CDATA[LiFi]]></category>
		<category><![CDATA[LiFi Arduino project]]></category>
		<category><![CDATA[LiFI Router]]></category>
		<category><![CDATA[Light Fidelity]]></category>
		<category><![CDATA[text messages]]></category>
		<category><![CDATA[text messages from Pi to Arduino]]></category>
		<category><![CDATA[visible Light communication]]></category>
		<category><![CDATA[visible light communication project]]></category>
		<category><![CDATA[VLC]]></category>
		<category><![CDATA[VLC Arduino project]]></category>
		<category><![CDATA[VLC Raspberry Pi project]]></category>
		<guid isPermaLink="false">https://nerd-corner.com/de/?p=962</guid>

					<description><![CDATA[<p>I like the idea of sending data via visible light. In general, Li-Fi (Light Fidelity) and VLC (Visible Light Communication) are heavily discussed at the &#8230; </p>
<p>The post <a href="https://nerd-corner.com/sending-text-messages-with-visible-light-communication/">Sending text messages with visible light communication or LiFi &#8211; Pi to Arduino</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I like the idea of sending data via visible light. In general, Li-Fi (Light Fidelity) and VLC (Visible Light Communication) are heavily discussed at the moment. VLC is a visible light communication, which means it is primarily a cable replacement, while LiFi is a similarity to WiFi. A LiFi device would be a kind of Internet-enabled router that transmits data via light signals instead of radio frequency signals. Currently, however, no company has developed or is selling a Li-Fi router. VLC technology is used prominently at the moment by Elon Musk&#8217;s StarLink project. This allows satellites to exchange data using laser beams. I have replicated that in a simplified way in this blog article.</p>
<p>At first, I only want to transmit individual text messages in one direction. In a next step this can then be extended to transmit whole files bidirectionally. To receive the messages, I chose an Ardunio, because unlike the Raspberry Pi, it has analog inputs and can thus be easily connected to analog sensors. For sending, a Raspberry Pi is suitable, since only digital pins are needed here and a Pi can generally transmit data more efficiently and faster. This has already been tested in the previous posts about defining a clock frequency for the Arduino and the Raspberry Pi. All scripts to run the VLC communication can be downloaded at the end of the article. The following three blogposts are directly related to this project:</p>
<p><span style="color: #ff0000;"><strong>===&gt; UPGRADE: </strong></span><em><a href="https://nerd-corner.com/upgrade-data-transfer-via-vlc-and-lifi-pi-to-pi-transfer/" target="_blank" rel="noopener">SENDING ALL KINDS OF DATA WITH VISIBLE LIGHT COMMUNICATION</a></em></p>
<p><em><strong>How to program the clock frequency of the Arduino:</strong> <a href="https://nerd-corner.com/arduino-timer-interrupts-how-to-program-arduino-registers/">Use timer interrupts as clock frequency.</a></em></p>
<p><em><strong>How to program the clock frequency of the Pi:</strong> <a href="https://nerd-corner.com/how-to-program-a-highly-precise-timer-in-c-for-linux/">Precise timer function in C for the Pi.</a></em></p>
<p><em><strong>How to prevent errors in data transmission:</strong> <a href="https://nerd-corner.com/cyclic-redundancy-check-in-c-code/">Using CRC to detect corrupted packets.</a></em></p>
<h2>List of components</h2>
<ul>
<li>Arduino Uno</li>
<li>Raspberry Pi</li>
<li>5V Solarcell</li>
<li>5V Laserdiode</li>
<li>Jumper cables</li>
</ul>
<h2>Wiring for the visible light communication</h2>
<p><img loading="lazy" decoding="async" class="zoooom aligncenter wp-image-939" src="https://nerd-corner.com/wp-content/uploads/2021/06/FritzingPi_Arduino.png" alt="Textnachrichten VLC Fritzing Verkabelung für Visuelle Lichtkommunikation" width="2770" height="1130" srcset="https://nerd-corner.com/wp-content/uploads/2021/06/FritzingPi_Arduino.png 2772w, https://nerd-corner.com/wp-content/uploads/2021/06/FritzingPi_Arduino-300x122.png 300w, https://nerd-corner.com/wp-content/uploads/2021/06/FritzingPi_Arduino-1024x418.png 1024w, https://nerd-corner.com/wp-content/uploads/2021/06/FritzingPi_Arduino-768x313.png 768w, https://nerd-corner.com/wp-content/uploads/2021/06/FritzingPi_Arduino-1536x627.png 1536w, https://nerd-corner.com/wp-content/uploads/2021/06/FritzingPi_Arduino-2048x836.png 2048w" sizes="auto, (max-width: 2770px) 100vw, 2770px" /></p>
<p>The wiring is rather simple. The 5V solar cell is very well suited to detect light signals. Therefore the solar cell is connected to the receiver, which is the Arduino. The ground of the solar cell is connected to a ground of the Arduino. The positive line of the solar cell is connected to an analog pin of the Arduino. Here, for example, A0 is suitable.</p>
<p>From the Raspberry Pi the messages are transmitted to the Arduino via light signals of the laser. For this, the ground of a 5V laser diode is connected to a ground pin of the Pi (see graphic). Then the positive line of the laser diode is connected to one of the digital pins of the Raspberry Pi. Here I chose the GPIO17 pin, which corresponds to pin 0 in the &#8220;wiringPi&#8221; library (see graphic).</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-940 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/06/pinbelegung-Pi.png" alt="VLC Textnachrichten visuelle Lichtkommunikation wiringPi" width="598" height="294" srcset="https://nerd-corner.com/wp-content/uploads/2021/06/pinbelegung-Pi.png 600w, https://nerd-corner.com/wp-content/uploads/2021/06/pinbelegung-Pi-300x148.png 300w" sizes="auto, (max-width: 598px) 100vw, 598px" /></p>
<p>As an alternative to the laser and the solar cell combination, an LED and a photoresistor can also be used. However, a laser is better suited for faster and more precise data transmission. In addition, a solar cell offers a large area to detect the laser beams.</p>
<h2>Modulationtechnique On-Off-Keying</h2>
<p>The text messages are transmitted in binary code as &#8220;1&#8221; or &#8220;0&#8221;. There are different ways to modulate this data. One of the simplest possibilities is to set an identical clock frequency for the transmitter and receiver. Then either a &#8220;1&#8221; or a &#8220;0&#8221; is transmitted in each clock pulse.</p>
<p>The procedure is called aplitude shift keying. If the laser diode illuminates the solar plate particularly strongly, this is detected by the receiver as a binary &#8220;1&#8221;. If the laser diode shines only weakly, it will be detected as binary &#8220;0&#8221;.</p>
<p>In fact it makes sense not to let the laser diode shine at all for a binary &#8220;0&#8221;. This is called On-Off keying. This is a simplification of amplitude shift keying. The following graphic illustrates the difference between amplitude shift keying and on-off keying.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-942 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/06/OOK-ASK-1.jpg" alt="Modulationstechnik Visuelle Lichtkommunikation" width="848" height="587" srcset="https://nerd-corner.com/wp-content/uploads/2021/06/OOK-ASK-1.jpg 850w, https://nerd-corner.com/wp-content/uploads/2021/06/OOK-ASK-1-300x208.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/06/OOK-ASK-1-768x531.jpg 768w" sizes="auto, (max-width: 848px) 100vw, 848px" /></p>
<p>That means, whenever the solar cell detects light, a corresponding voltage value is passed to the analog pin of the Arduino. If this voltage value exceeds a predefined value, the Arduino registers it as a binary &#8220;1&#8221;, otherwise as a binary &#8220;0&#8221;. It makes sense to adjust the predefined value to the daylight. Possibly with the help of an additional light sensor.</p>
<h2>Arduino code to receive messages</h2>
<pre class="EnlighterJSRAW" data-enlighter-language="c" data-enlighter-group="Receiver" data-enlighter-title="Receiver.ino" data-enlighter-theme="beyond">//This is the "real" loop function
  switch (state)
  {
    case 0:
      //looking for synchronization sequence
      synchro_Done=false;
      lookForSynchro(data);

      if (synchro_Done== true)
      {
        state=1;
      }
      break;
    case 1:
      //receive Data
      receiveData_Done =false;
      receiveData(data);

      if (receiveData_Done==true)
      {
        state=0; 
      }
      break;
  }</pre>
<p>The software of the Arduino is basically built as a state machine. There are two states. One state for synchronization and one for reading the text message. In the state synchronization the receiver waits for a fixed bit sequence (preamble) for example &#8220;101010101111111111&#8221;. This sequence means that the receiver must listen now because a text message follows. The complete Arduino code can be downloaded at the end of the article. The following graphic shows the exact structure of the data packets.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-943 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/06/FrameVariableDataLength.jpg" alt="Aufbau Textnachrichten VLC" width="953" height="554" srcset="https://nerd-corner.com/wp-content/uploads/2021/06/FrameVariableDataLength.jpg 955w, https://nerd-corner.com/wp-content/uploads/2021/06/FrameVariableDataLength-300x174.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/06/FrameVariableDataLength-768x446.jpg 768w" sizes="auto, (max-width: 953px) 100vw, 953px" /></p>
<p>As soon as the preamble is recognized, the receiver automatically switches to the second state and receives the actual message. However, the first 16 bits of the text message correspond to a decimal number, which tells the receiver how many characters the incoming text message contains. When this number is reached, the text is printed in the Serial Monitor of the Arduino and the state changes back again. Now the synchronization sequence is awaited again. The complete software code can be downloaded at the end of the blog article. To improve the transmission quality, a cyclic redundancy check (CRC) can be performed as shown in the following graphic.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-944 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/06/FrameVariableDataLengthAndCRC.jpg" alt="CRC Datenpakete Aufbau VLC" width="1264" height="555" srcset="https://nerd-corner.com/wp-content/uploads/2021/06/FrameVariableDataLengthAndCRC.jpg 1266w, https://nerd-corner.com/wp-content/uploads/2021/06/FrameVariableDataLengthAndCRC-300x132.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/06/FrameVariableDataLengthAndCRC-1024x450.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/06/FrameVariableDataLengthAndCRC-768x337.jpg 768w" sizes="auto, (max-width: 1264px) 100vw, 1264px" /></p>
<h2>Raspberry Pi code to send messages</h2>
<pre class="EnlighterJSRAW" data-enlighter-language="c" data-enlighter-group="simpleLaser" data-enlighter-title="simpleLaser.c">//Read message
        char msg[3000]; 
        int len, k, length;
       
        printf("n Enter the Message: ");
        scanf("%[^'n']",msg);
        
        len=strlen(msg);
        
        
        int2bin(len*8, 16); //len*8, because 8 bits are one byte
        
        for(k=0;k&lt;len;k++)
        {
                chartobin(msg[k]);            
        }</pre>
<p>The program code of the Raspberry Pi must be written in C. Python would be too slow and would not achieve a stable clock frequency for sending the data. The complete program code can be downloaded at the end of the article. In order for the Pi to control the laser diode the &#8220;wiringPi.h&#8221; library is needed. With &#8220;digitalWrite(0, HIGH)&#8221; the diode can be switched on and with &#8220;digitalWrite(0, LOW)&#8221; it can be switched off. Important: Please don&#8217;t forget the &#8220;<a href="http://wiringpi.com/" target="_blank" rel="noopener">wiringPi</a>&#8221; library when compiling! The command is: &#8220;gcc -o simpleLaser simpleLaser.c -lwiringPi&#8221;.</p>
<p>At the beginning the program asks for a text message using the printf function. This is read in and stored by a scanf function. Then each letter is converted to binary code and stored in an array. The conversion is shown in the following graphic. At the end, the binary code is transmitted from the array in a fixed clock pulse. The laser diode is switched on for a binary &#8220;1&#8221; and off again for a binary &#8220;0&#8221;.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-945 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/06/BinToDec.jpg" alt="Character to binary conversion" width="750" height="389" srcset="https://nerd-corner.com/wp-content/uploads/2021/06/BinToDec.jpg 758w, https://nerd-corner.com/wp-content/uploads/2021/06/BinToDec-300x156.jpg 300w" sizes="auto, (max-width: 750px) 100vw, 750px" /></p>
<h2>Conclusion on the Visible Light Communication for Arduino</h2>
<p>The transmission of text messages by means of visual light communication works excellently. Thanks to the cyclic redundancy check, it is also absolutely error-free. However, the benefit of one-dimensional message communication is rather low. It would be better if any kind of files could be transmitted and that in both directions. An update will probably follow soon.</p>
<p><img loading="lazy" decoding="async" class="zoooom aligncenter wp-image-953" src="https://nerd-corner.com/wp-content/uploads/2021/06/SetUp-Arduino-Pi-scaled.jpg" alt="Set Up VLC Arduino Pi Visuelle Lichtkommunikation" width="2550" height="1913" srcset="https://nerd-corner.com/wp-content/uploads/2021/06/SetUp-Arduino-Pi-scaled.jpg 2560w, https://nerd-corner.com/wp-content/uploads/2021/06/SetUp-Arduino-Pi-300x225.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/06/SetUp-Arduino-Pi-1024x768.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/06/SetUp-Arduino-Pi-768x576.jpg 768w, https://nerd-corner.com/wp-content/uploads/2021/06/SetUp-Arduino-Pi-1536x1152.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2021/06/SetUp-Arduino-Pi-2048x1536.jpg 2048w" sizes="auto, (max-width: 2550px) 100vw, 2550px" /></p>
<h2>Download files</h2>
<ul>
<li><a  data-e-Disable-Page-Transition="true" class="download-link" title="" href="https://nerd-corner.com/download/946/?tmstv=1756257505" rel="nofollow" id="download-link-946" data-redirect="false" >
	Arduino Code VLC to receive text messages</a>
</li>
<li><a  data-e-Disable-Page-Transition="true" class="download-link" title="" href="https://nerd-corner.com/download/949/?tmstv=1756257505" rel="nofollow" id="download-link-949" data-redirect="false" >
	Raspberry Pi code to send text messages with VLC</a>
</li>
</ul>
<p>&nbsp;</p>
<p>The post <a href="https://nerd-corner.com/sending-text-messages-with-visible-light-communication/">Sending text messages with visible light communication or LiFi &#8211; Pi to Arduino</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nerd-corner.com/sending-text-messages-with-visible-light-communication/feed/</wfw:commentRss>
			<slash:comments>10</slash:comments>
		
		
			</item>
		<item>
		<title>Arduino Timer Interrupts – How to program Arduino registers</title>
		<link>https://nerd-corner.com/arduino-timer-interrupts-how-to-program-arduino-registers/</link>
					<comments>https://nerd-corner.com/arduino-timer-interrupts-how-to-program-arduino-registers/#comments</comments>
		
		<dc:creator><![CDATA[Nerds]]></dc:creator>
		<pubDate>Thu, 26 Nov 2020 21:30:19 +0000</pubDate>
				<category><![CDATA[Arduino projects]]></category>
		<category><![CDATA[Arduino Uno]]></category>
		<category><![CDATA[clock]]></category>
		<category><![CDATA[delay()]]></category>
		<category><![CDATA[Interrupts]]></category>
		<category><![CDATA[Millis()]]></category>
		<category><![CDATA[OCR1A]]></category>
		<category><![CDATA[precise]]></category>
		<category><![CDATA[registers]]></category>
		<category><![CDATA[Timer]]></category>
		<category><![CDATA[Timer Interrupts]]></category>
		<category><![CDATA[Timer1]]></category>
		<guid isPermaLink="false">https://nerd-corner.com/?p=781</guid>

					<description><![CDATA[<p>If you want to achieve a regular time interval with the Arduino you can simply use the delay() function. This will pause the program of &#8230; </p>
<p>The post <a href="https://nerd-corner.com/arduino-timer-interrupts-how-to-program-arduino-registers/">Arduino Timer Interrupts – How to program Arduino registers</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>If you want to achieve a regular time interval with the Arduino you can simply use the delay() function. This will pause the program of the Arduino for the appropriate amount of time. If the requirements are higher you can also use millis() or nanos() as timer. The delay() and millis() functions are probably sufficient for most applications, but if you don&#8217;t want to pause the whole program or achieve a 100% exact clock time it makes sense to use Arduino Timer Interrupts. We explain what timer interrupts are and how to use them. You can find the Arduino code at the end of the post.</p>
<p><em><strong>This might also be interesting for you:</strong> <a href="https://nerd-corner.com/android-bluetooth-classic-app-for-arduino-fan-control/" target="_blank" rel="noopener noreferrer">How to control an Arduino via Bluetooth</a></em></p>
<h2>List of components</h2>
<ul>
<li>Arduino Uno</li>
<li>LED</li>
<li>220 Ohm resistor</li>
<li>Wires</li>
<li>Breadboard</li>
</ul>
<h2>What is a timer actually?</h2>
<p>A timer is basically nothing else than a certain register in the microcontroller, which is increased (or decreased) continuously by 1 under hardware control. Instead of coding instructions in the program that are executed regularly and increment a register by 1, the microcontroller does this all by itself!</p>
<p>This becomes useful, if an action is executed at certain counter values. One of these &#8216;certain counts&#8217; is for example the overflow. The count register of a timer can not be incremented arbitrarily long. E.g. the highest count that an 8-bit-timer can reach is 2^8 &#8211; 1 = 255. The next incrementing step is not 256, instead an overflow occurs, which makes the timer become 0 again. This is the magic! We can configure the controller so that an interrupt is triggered when the timer overflow occurs. We can write code in the Arduino program what should happen in case of an interrupt. For example, we can make an LED light up or query a certain sensor value.</p>
<h2>Arduino Uno Microcontroller ATMEGA328P</h2>
<p><img loading="lazy" decoding="async" class="alignright wp-image-784 size-medium zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/11/ATMEGA328P-300x274.jpg" alt="Microcontroller ATMEGA328P Nerd Corner Arduino Uno Timer Interrupts" width="300" height="274" srcset="https://nerd-corner.com/wp-content/uploads/2020/11/ATMEGA328P-300x274.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/11/ATMEGA328P.jpg 466w" sizes="auto, (max-width: 300px) 100vw, 300px" />The ATMEGA328P microcontroller is the heart of the Arduino Uno board. (ATTENTION: The Arduino Mega e.g. has a different microcontroller!) The ATMEGA328P microcontroller has 3 timers (<a href="https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf">datasheet</a>) which are partly used in Arduino functions and/or partly in libraries. Overwriting the timer registers can therefore lead to complications with existing timer functions like millis(), micros() or delay() and should be used with caution. The 3 timers are Timer0 (8Bit), Timer1 (16Bit) and Timer2 (8Bit).</p>
<ul>
<li>8 Bit-Timer0: used for functions millis(), micros(), delay() and for PWM at pin D5 and D6</li>
<li>16 Bit Timer1: Use e.g. for the Servo, VirtualWire and TimerOne library and for PWM at pin D9 and D10</li>
<li>8 Bit Timer2: Used for function tone() and for PWM at pin D3 and D11</li>
</ul>
<h2>How to vary the clock speed?</h2>
<p>The system clock of the Arduino Uno is 16 MHz (CPU frequency). This means Timer0, Timer1 and Timer2 increase 16 million times per second. For example, the 8 bit timers count from 0 to 255 each time. At 256 an overflow occurs and the timers start again from 0. This means 16000000/256 = 62500 overflows per second (62.5kHz clock rate). This is likely too fast for most timer applications!</p>
<p>Therefore there is a trick to slow down the clock rates. You use a so-called prescaler. A prescaler can be set to the values 1, 8, 64, 256 or 1024. It allows you to divide the system clock (16MHz) by the selected factor and set a lower clock rate for the timers. For example, a prescaler of 1024 would increase the timer registers by 1 only at the 1024th system clock pulse. This would be 16000000/1024=15625 increments per second and thus with an 8 bit timer 15625/256= 61.035 overflows per second (~61 Hz clock rate of the timer).</p>
<h2>Practical example LED should light up with 50Hz</h2>
<p>In the following, the triggering of Arduino Timer Interrupts is shown with the 16-bit timer1. With this a LED should light up in a 50 Hz cycle. Schematic, Arduino code and pictures are also included. (The procedure for the 8 bit timer0 and timer2 is analog.) For the time controlled pulse you need the so called &#8220;CTC Mode&#8221;.</p>
<p>In CTC mode (&#8220;Clear Timer on Compare Mode&#8221;) the counter is cleared when the value of the counter (TNCT1) matches either the value of the OCR1A register or the value of the ICR1 register (in our case OCR1A). So the OCR1A register determines the maximum value of the counter and thus its resolution.</p>
<h3>The 16 Bit Timer1 needs the following registers</h3>
<ul>
<li>Timer Counter Register 1: TCNT1</li>
<li>Output Compare Register A: OCR1A</li>
<li>Timer Counter Control Register A: TCCR1A</li>
<li>Timer Counter Control Register B: TCCR1B</li>
<li>Timer/Counter Interrupt Mask Register: TIMSK1</li>
<li>(For Timer0 and Timer2 the corresponding registers would be TCNT0 and TCNT2, respectively)</li>
</ul>
<h3>Calculate the OCR1A register for Arduino Timer Interrupts</h3>
<p>The value of the OCR1A register depends on the desired interrupt frequency and the selected prescaler. The following formula applies:</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-783 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/11/InterruptFrequency.jpg" alt="Formula for Arduino Timer Interrupt Frequency calculation OCR1A register" width="691" height="156" srcset="https://nerd-corner.com/wp-content/uploads/2020/11/InterruptFrequency.jpg 692w, https://nerd-corner.com/wp-content/uploads/2020/11/InterruptFrequency-300x68.jpg 300w" sizes="auto, (max-width: 691px) 100vw, 691px" /></p>
<p>We put our specifications into the formula:</p>
<ul>
<li>CPU frequency Arduino Uno: 16.000.000 Hz</li>
<li>Desired interrupt frequency: 50 Hz (= 20 ms period duration)</li>
<li>Possible prescaler: 1, 8, 64, 256 or 1024</li>
</ul>
<p><strong>Calculation example with Prescaler 1024:</strong><br />
OCR1A= (16.000.000 / (1024 * 50)) &#8211; 1 = 311,5</p>
<p><strong>Calculation example with Prescaler 8:</strong><br />
OCR1A= (16,000,000 / (8 * 50)) &#8211; 1 = 39,999</p>
<p><strong>ATTENTION:</strong> The OCR1A value must be less than 65.536 (2^16 )!</p>
<p><strong>Therefore a prescaler 8 can NOT reach 10Hz interrupt frequency:</strong><br />
OCR1A= (16.000.000 / (8 * 10)) &#8211; 1 = 199.999</p>
<p>The value 199.999 is larger than the register with 65.536, therefore another prescaler must be used to reach 10 Hz</p>
<p><strong>Instead a prescaler 64 for 10 Hz interrupt frequency:</strong><br />
OCR1A= (16.000.000 / (64 * 10)) &#8211; 1 = 24.999</p>
<p><em>If a Timer1 interrupt is now triggered, the program flow jumps to an interrupt service routine to be created &#8220;ISR(TIMER1_COMPA_vect)&#8221;. (See Arduino Code)</em></p>
<h3>Bit combination for the desired prescaler</h3>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-785 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/11/TimerInterrupts.jpg" alt="Arduino Uno timer interrupts Prescaler " width="1121" height="413" srcset="https://nerd-corner.com/wp-content/uploads/2020/11/TimerInterrupts.jpg 1122w, https://nerd-corner.com/wp-content/uploads/2020/11/TimerInterrupts-300x110.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/11/TimerInterrupts-1024x377.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/11/TimerInterrupts-768x283.jpg 768w" sizes="auto, (max-width: 1121px) 100vw, 1121px" /></p>
<h3>Arduino Timer Interrupts code for 50 Hz frequency</h3>
<pre class="EnlighterJSRAW" data-enlighter-language="c">void setup() {

  pinMode(11,OUTPUT);  //LED pin (to blink in 50Hz frequency)
  
//START TIMER SETUP
//TIMER SETUP for highly preceise timed measurements 

  cli();//stop all interrupts

  // turn on CTC mode
  TCCR1A = 0;// set entire TCCR1A register to 0
  TCCR1B = 0;// same for TCCR1B
  TCCR1B |= (1 &lt;&lt; WGM12);

  // Set CS11 bit for prescaler 8
  TCCR1B |= (1 &lt;&lt; CS11); 
  
  //initialize counter value to 0;
  TCNT1  = 0;
  
  // set timer count for 50Hz increments
  OCR1A = 39999;// = (16*10^6) / (50*8) - 1  
  
  // enable timer compare interrupt
  TIMSK1 |= (1 &lt;&lt; OCIE1A);
  
  sei();//allow interrupts
  //END TIMER SETUP
}



ISR(TIMER1_COMPA_vect) {//Interrupt at frequency of 50 Hz
 //write your timer code here

 digitalWrite(11,HIGH);
 delay(15);
 digitalWrite(11,LOW);
}




void loop() {

//when the timer is over, your program will stop in the loop function and jump to the timer code. 
//After the timer code it will jump back to the point where it left the loop function
}</pre>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-786 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/11/TimerInterruptLED.jpg" alt="Arduino Timer Interrupt LED sketch" width="1649" height="839" srcset="https://nerd-corner.com/wp-content/uploads/2020/11/TimerInterruptLED.jpg 1650w, https://nerd-corner.com/wp-content/uploads/2020/11/TimerInterruptLED-300x153.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/11/TimerInterruptLED-1024x521.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/11/TimerInterruptLED-768x391.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/11/TimerInterruptLED-1536x782.jpg 1536w" sizes="auto, (max-width: 1649px) 100vw, 1649px" /></p>
<p>The post <a href="https://nerd-corner.com/arduino-timer-interrupts-how-to-program-arduino-registers/">Arduino Timer Interrupts – How to program Arduino registers</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nerd-corner.com/arduino-timer-interrupts-how-to-program-arduino-registers/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
		<item>
		<title>Hall Sensor Movement Detection</title>
		<link>https://nerd-corner.com/hall-sensor-movement-detection/</link>
					<comments>https://nerd-corner.com/hall-sensor-movement-detection/#comments</comments>
		
		<dc:creator><![CDATA[Nerds]]></dc:creator>
		<pubDate>Wed, 12 Aug 2020 14:51:16 +0000</pubDate>
				<category><![CDATA[Arduino projects]]></category>
		<category><![CDATA[Handcrafted]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Arduino Code]]></category>
		<category><![CDATA[arduino nano]]></category>
		<category><![CDATA[hall effect]]></category>
		<category><![CDATA[hall sensor]]></category>
		<category><![CDATA[hallsensor]]></category>
		<category><![CDATA[KY-024]]></category>
		<category><![CDATA[KY024]]></category>
		<category><![CDATA[led]]></category>
		<category><![CDATA[leds]]></category>
		<category><![CDATA[movement detection]]></category>
		<category><![CDATA[rotary]]></category>
		<category><![CDATA[rotary movement]]></category>
		<guid isPermaLink="false">https://nerd-corner.com/?p=695</guid>

					<description><![CDATA[<p>We built a test bench to detect a rotary movement. We call it the Hall Sensor Movement Detection. The necessary parts were 3D printed. You &#8230; </p>
<p>The post <a href="https://nerd-corner.com/hall-sensor-movement-detection/">Hall Sensor Movement Detection</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>We built a test bench to detect a rotary movement. We call it the Hall Sensor Movement Detection. The necessary parts were 3D printed. You find the 3d parts at the end of this parts in the &#8220;Download files&#8221; section. The aim of the Hall sensor detection wheel is to detect a rotation and to keep the LEDs continuously lightning during the rotation. We need this set-up for our project to build a prayer wheel, because we are going to use the Arduino code here for the prayer wheel.</p>
<p><strong><em>This might also be interesting for you: </em></strong><a href="https://nerd-corner.com/hallsensor-ky-024-arduino-code/" target="_blank" rel="noopener noreferrer"><em>Simple guide on how to use a Hall Sensor with an Arduino</em></a></p>
<h2>List of components</h2>
<ul>
<li>Arduino Nano</li>
<li>Nano Terminal Adapter</li>
<li>6 magnets</li>
<li>Hall sensor KY024</li>
<li>LED strip</li>
<li>Jumper cables</li>
<li>Screws 2x M2 and 1x M3 for the sensor</li>
<li>Deep groove ball bearing 6807 2RS / 61807 2RS 35x47x7 mm</li>
<li>3D printing test setup (STL files in Download section)</li>
</ul>
<h2>Construction of test bench</h2>
<div style="width: 1200px;" class="wp-video"><!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->
<video class="wp-video-shortcode" id="video-695-1" width="1200" height="675" preload="metadata" controls="controls"><source type="video/mp4" src="https://nerd-corner.com/wp-content/uploads/2020/08/MagneranimationA.mp4?_=1" /><a href="https://nerd-corner.com/wp-content/uploads/2020/08/MagneranimationA.mp4">https://nerd-corner.com/wp-content/uploads/2020/08/MagneranimationA.mp4</a></video></div>
<p>First we glued the 6 magnets into the 3D printed wheel. Make sure that the magnets are aligned homogeneously. Then the deep groove ball bearing is inserted into the detection wheel. The wheel can now be connected to the 3D printed bracket. Next we attach the Hall sensor KY-024 to the bracket. The Arduino Nano is plugged onto the adapter terminal and also attached to the bracket. The LED strip does not have to be attached separately. So you can start with the wiring.</p>
<h2>Wiring</h2>
<p>The wiring is not very difficult. Proceed according to the <a href="https://fritzing.org/" target="_blank" rel="nofollow noopener noreferrer">fritzing</a> sketch. Connect the 4 jumper cables to the pins of the Hall sensor KY-024 and connect them to the Arduino Terminal Adapter. The 5V output of the Arduino is shared with both the Hall Sensor and the LEDs. Since there are only a few LEDs, no external power supply is required. For the LED strip you may have to solder them. We recommend to use a 220 Ohm resistor for the digital input of the LED strip.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-696 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/08/Hall-Sensor-Detektionsrad-Fritzing.png" alt="Hall Sensor movement detection wheel wiring fritzing hall effect" width="3071" height="1611" srcset="https://nerd-corner.com/wp-content/uploads/2020/08/Hall-Sensor-Detektionsrad-Fritzing.png 3072w, https://nerd-corner.com/wp-content/uploads/2020/08/Hall-Sensor-Detektionsrad-Fritzing-300x157.png 300w, https://nerd-corner.com/wp-content/uploads/2020/08/Hall-Sensor-Detektionsrad-Fritzing-1024x537.png 1024w, https://nerd-corner.com/wp-content/uploads/2020/08/Hall-Sensor-Detektionsrad-Fritzing-768x403.png 768w, https://nerd-corner.com/wp-content/uploads/2020/08/Hall-Sensor-Detektionsrad-Fritzing-1536x806.png 1536w, https://nerd-corner.com/wp-content/uploads/2020/08/Hall-Sensor-Detektionsrad-Fritzing-2048x1075.png 2048w" sizes="auto, (max-width: 3071px) 100vw, 3071px" /></p>
<h2>Arduino Code Simple (with digital input)</h2>
<p>In this code example, the Hall sensor KY024 sends the digital value 1 (HIGH) if there is a magnet or 0 (LOW) if no magnet is nearby. As soon as a HIGH is detected, the LEDs start to light up. But if the a magnet stops in front of the Hall sensor, it will send a HIGH constantly and the LEDs won&#8217;t stop lightning.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c" data-enlighter-theme="beyond" data-enlighter-title="HallSensorDetectionWheelSimple.ino" data-enlighter-group="HallSensorDetectionWheelSimple">#include &lt;FastLED.h&gt;
#define LED_PIN     7
#define NUM_LEDS    6

CRGB leds[NUM_LEDS];

int digitalPin = 9; // Hall magnetic sensor input 1 (high) or 0 (low)
int digitalInputValue ; // digital readings

void setup ()
{
  FastLED.addLeds&lt;WS2812, LED_PIN, GRB&gt;(leds, NUM_LEDS);
  pinMode (digitalPin, INPUT); 
  
  Serial.begin(9600);
}

void loop ()
{
  
  digitalInputValue = digitalRead(digitalPin) ; 
  Serial.println(digitalInputValue); // print value
  if (digitalInputValue == HIGH) 
  {
    for (int i = 0; i &lt;= 5; i++) 
    {
    leds[i] = CRGB ( 255, 0, 0);
    FastLED.show();
    delay(40);
    }
  }

  else if (digitalInputValue ==LOW)
  {
    for (int i = 0; i &lt;= 5; i++) 
    {
      leds[i] = CRGB ( 0, 0, 0);
      FastLED.show();
      delay(30);
    }
  } 
}</pre>
<h2>Arduino code more advanced (with analog input)</h2>
<p>This code is a bit more advanced. The goal for the Hall Sensor Movement Detection is to let the LEDs light up as soon as a rotary movement is detected. Even if a magnet stops directly in front of the KY024 Hall sensor, the LEDs must not light up, because there is no movement.</p>
<p>For this reason, the analog value of the Hall sensor is considered instead of the digital value. If the analog value changes, a rotary movement takes place. A small offset has been integrated to compensate minor fluctuations that occur even without a rotary movement. A counter was programmed as a double safeguard, which also counts how often the analog value changes. The double protection is intended to prevent the Hall sensor from detecting a magnetic field at a standstill.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c" data-enlighter-theme="beyond" data-enlighter-group="HallSensorDetectionWheelAnalog" data-enlighter-title="HallSensorDetectionWheelAnalog.ino">#include &lt;FastLED.h&gt;
#define LED_PIN 7
#define NUM_LEDS 6
CRGB leds[NUM_LEDS];


int analogPin =A0;
int analogVal; // analog readings
int detector =0;
int firstVal=0;
int HIGHcount=0;


void setup() {
  FastLED.addLeds&lt;WS2812, LED_PIN, GRB&gt;(leds, NUM_LEDS);//pinMode (led, OUTPUT); 
  pinMode (analogPin, INPUT); 
  Serial.begin(9600);
  
}

void loop() {
  analogVal= analogRead(analogPin);
  detector = abs(firstVal-analogVal);  //if there is a difference &gt;0 then the wheel might be spinning
  firstVal=analogVal;

  if (detector&gt;4)   //offset = 4 can be adjusted
  {
    HIGHcount++;  //counting the high to eleminate false positives  
    }
  else if (detector&lt;=10)
  {
    HIGHcount=0;
  }

  if (HIGHcount&gt;1)
  {
    YellowToRed(0); 
    delay(1000);
    HIGHcount=0;
    }

  else
  {
     for (int i = 0; i &lt;= 5; i++) 
  {
    leds[i] = CRGB ( 0, 0, 0);
    FastLED.show();
    delay(30);
  } 
    }

}


void YellowToRed(int colorStep)
{
  for( colorStep; colorStep&lt;250; colorStep+=5 ) {

      int r = 255;  // Redness starts at zero and goes up to full
      int b = 0;  // Blue starts at full and goes down to zero
      int g = 255-colorStep;              // No green needed to go from blue to red

      // Now loop though each of the LEDs and set each one to the current color

      for(int x = 0; x &lt; NUM_LEDS; x++){
          leds[x] = CRGB(r,g,b);
          leds[x].maximizeBrightness(255-colorStep);
      }

      // Display the colors we just set on the actual LEDs
      FastLED.show();

      delay(50); 
  }
}</pre>
<h2>Pictures of the Hall Sensor Movement Detection</h2>
<p><img loading="lazy" decoding="async" class="zoooom aligncenter wp-image-702" src="https://nerd-corner.com/wp-content/uploads/2020/08/Magnetrad1.jpg" alt="Hall Sensor Movement Detection wheel" width="1745" height="1383" srcset="https://nerd-corner.com/wp-content/uploads/2020/08/Magnetrad1.jpg 1746w, https://nerd-corner.com/wp-content/uploads/2020/08/Magnetrad1-300x238.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/08/Magnetrad1-1024x812.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/08/Magnetrad1-768x609.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/08/Magnetrad1-1536x1218.jpg 1536w" sizes="auto, (max-width: 1745px) 100vw, 1745px" /> <img loading="lazy" decoding="async" class="aligncenter wp-image-703 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/08/Magnetradkpl1-scaled.jpg" alt="magnet wheel for movement detection" width="2559" height="1396" srcset="https://nerd-corner.com/wp-content/uploads/2020/08/Magnetradkpl1-scaled.jpg 2560w, https://nerd-corner.com/wp-content/uploads/2020/08/Magnetradkpl1-300x164.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/08/Magnetradkpl1-1024x559.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/08/Magnetradkpl1-768x419.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/08/Magnetradkpl1-1536x838.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2020/08/Magnetradkpl1-2048x1117.jpg 2048w" sizes="auto, (max-width: 2559px) 100vw, 2559px" /> <img loading="lazy" decoding="async" class="aligncenter wp-image-704 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/08/MagnettestradStander.jpg" alt="" width="1183" height="1421" srcset="https://nerd-corner.com/wp-content/uploads/2020/08/MagnettestradStander.jpg 1184w, https://nerd-corner.com/wp-content/uploads/2020/08/MagnettestradStander-250x300.jpg 250w, https://nerd-corner.com/wp-content/uploads/2020/08/MagnettestradStander-853x1024.jpg 853w, https://nerd-corner.com/wp-content/uploads/2020/08/MagnettestradStander-768x922.jpg 768w" sizes="auto, (max-width: 1183px) 100vw, 1183px" /> <img loading="lazy" decoding="async" class="zoooom aligncenter wp-image-706" src="https://nerd-corner.com/wp-content/uploads/2020/08/Magnettestradz.jpg" alt="construction magnet wheel Hall Sensor Movement Detection" width="1692" height="1639" srcset="https://nerd-corner.com/wp-content/uploads/2020/08/Magnettestradz.jpg 1693w, https://nerd-corner.com/wp-content/uploads/2020/08/Magnettestradz-300x291.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/08/Magnettestradz-1024x992.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/08/Magnettestradz-768x744.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/08/Magnettestradz-1536x1488.jpg 1536w" sizes="auto, (max-width: 1692px) 100vw, 1692px" /></p>
<h2>Download files</h2>
<ul>
<li><a href="https://www.thingiverse.com/thing:5259642" target="_blank" rel="noopener">Magnet Wheel (STL)</a></li>
</ul>
<p>The post <a href="https://nerd-corner.com/hall-sensor-movement-detection/">Hall Sensor Movement Detection</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nerd-corner.com/hall-sensor-movement-detection/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		<enclosure url="https://nerd-corner.com/wp-content/uploads/2020/08/MagneranimationA.mp4" length="47581724" type="video/mp4" />

			</item>
		<item>
		<title>How to use the hallsensor KY-024 with Arduino Code and Wiring</title>
		<link>https://nerd-corner.com/hallsensor-ky-024-arduino-code/</link>
					<comments>https://nerd-corner.com/hallsensor-ky-024-arduino-code/#comments</comments>
		
		<dc:creator><![CDATA[Nerds]]></dc:creator>
		<pubDate>Tue, 21 Jul 2020 14:09:01 +0000</pubDate>
				<category><![CDATA[Arduino projects]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Arduino Code]]></category>
		<category><![CDATA[arduino mega]]></category>
		<category><![CDATA[Fritzing]]></category>
		<category><![CDATA[hall sensor]]></category>
		<category><![CDATA[hallsensor]]></category>
		<category><![CDATA[KY-024]]></category>
		<category><![CDATA[KY024]]></category>
		<category><![CDATA[Wiring]]></category>
		<guid isPermaLink="false">https://nerd-corner.com/?p=667</guid>

					<description><![CDATA[<p>A Hall sensor can detect magnetic fields and is therefore very suitable in the handicraft area to detect movements. You can often find videos on &#8230; </p>
<p>The post <a href="https://nerd-corner.com/hallsensor-ky-024-arduino-code/">How to use the hallsensor KY-024 with Arduino Code and Wiring</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>A Hall sensor can detect magnetic fields and is therefore very suitable in the handicraft area to detect movements. You can often find videos on the Internet in which a Hall sensor KY-024 serves as a tachometer with an Arduino.</p>
<p><em><strong>This might be interesting for you:</strong> <a href="https://nerd-corner.com/hall-sensor-movement-detection/" target="_blank" rel="noopener noreferrer">We built a Hall sensor movement detection wheel</a></em></p>
<p>We have already started small Arduino <a href="https://nerd-corner.com/category/arduino-projects/">projects</a>. Next we want to build a prayer wheel that will light up when it is rotated. For this we will need a Hall sensor.<br />
This post shows a simple example to explain how to connect a Hall sensor to an Arduino and program it so that an LED starts to light up as soon as the Hall sensor KY024 detects a magnetic field.</p>
<h2>List of components</h2>
<ul>
<li>Arudino Mega</li>
<li>Jumper cable</li>
<li>220 Ohm resistor</li>
<li>LED</li>
<li>Magnets</li>
<li>Hall sensor KY-024</li>
</ul>
<p><iframe loading="lazy" hcb-fetch-image-from="https://youtu.be/SyzZMWDjQ1w" title="KY-024 Hall Sensor with Arduino code and full user guide!" width="1200" height="675" src="https://www.youtube.com/embed/SyzZMWDjQ1w?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></p>
<h2>How does a Hall sensor work or what is the Hall effect?</h2>
<p>When a current-carrying electrical conductor is in a magnetic field, an electrical field builds up. This is perpendicular to the current direction and to the magnetic field and compensates for the Lorentz force which acts on the electrons.</p>
<p>A Hall sensor also provides a signal when the magnetic field in which it is located is constant. This is the advantage compared to a simple coil, which can only determine the derivation of the magnetic field over time.</p>
<h2>The Hall sensor KY-024</h2>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-672 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/07/KY024.jpg" alt="Hall sensor KY024 KY-024 KY 024 arduino code" width="913" height="755" srcset="https://nerd-corner.com/wp-content/uploads/2020/07/KY024.jpg 914w, https://nerd-corner.com/wp-content/uploads/2020/07/KY024-300x248.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/07/KY024-768x635.jpg 768w" sizes="auto, (max-width: 913px) 100vw, 913px" /></p>
<p>The linear magnetic Hall sensor KY-024 can detect magnetic fields and therefore reacts as soon as you approach it with a magnet. It has a potentiometer with which the sensitivity of the sensor can be set. The KY-024 Hall sensor offers both an analog and a digital output.</p>
<p>The digital output acts as a switch that turns on and off when a magnet is nearby. The analog output, on the other hand, can measure the polarity and relative strength of the magnetic field.</p>
<h2>KY-024 Arduino Wiring</h2>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-670 zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/07/HallSensor_Steckplatine.png" alt="Wiring the KY024 hall sensor to an arduino" width="1913" height="1034" srcset="https://nerd-corner.com/wp-content/uploads/2020/07/HallSensor_Steckplatine.png 1914w, https://nerd-corner.com/wp-content/uploads/2020/07/HallSensor_Steckplatine-300x162.png 300w, https://nerd-corner.com/wp-content/uploads/2020/07/HallSensor_Steckplatine-1024x554.png 1024w, https://nerd-corner.com/wp-content/uploads/2020/07/HallSensor_Steckplatine-768x415.png 768w, https://nerd-corner.com/wp-content/uploads/2020/07/HallSensor_Steckplatine-1536x831.png 1536w" sizes="auto, (max-width: 1913px) 100vw, 1913px" /></p>
<p>It is a simple structure that only serves to illustrate the functioning of the KY-024 Hall sensor. Please pay attention to the forward direction of the LED, the kinked end is connected to an Arduino pin and the straight end to GND. Correctly the LED needs a 220 Ohm ballast resistor. However, this can also be neglected for the short duration of use.</p>
<p>Otherwise, connect the GND of the KY-024 to the GND of the Arduino analogous to the <a href="https://fritzing.org/" target="_blank" rel="noopener noreferrer">Fritzing</a> sketch. Connect the analog output A0 of the KY-024 to A0 of the Arduino Mega. Connect the + of the KY-024 to 5V of the Arduino and connect the digital output D0 of the KY-024 to pin 9 of the Arduino. That was the complete wiring.</p>
<h2>Hall sensor KY-024 Arduino Code</h2>
<pre class="EnlighterJSRAW" data-enlighter-language="c" data-enlighter-title="Hallsensor.ino" data-enlighter-theme="beyond" data-enlighter-group="Hallsensor">int LED = 53 ; // LED
int digitalPin = 9; // Hall magnetic sensor input 1 (high) or 0 (low)
int analogPin = A0; // analog Pin also available, but not necessary
int digitalInputValue ; // digital readings
int analogInputValue; // analog readings

void setup ()
{
  pinMode (LED, OUTPUT); 
  pinMode (digitalPin, INPUT); 
  pinMode(analogPin, INPUT); //not necessary, but it is interesting to see the analog values
  Serial.begin(9600);
}

void loop ()
{
  
  digitalInputValue = digitalRead(digitalPin) ; 
  if (digitalInputValue == HIGH) // When magnet is present, digitalInputValue gets 1 (HIGH) and turns LED on
  {
    digitalWrite (LED, HIGH);
    
  }
  else
  {
    
    digitalWrite (LED, LOW);
  }
  
  //Here you can see the analog values of the sensor
  analogInputValue = analogRead(analogPin);
  Serial.println(analogInputValue); // print analog value

  delay(100);
}</pre>
<p>We first define the assignment of the LED (here pin 53), the digital (pin 9) and the analog pin (pin A0) and two variables to read the digital and analog sensor data. The digital pin is sufficient for our purpose of lighting the LED.</p>
<p>The analog pin can actually be neglected. However, since it is useful for this tutorial to show the analog values, the analog pin was nevertheless taken into account in the code.<br />
The respective pin mode is defined in the setup and the digital sensor value of the KY 024 is read in the loop function and, depending on the value, the LED receives the command to light or not. The digital sensor value is either 0 or 1. If you want to, you can use the penultimate 2 lines to display the associated analog values.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-677 size-large zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/07/Analog-Sensor-Data-1024x597.jpg" alt="hallsensor Ky024 arduino code analog data" width="1024" height="597" srcset="https://nerd-corner.com/wp-content/uploads/2020/07/Analog-Sensor-Data-1024x597.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/07/Analog-Sensor-Data-300x175.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/07/Analog-Sensor-Data-768x447.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/07/Analog-Sensor-Data-1536x895.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2020/07/Analog-Sensor-Data.jpg 1917w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></p>
<h2>Download file</h2>
<ul>
<li><a  data-e-Disable-Page-Transition="true" class="download-link" title="" href="https://nerd-corner.com/download/674/?tmstv=1756257505" rel="nofollow" id="download-link-674" data-redirect="false" >
	Hall sensor KY-024 Arduino code</a>
</li>
</ul>
<p>The post <a href="https://nerd-corner.com/hallsensor-ky-024-arduino-code/">How to use the hallsensor KY-024 with Arduino Code and Wiring</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nerd-corner.com/hallsensor-ky-024-arduino-code/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>Android Bluetooth classic App for Arduino fan control</title>
		<link>https://nerd-corner.com/android-bluetooth-classic-app-for-arduino-fan-control/</link>
					<comments>https://nerd-corner.com/android-bluetooth-classic-app-for-arduino-fan-control/#comments</comments>
		
		<dc:creator><![CDATA[Nerds]]></dc:creator>
		<pubDate>Thu, 12 Mar 2020 13:45:02 +0000</pubDate>
				<category><![CDATA[App development]]></category>
		<category><![CDATA[Arduino projects]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[App]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Bluetooth]]></category>
		<category><![CDATA[fan]]></category>
		<guid isPermaLink="false">https://nerd-corner.com/?p=316</guid>

					<description><![CDATA[<p>We have already created a post in which we explain how to regulate fans by voltage. It doesn&#8217;t matter whether the fan is supplied with &#8230; </p>
<p>The post <a href="https://nerd-corner.com/android-bluetooth-classic-app-for-arduino-fan-control/">Android Bluetooth classic App for Arduino fan control</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>We have already created a post in which we explain <a href="https://nerd-corner.com/arduino-fan-controller/">how to regulate fans by voltage</a>. It doesn&#8217;t matter whether the fan is supplied with 12V or 5V. The number of connections is also unimportant. You only need the + and &#8211; of the fan. Now we also want to connect a Bluetooth module to the Arduino and write an app that can be used to change the speed of the fan. So let&#8217;s get started with the Android Bluetooth classic App for Arduino.</p>
<h2>List of components</h2>
<ul>
<li>Arudino Mega</li>
<li>Breadboard</li>
<li>12V power supply</li>
<li>12V fan</li>
<li>jumper cable</li>
<li>220 Ohm resistor</li>
<li>NPN Transistor number: BC546B D6</li>
<li>Bluetooth module HC-05 or HC-06</li>
</ul>
<p>&nbsp;</p>
<p><iframe loading="lazy" hcb-fetch-image-from="https://www.youtube.com/watch?v=sJ2Og_How2Y" title="Android Bluetooth classic App for Arduino fan control // Arduino Code and Wiring // Full user guide" width="1200" height="675" src="https://www.youtube.com/embed/sJ2Og_How2Y?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></p>
<p><img loading="lazy" decoding="async" class="wp-image-323 size-large zoooom aligncenter" src="https://nerd-corner.com/wp-content/uploads/2020/03/IMG_20200311_134834-1024x768.jpg" alt="Android Bluetooth app for arduino control nerd corner" width="720" height="540" srcset="https://nerd-corner.com/wp-content/uploads/2020/03/IMG_20200311_134834-1024x768.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/03/IMG_20200311_134834-300x225.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/03/IMG_20200311_134834-768x576.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/03/IMG_20200311_134834-1536x1152.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2020/03/IMG_20200311_134834-2048x1536.jpg 2048w, https://nerd-corner.com/wp-content/uploads/2020/03/IMG_20200311_134834-1920x1440.jpg 1920w, https://nerd-corner.com/wp-content/uploads/2020/03/IMG_20200311_134834-scaled.jpg 2560w" sizes="auto, (max-width: 720px) 100vw, 720px" /></p>
<h2>Wiring</h2>
<p><img loading="lazy" decoding="async" class="wp-image-324 size-large zoooom aligncenter" src="https://nerd-corner.com/wp-content/uploads/2020/03/fan_mit_bluetooth_mit_transistor-1024x588.png" alt="Android Bluetooth app for arduino control nerd corner" width="720" height="413" srcset="https://nerd-corner.com/wp-content/uploads/2020/03/fan_mit_bluetooth_mit_transistor-1024x588.png 1024w, https://nerd-corner.com/wp-content/uploads/2020/03/fan_mit_bluetooth_mit_transistor-300x172.png 300w, https://nerd-corner.com/wp-content/uploads/2020/03/fan_mit_bluetooth_mit_transistor-768x441.png 768w, https://nerd-corner.com/wp-content/uploads/2020/03/fan_mit_bluetooth_mit_transistor-1536x881.png 1536w, https://nerd-corner.com/wp-content/uploads/2020/03/fan_mit_bluetooth_mit_transistor-2048x1175.png 2048w, https://nerd-corner.com/wp-content/uploads/2020/03/fan_mit_bluetooth_mit_transistor-1920x1102.png 1920w, https://nerd-corner.com/wp-content/uploads/2020/03/fan_mit_bluetooth_mit_transistor.png 3858w" sizes="auto, (max-width: 720px) 100vw, 720px" /></p>
<p>For the wiring, we proceed analogously to our &#8220;fan control&#8221; post. The 12V power supply must be connected to the breadboard. We connect this &#8211; of the breadboard with GND of the Arduino (the short blue cable connection in the picture). Then we connect the + of the breadboard to Vin of the Arduino Mega (red cable between Arduino and breadboard).</p>
<p>If we would plug the 12V power supply into the socket now. Then our Arduino would already be powered. There is no additional power supply like USB required. The Vin pin of the Arduino automatically regulates the 12V of the power supply to 5V for the Arduino.</p>
<p>Now we plug the NPN transistor into the breadboard. We connect the base (B) to the 220 Ohm resistor and then to pin 13 (yellow connection in the picture). We connect the collector (C) of the transistor directly to the negative connection of the fan (black fan cable). The positive fan connector is connected to the + of the breadboard. We connect the emitter (E) of the transistor to the – of the breadboard.</p>
<p>In addition to these already known steps, we take the Bluetooth module and connect the ground of the module to the ground of the Arduino (black cable). VCC of the module must be connected to 3.3V of the Arduino (red connection). If there is no 3.3V connection, the 5V connection can also be used. TX of the Bluetooth module has to be connected to RX of the Arduino (orange cable). RX of the module has to be connected to TX of the Arduino (purple cable). This means TX to RX and RX to TX. Always the equivalent!</p>
<p>Important: While the Arduino code is being flashed on the Arduino, you have to unplug RX and TX. Otherwise the flash process won&#8217;t work!</p>
<h2>Programming the Android Bluetooth classic app for Arduino</h2>
<p>We program a pure Android app with an HC-05 or alternatively HC-06 Bluetooth module. These two are Bluetooth Classic Modules. You can not connect to Bluetooth 4.0 also called Bluetooth Low Energy (BLE). The code for BLE is very different. Below is the programming guide for a Bluetooth Android app build with Xamarin Android. All important files are also uploaded!</p>
<p>As development environment we use Visual Studio (it is free) for the Xamarin.Android app. In AndroidStudio, the process is analogous, but the code will be in Java and not in C#.</p>
<p>Click on &#8220;Create new project&#8221; and select &#8220;Android app (Xamarin)&#8221;. At First we add the Bluetooth permissions to the &#8220;AndroidManifest.xml&#8221; file:</p>
<pre>&lt;uses-permission android: name = "android.permission.BLUETOOTH" /&gt;
&lt;uses-permission android: name = "android.permission.BLUETOOTH_ADMIN" /&gt;</pre>
<p>Then we design the layout of the app in the &#8220;activity_main.xml&#8221; file. We need 2 buttons for &#8220;Connect&#8221; and &#8220;Disconnect&#8221; and a slider for speed control. For the slider we set the maximum value to 127 (android: max = &#8220;127&#8221;).</p>
<p>In &#8220;MainActivity.cs&#8221; we add &#8220;using Android.Bluetooth&#8221;, create a &#8220;BluetoothConnection&#8221; class and set our &#8220;activity_main.xml&#8221; file as the start page. A Bluetooth socket is created for the connection to the Arduino. We recommend to look at the source code which is attached to this post.</p>
<p>Essentially, we always send a byte to the Arduino. That means we can send numbers between 0 and 255. For the fan control, we take the range from 0 to 127. The Arduino doubles this value and thus regulates the fan, which also runs in a range between 0 and 255. The rest of the range between 128 and 255 can be used for further functions. That&#8217;s it, just compile the app and go to the next step!</p>
<p>Incidentally, the code for the app is based on this project here: <a href="https://www.instructables.com/id/3-LED-Backlight-Xamarin-and-Arduino-With-HC05/" target="_blank" rel="noopener noreferrer">https://www.instructables.com/id/3-LED-Backlight-Xamarin-and-Arduino-With-HC05/</a></p>
<h2>Arduino Code</h2>
<p><img loading="lazy" decoding="async" class="wp-image-325 size-large zoooom aligncenter" src="https://nerd-corner.com/wp-content/uploads/2020/03/arduino_fan_controller_with_bluetooth_screenshot-1024x866.jpg" alt="arduino fan controller with bluetooth nerd corner" width="720" height="609" srcset="https://nerd-corner.com/wp-content/uploads/2020/03/arduino_fan_controller_with_bluetooth_screenshot-1024x866.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/03/arduino_fan_controller_with_bluetooth_screenshot-300x254.jpg 300w, https://nerd-corner.com/wp-content/uploads/2020/03/arduino_fan_controller_with_bluetooth_screenshot-768x649.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/03/arduino_fan_controller_with_bluetooth_screenshot.jpg 1081w" sizes="auto, (max-width: 720px) 100vw, 720px" /></p>
<pre><code>#define motorPin 13
int received; //for the received Byte
int fanSpeed = 127; //initial speed - must be a number between 0 and 255
void setup() {
  Serial.begin(9600); //for communication with the app
  delay(3000); // small delay
  pinMode(motorPin, OUTPUT); //define motor pin as output
  analogWrite(motorPin,fanSpeed); //set the initial speed of the fan
}
void loop() {  
  while(Serial.available()) 
  {
     received = Serial.read(); //received Byte    
     Serial.println(received); //if the arduino is connected to the PC, than you can check the received Byte
     switch (received)  //you can easily add new cases to customize your arduino
     {
        case 200:
            Serial.println("RESTARTED");
            break;
        default:
            if(received &gt;0 &amp;&amp; received &lt;=127)
            {
              fanSpeed = (received*2); //app sends value between 0 and 127 - so we need to double it for the fan range between 0 and 255
              delay(10);
            }
            break;
     }  
  }
  analogWrite(motorPin,fanSpeed); //set the speed of the fan
}</code></pre>
<p>Please do not forget to disconnect the RX and TX wires before flashing the Arduino and afterwards connect it again correctly (RX to TX and TX to RX)!</p>
<p>Since we have connected the base of the transistor to pin 13, we define it as &#8220;motorPin&#8221;. The fan speed can be controlled via the &#8220;fanSpeed&#8221; variable. At the beginning, we set &#8220;fanSpeed&#8221; to half the speed, i.e. 127. (Depending on the fan model, a certain minimum speed is necessary for the fan to start.)</p>
<p>We define a variable &#8220;received&#8221; in which we store the byte sent from the app. In the setup function we start the communication with &#8220;Serial.begin&#8221; and set the baud rate to 9600. Then we program a while loop in the loop function. The while loop becomes active whenever a byte is received. If the value of the byte is between 0 and 127, we double it and define it as our new fan speed &#8220;fanSpeed&#8221;. As soon as the while loop has ended, the new speed for the fan is set with &#8220;analogWrite (motorPin, fanSpeed);&#8221;</p>
<h2>Screenshots of the Android Bluetooth classic App for Arduino</h2>
<p>Please note, you have to go to the settings and connect to the Bluetooth module at first. Otherwise you won&#8217;t be able to connect to the Arduino with the app!</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-329 size-medium zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/03/Screenshot_20200311_154409_com.companyname.fancontrollerbluetooth-150x300.jpg" alt="Screenshots Android App Bluetooth arduino control nerd corner" width="150" height="300" srcset="https://nerd-corner.com/wp-content/uploads/2020/03/Screenshot_20200311_154409_com.companyname.fancontrollerbluetooth-150x300.jpg 150w, https://nerd-corner.com/wp-content/uploads/2020/03/Screenshot_20200311_154409_com.companyname.fancontrollerbluetooth-512x1024.jpg 512w, https://nerd-corner.com/wp-content/uploads/2020/03/Screenshot_20200311_154409_com.companyname.fancontrollerbluetooth-768x1536.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/03/Screenshot_20200311_154409_com.companyname.fancontrollerbluetooth-1024x2048.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/03/Screenshot_20200311_154409_com.companyname.fancontrollerbluetooth.jpg 1080w" sizes="auto, (max-width: 150px) 100vw, 150px" /> <img loading="lazy" decoding="async" class="alignnone wp-image-330 size-medium zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/03/Screenshot_20200311_154416_com.companyname.fancontrollerbluetooth-1-150x300.jpg" alt="Screenshots Android App Bluetooth arduino control nerd corner" width="150" height="300" srcset="https://nerd-corner.com/wp-content/uploads/2020/03/Screenshot_20200311_154416_com.companyname.fancontrollerbluetooth-1-150x300.jpg 150w, https://nerd-corner.com/wp-content/uploads/2020/03/Screenshot_20200311_154416_com.companyname.fancontrollerbluetooth-1-512x1024.jpg 512w, https://nerd-corner.com/wp-content/uploads/2020/03/Screenshot_20200311_154416_com.companyname.fancontrollerbluetooth-1-768x1536.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/03/Screenshot_20200311_154416_com.companyname.fancontrollerbluetooth-1-1024x2048.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/03/Screenshot_20200311_154416_com.companyname.fancontrollerbluetooth-1.jpg 1080w" sizes="auto, (max-width: 150px) 100vw, 150px" /> <img loading="lazy" decoding="async" class="alignnone wp-image-331 size-medium zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/03/Screenshot_20200311_154426_com.companyname.fancontrollerbluetooth-150x300.jpg" alt="Screenshots Android App Bluetooth arduino control nerd corner" width="150" height="300" srcset="https://nerd-corner.com/wp-content/uploads/2020/03/Screenshot_20200311_154426_com.companyname.fancontrollerbluetooth-150x300.jpg 150w, https://nerd-corner.com/wp-content/uploads/2020/03/Screenshot_20200311_154426_com.companyname.fancontrollerbluetooth-512x1024.jpg 512w, https://nerd-corner.com/wp-content/uploads/2020/03/Screenshot_20200311_154426_com.companyname.fancontrollerbluetooth-768x1536.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/03/Screenshot_20200311_154426_com.companyname.fancontrollerbluetooth-1024x2048.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/03/Screenshot_20200311_154426_com.companyname.fancontrollerbluetooth.jpg 1080w" sizes="auto, (max-width: 150px) 100vw, 150px" /> <img loading="lazy" decoding="async" class="alignnone wp-image-332 size-medium zoooom" src="https://nerd-corner.com/wp-content/uploads/2020/03/Screenshot_20200311_154438_com.companyname.fancontrollerbluetooth-150x300.jpg" alt="Screenshots Android App Bluetooth arduino control nerd corner" width="150" height="300" srcset="https://nerd-corner.com/wp-content/uploads/2020/03/Screenshot_20200311_154438_com.companyname.fancontrollerbluetooth-150x300.jpg 150w, https://nerd-corner.com/wp-content/uploads/2020/03/Screenshot_20200311_154438_com.companyname.fancontrollerbluetooth-512x1024.jpg 512w, https://nerd-corner.com/wp-content/uploads/2020/03/Screenshot_20200311_154438_com.companyname.fancontrollerbluetooth-768x1536.jpg 768w, https://nerd-corner.com/wp-content/uploads/2020/03/Screenshot_20200311_154438_com.companyname.fancontrollerbluetooth-1024x2048.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2020/03/Screenshot_20200311_154438_com.companyname.fancontrollerbluetooth.jpg 1080w" sizes="auto, (max-width: 150px) 100vw, 150px" /></p>
<h2>Download files</h2>
<ul>
<li><a  data-e-Disable-Page-Transition="true" class="download-link" title="" href="https://nerd-corner.com/download/340/?tmstv=1756257505" rel="nofollow" id="download-link-340" data-redirect="false" >
	Source Code Android App "FanControllerBluetooth"</a>
</li>
<li><a  data-e-Disable-Page-Transition="true" class="download-link" title="" href="https://nerd-corner.com/download/350/?tmstv=1756257505" rel="nofollow" id="download-link-350" data-redirect="false" >
	Arduino Code for the "FanControllerBluetooth" app</a>
</li>
<li><a  data-e-Disable-Page-Transition="true" class="download-link" title="" href="https://nerd-corner.com/download/345/?tmstv=1756257505" rel="nofollow" id="download-link-345" data-redirect="false" >
	Only MainActivity.cs AndroidMainfest.xml and activity_main.xml of the "FanControllerBluetooth" app</a>
</li>
</ul>
<p>The post <a href="https://nerd-corner.com/android-bluetooth-classic-app-for-arduino-fan-control/">Android Bluetooth classic App for Arduino fan control</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nerd-corner.com/android-bluetooth-classic-app-for-arduino-fan-control/feed/</wfw:commentRss>
			<slash:comments>8</slash:comments>
		
		
			</item>
		<item>
		<title>Arduino fan controller</title>
		<link>https://nerd-corner.com/arduino-fan-controller/</link>
					<comments>https://nerd-corner.com/arduino-fan-controller/#comments</comments>
		
		<dc:creator><![CDATA[Nerds]]></dc:creator>
		<pubDate>Thu, 12 Mar 2020 12:57:32 +0000</pubDate>
				<category><![CDATA[Arduino projects]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[fan]]></category>
		<category><![CDATA[transistor]]></category>
		<guid isPermaLink="false">https://nerd-corner.com/?p=305</guid>

					<description><![CDATA[<p>There are many different ways to control the speed of a fan. For example, if your fan has a PWM wire, then you could directly &#8230; </p>
<p>The post <a href="https://nerd-corner.com/arduino-fan-controller/">Arduino fan controller</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>There are many different ways to control the speed of a fan. For example, if your fan has a PWM wire, then you could directly use the PWM signal. Also see our other post for <a href="https://nerd-corner.com/android-bluetooth-classic-app-for-arduino-fan-control/">an Arduino fan controller with a Bluetooth Android app</a>.</p>
<p>In this post we show you how to regulate the rotational speed of any fan. It doesn&#8217;t matter if your fan needs 12 Volt or 5 Volt. Also the number of wires is not important. You can use a 3, 4 or 2 wire fan! We only work with the + and &#8211; wire of your fan.</p>
<p>The Arduino supports 5 Volt directly. In our case we use an old PC fan with 12 Volt, so an external 12 Volt power supply is necessary.</p>
<h2>List of components</h2>
<ul>
<li>Arudino Mega</li>
<li>Breadboard</li>
<li>12V power supply</li>
<li>12V fan</li>
<li>Jumper cable</li>
<li>220 Ohm resistor</li>
<li>NPN Transistor number: BC546B D6</li>
</ul>
<p><iframe loading="lazy" hcb-fetch-image-from="https://youtu.be/gY5d0foRP28" title="Arduino Fan Controller // With Arduino Code and Wiring // Full user guide // Step by Step" width="1200" height="675" src="https://www.youtube.com/embed/gY5d0foRP28?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></p>
<p>&nbsp;</p>
<h2>Wiring</h2>
<p><img loading="lazy" decoding="async" class="wp-image-308 size-large zoooom aligncenter" src="https://nerd-corner.com/wp-content/uploads/2020/03/fan_ohne_bluetooth_mit_transistor-1024x465.png" alt="arduino fan controller wiring fritzing" width="720" height="327" srcset="https://nerd-corner.com/wp-content/uploads/2020/03/fan_ohne_bluetooth_mit_transistor-1024x465.png 1024w, https://nerd-corner.com/wp-content/uploads/2020/03/fan_ohne_bluetooth_mit_transistor-300x136.png 300w, https://nerd-corner.com/wp-content/uploads/2020/03/fan_ohne_bluetooth_mit_transistor-768x349.png 768w, https://nerd-corner.com/wp-content/uploads/2020/03/fan_ohne_bluetooth_mit_transistor-1536x698.png 1536w, https://nerd-corner.com/wp-content/uploads/2020/03/fan_ohne_bluetooth_mit_transistor-2048x930.png 2048w, https://nerd-corner.com/wp-content/uploads/2020/03/fan_ohne_bluetooth_mit_transistor-1920x872.png 1920w, https://nerd-corner.com/wp-content/uploads/2020/03/fan_ohne_bluetooth_mit_transistor.png 3858w" sizes="auto, (max-width: 720px) 100vw, 720px" /></p>
<p>For the wiring we proceed according to the sketch . The 12V power supply is connected to the breadboard. We connect the &#8211; of the breadboard with GND of the Arduino (the short blue cable connection). Then the + of the breadboard to Vin of the Arduino Mega (red cable between Arduino and breadboard).</p>
<p>If we would plug the 12V power supply into the socket now. Then our Arduino would already be powered. There is no additional power supply like USB required. The Vin pin of the Arduino automatically regulates the 12V of the power supply to 5V for the Arduino.</p>
<p>Now we plug the NPN transistor into the breadboard. We connect the base (B) to the 220 Ohm resistor and then to pin 13 (yellow connection in the picture). We connect the collector (C) of the transistor directly to the negative connection of the fan (black fan cable). The positive fan connector is connected to the + of the breadboard. We connect the emitter (E) of the transistor to the &#8211; of the breadboard. That&#8217;s all for the wiring! Time for the Arduino code!</p>
<h2>The code for the Arduino fan controller</h2>
<p><img loading="lazy" decoding="async" class="wp-image-307 zoooom aligncenter" src="https://nerd-corner.com/wp-content/uploads/2020/03/arduino_fan_controller_screenshot.jpg" alt="arduino code fan controller nerd corner" width="635" height="719" srcset="https://nerd-corner.com/wp-content/uploads/2020/03/arduino_fan_controller_screenshot.jpg 636w, https://nerd-corner.com/wp-content/uploads/2020/03/arduino_fan_controller_screenshot-265x300.jpg 265w" sizes="auto, (max-width: 635px) 100vw, 635px" /></p>
<p>The Arduino code is absolutely simple and can be easily integrated into any existing Arduino <a href="https://www.arduino.cc/en/main/software">program</a>. Since we have connected the base of the transistor to pin 13, we define it as &#8220;motorPin&#8221;. The speed of the fan can then be controlled via the &#8220;speed&#8221; variable. A value between 0 and 255 must be selected for the speed. Depending on the fan model, a minimum speed is necessary for the fan to start.</p>
<p>The post <a href="https://nerd-corner.com/arduino-fan-controller/">Arduino fan controller</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nerd-corner.com/arduino-fan-controller/feed/</wfw:commentRss>
			<slash:comments>9</slash:comments>
		
		
			</item>
	</channel>
</rss>
