<?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>fan Archives - Nerd Corner</title>
	<atom:link href="https://nerd-corner.com/tag/fan/feed/" rel="self" type="application/rss+xml" />
	<link>https://nerd-corner.com/tag/fan/</link>
	<description>Craft your dreams!</description>
	<lastBuildDate>Thu, 08 Jul 2021 14:56:16 +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>fan Archives - Nerd Corner</title>
	<link>https://nerd-corner.com/tag/fan/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Upgrade: Data transfer via VLC and LiFi &#8211; Pi to Pi transfer</title>
		<link>https://nerd-corner.com/upgrade-data-transfer-via-vlc-and-lifi-pi-to-pi-transfer/</link>
					<comments>https://nerd-corner.com/upgrade-data-transfer-via-vlc-and-lifi-pi-to-pi-transfer/#comments</comments>
		
		<dc:creator><![CDATA[Nerds]]></dc:creator>
		<pubDate>Thu, 08 Jul 2021 14:27:07 +0000</pubDate>
				<category><![CDATA[Handcrafted]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[3D print]]></category>
		<category><![CDATA[CAD]]></category>
		<category><![CDATA[CAD design]]></category>
		<category><![CDATA[cyclic redundancy check]]></category>
		<category><![CDATA[data transfer]]></category>
		<category><![CDATA[fan]]></category>
		<category><![CDATA[LiFi]]></category>
		<category><![CDATA[LiFI Router]]></category>
		<category><![CDATA[Light Fidelity]]></category>
		<category><![CDATA[LM393]]></category>
		<category><![CDATA[pi]]></category>
		<category><![CDATA[precise]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[Timer]]></category>
		<category><![CDATA[visible Light communication]]></category>
		<category><![CDATA[visible light communication project]]></category>
		<category><![CDATA[VLC Raspberry Pi project]]></category>
		<guid isPermaLink="false">https://nerd-corner.com/de/?p=985</guid>

					<description><![CDATA[<p>After I already transferred simple text messages via light signals from a Raspberry Pi to an Arduino Uno ( Link: https://nerd-corner.com/sending-text-messages-with-visible-light-communication/ ), I wanted to &#8230; </p>
<p>The post <a href="https://nerd-corner.com/upgrade-data-transfer-via-vlc-and-lifi-pi-to-pi-transfer/">Upgrade: Data transfer via VLC and LiFi &#8211; Pi to Pi transfer</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>After I already transferred simple text messages via light signals from a Raspberry Pi to an Arduino Uno ( Link: <a href="https://nerd-corner.com/sending-text-messages-with-visible-light-communication/" target="_blank" rel="noopener">https://nerd-corner.com/sending-text-messages-with-visible-light-communication/</a> ), I wanted to improve this system to be able to transfer any file formats in both directions. Since a Raspberry Pi uses Linux, this system can be transferred to any Linux device for data transfer via VLC (visual light communication). The software code and STL files can be downloaded at the end of the blog entry.</p>
<p><em><strong>This might also be interesting for you:</strong> <a href="https://nerd-corner.com/sending-text-messages-with-visible-light-communication/" target="_blank" rel="noopener">Sending text messages with light signals</a></em></p>
<p><em><strong>Closely related to this article:</strong> <a href="https://nerd-corner.com/cyclic-redundancy-check-in-c-code/" target="_blank" rel="noopener">Error detection during data transmission</a></em></p>
<p><em><strong>Also relevant:</strong> <a href="https://nerd-corner.com/how-to-program-a-highly-precise-timer-in-c-for-linux/" target="_blank" rel="noopener">Precise Timer in C for data transfer</a></em></p>
<h2>List of components</h2>
<ul>
<li>2x Raspberry Pi 4</li>
<li>2x 5V Solar cell</li>
<li>2x 5V Laser diode</li>
<li>Jumper cables</li>
<li>3D printer</li>
<li>Filament</li>
<li>2x 5V Fan</li>
<li>NPN Transistor</li>
<li>2x ADC Board with a LM393 dual comparator</li>
</ul>
<p><img fetchpriority="high" decoding="async" class="zoooom aligncenter wp-image-966" src="https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-parts-scaled.jpg" alt="Datenübertragung mit Licht Einzelteile Data transfer via VLC" width="2500" height="1681" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-parts-scaled.jpg 2560w, https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-parts-300x202.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-parts-1024x689.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-parts-768x516.jpg 768w, https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-parts-1536x1033.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-parts-2048x1377.jpg 2048w" sizes="(max-width: 2500px) 100vw, 2500px" /></p>
<h2>Wiring</h2>
<p>Unlike the wiring in the last article, where text messages were sent from a Pi to an Arduino via light signals ( Link: <a href="https://nerd-corner.com/sending-text-messages-with-visible-light-communication/" target="_blank" rel="noopener">https://nerd-corner.com/sending-text-messages-with-visible-light-communication/</a> ), there is now no defined receiver and no defined transmitter. Instead, two identical stations are set up that can both send and receive data.</p>
<p><img decoding="async" class="aligncenter wp-image-965 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/07/FritzingPiTransceiver_Steckplatine.png" alt="Fritzing Pi VLC LiFI" width="2250" height="1459" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/FritzingPiTransceiver_Steckplatine.png 2270w, https://nerd-corner.com/wp-content/uploads/2021/07/FritzingPiTransceiver_Steckplatine-300x195.png 300w, https://nerd-corner.com/wp-content/uploads/2021/07/FritzingPiTransceiver_Steckplatine-1024x664.png 1024w, https://nerd-corner.com/wp-content/uploads/2021/07/FritzingPiTransceiver_Steckplatine-768x498.png 768w, https://nerd-corner.com/wp-content/uploads/2021/07/FritzingPiTransceiver_Steckplatine-1536x996.png 1536w, https://nerd-corner.com/wp-content/uploads/2021/07/FritzingPiTransceiver_Steckplatine-2048x1328.png 2048w" sizes="(max-width: 2250px) 100vw, 2250px" /></p>
<p>For this reason, the Raspberry Pi&#8217;s are connected to both a 5V laser and a 5V solar cell. For the laser the GPIO18 pin was chosen, which corresponds to pin 1 in the &#8220;wiringPi&#8221; library. The &#8220;wiringPi&#8221; library is used in the program code. Directly below GPIO18 is a ground, which is connected to the negative pole of the laser.</p>
<p><img decoding="async" class="aligncenter wp-image-967 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/07/GPIO.png" alt="Datenübertragung mittels Licht Pi" width="1500" height="1125" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/GPIO.png 1600w, https://nerd-corner.com/wp-content/uploads/2021/07/GPIO-300x225.png 300w, https://nerd-corner.com/wp-content/uploads/2021/07/GPIO-1024x768.png 1024w, https://nerd-corner.com/wp-content/uploads/2021/07/GPIO-768x576.png 768w, https://nerd-corner.com/wp-content/uploads/2021/07/GPIO-1536x1152.png 1536w" sizes="(max-width: 1500px) 100vw, 1500px" /></p>
<p>The solar cell provides a corresponding voltage value depending on the light intensity. But since the digital pins of the Raspberry Pi can only recognize 1 and 0, the analog value of the solar cell must be converted into a digital value with the help of a comparator. The process is explained in more detail in the section &#8220;ADC Board with an LM393 Comparator&#8221;. For the wiring, the plus and minus pole of the solar cell is connected to the plus and minus contacts of the ADC board. Then the ground of the ADC board is connected to a Raspberry Pi ground and for the power supply the plus pole of the ADC board is connected to 5V of the Pi. The D0 pin of the ADC board provides the digital value 0 or 1, depending on the light intensity of the solar cell. I connected this pin to GPIO17, which corresponds to pin 0 in the &#8220;wiringPi&#8221; library.</p>
<p>Since I noticed that the Pi gets very hot during operation, I connected a fan. So that the fan is not permanently in operation, which would have a negative effect on the performance of the laser, the fan can be switched on and off by a NPN transistor. Connect the positive pole of the fan directly to a 5V pin of the Raspberry Pi and the negative pole of the fan to the emitter of the NPN transistor. The collector of the transistor is connected to a ground of the Pi. To switch the fan on and off via the transistor, the transistor base is connected to a GPIO pin. For example I chose GPIO27 (corresponds to pin 2 in the &#8220;wiringPi&#8221; library). In the following table the pins of the Pi are compared to the numbering of the &#8220;wiringPi&#8221; library.</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 Datenübertragung mit Licht" width="599" height="295" 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: 599px) 100vw, 599px" /></p>
<h2>ADC Board with a LM393 camparator</h2>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-968 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/07/ADC-LM393.jpg" alt="ADC Board mit LM393 Komparator" width="450" height="319" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/ADC-LM393.jpg 771w, https://nerd-corner.com/wp-content/uploads/2021/07/ADC-LM393-300x213.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/07/ADC-LM393-768x545.jpg 768w, https://nerd-corner.com/wp-content/uploads/2021/07/ADC-LM393-120x85.jpg 120w" sizes="auto, (max-width: 450px) 100vw, 450px" /></p>
<p>The solar cell returns a voltage value depending on the light intensity. Unfortunately the Raspberry Pi has no analog pins to read this voltage value. Therefore the analog signal has to be converted into a digital signal. This is possible with the help of the LM393 comparator. The comparator is often used on ADC boards. Here I simply replaced the original sensor (it was a photoresistor) through a solar cell. With the help of a potentiometer the comparator can be adjusted. That means, as soon as the voltage value of the solar cell, which depends on the light intensity, exceeds the adjusted value of the potentiometer, a digital 1 is measured, otherwise a digital 0.</p>
<h2>Structure of the data frame</h2>
<p><img loading="lazy" decoding="async" class="zoooom aligncenter wp-image-969" src="https://nerd-corner.com/wp-content/uploads/2021/07/MultipleFrames-1.jpg" alt="Aufbau Datenframe Lichtübertragung Daten Datentransfer mittels VLC" width="1300" height="469" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/MultipleFrames-1.jpg 1409w, https://nerd-corner.com/wp-content/uploads/2021/07/MultipleFrames-1-300x108.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/07/MultipleFrames-1-1024x369.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/07/MultipleFrames-1-768x277.jpg 768w" sizes="auto, (max-width: 1300px) 100vw, 1300px" /></p>
<p>The data frame for sending the text messages using visual light communication (Link: <a href="https://nerd-corner.com/sending-text-messages-with-visible-light-communication/" target="_blank" rel="noopener">https://nerd-corner.com/sending-text-messages-with-visible-light-communication/ </a>) consisted of a preamble, the length of the text message, the text content and the cyclic redundancy check. However, to be able to send all kinds of data instead of text messages, the file name, the file extension, the total number of packets and the number of the current packet must be specified instead of the length of the text message. Then the data content and the code of the cyclic redundancy check can be added.</p>
<h2>Software code for data transfer via VLC</h2>
<p>Basically, the receiver and sender scripts from the previous project on sending text messages using visual light communication (link: https://nerd-corner.com/de/textnachrichten-mittels-lichtsignale-senden-pi-zu-arduino/ ) were further developed and combined into one single script. Which is applied on both Raspberry Pi&#8217;s. For example, a &#8220;ReadFile&#8221; and &#8220;WriteFile&#8221; function was added, which can read files and combine and save received data packets to a file. The program was written in C again, because a high speed of data transfer should be achieved. Details about precise programming in C for fast data transfer are given in this article: <a href="https://nerd-corner.com/how-to-program-a-highly-precise-timer-in-c-for-linux/" target="_blank" rel="noopener">https://nerd-corner.com/how-to-program-a-highly-precise-timer-in-c-for-linux/</a> .</p>
<p>The complete software code for data transfer using VLC can be downloaded at the end of the article. The core of the program is again a state machine with the help of which can be selected whether data should be sent or received. In addition, the program automatically turns on the fan when no data transfer is taking place. Important: When compiling please do not forget the &#8220;wiringPi&#8221; library and the &#8220;math.h&#8221; library! The command is: &#8220;gcc -o transceiver transceiver.c -lwiringPi -lm&#8221;.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c" data-enlighter-group="transceiver" data-enlighter-title="transceiver.c">while(1)
    {
        digitalWrite (2, HIGH);
        printf("Press the R button for Receiver Mode or any other key for Sender Moden");
        scanf(" %c",&amp;mode);
        
        if (mode=='R'||mode=='r')
        {
            digitalWrite(2,LOW);
            modeReceiver=true;
        }
        
        if (mode!='R'&amp;&amp;mode!='r')
        {
            digitalWrite(2,LOW);
            modeReceiver=false;
            
            char dataName[NAME_MAX];
            char dataExtension[NAME_MAX];
            
               
            printf("n Name of file WITHOUT extension: ");
            scanf("%s",dataName);

            printf("n Extension: ");
            scanf("%s",dataExtension);

            if (read_file(dataName, dataExtension, file_content) != OK)
            {
                printf("File read error, size exceeds array sizen");
                return -1;
            }
            BuildDataFrame(dataName, dataExtension, file_content);
        }
        
        
        
        while(modeReceiver)
        {
            gettimeofday(&amp;tval_after, NULL);
            timersub(&amp;tval_after, &amp;tval_before, &amp;tval_result);
            double time_elapsed = (double)tval_result.tv_sec + ((double)tval_result.tv_usec/1000000.0f);
            
            while(time_elapsed &lt; 0.001)
            {
                gettimeofday(&amp;tval_after, NULL);
                timersub(&amp;tval_after, &amp;tval_before, &amp;tval_result);
                time_elapsed = (double)tval_result.tv_sec + ((double)tval_result.tv_usec/1000000.0f);
            }
            gettimeofday(&amp;tval_before, NULL);
            
            int data = digitalRead(0);
            
            
            switch (state)
            {
                case 0:
                    //looking for preamble pattern
                    synchro_Done=false;
                    LookForSynchro(data);
                    
                    if (synchro_Done==true)
                    {
                        state=1;
                    }
                    break;
                    
                case 1:
                    //receive the actual data
                    receiveData_Done=false;
                    senderState=false;
                    ReceiveData(data);
                    
                    if(receiveData_Done&amp;&amp;senderState==false)
                    {
                        state=0;
                    }
                    if(senderState==true){
                        senderState=false;
                        state=0;
                        modeReceiver=false;
                        }
                    break;
                  
            }
            
        }
    }</pre>
<h2>Housing</h2>
<p>In order to be able to hold the components in place, a housing was constructed in CAD. This also has the advantage that no complicated alignment of the lasers and the solar cells is necessary for the data transmission. For beginners, <a href="https://www.tinkercad.com/" target="_blank" rel="noopener">TinkerCAD</a> is suitable for housing design. TinkerCAD is free and can be used directly in the browser. Alternatively, the STL files for the 3D printer can also be downloaded here.</p>
<p><img loading="lazy" decoding="async" class="zoooom aligncenter wp-image-970" src="https://nerd-corner.com/wp-content/uploads/2021/07/gehaeuse-CAD.jpg" alt="Datenübertragung per Licht Gehäuse Datentransfer mittels VLC" width="600" height="530" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/gehaeuse-CAD.jpg 682w, https://nerd-corner.com/wp-content/uploads/2021/07/gehaeuse-CAD-300x265.jpg 300w" sizes="auto, (max-width: 600px) 100vw, 600px" /></p>
<p>The housing for data transfer via VLC has an opening for the solar cell and the laser. In addition, an exhaust vent for the fan was constructed and space was also left free for a Raspberry Pi housing. The following picture shows the installation of the components.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-971 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/07/assembly-end-scaled.jpg" alt="Datenübertragung per Licht Lifi VLC" width="2500" height="1875" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/assembly-end-scaled.jpg 2560w, https://nerd-corner.com/wp-content/uploads/2021/07/assembly-end-300x225.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/07/assembly-end-1024x768.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/07/assembly-end-768x576.jpg 768w, https://nerd-corner.com/wp-content/uploads/2021/07/assembly-end-1536x1152.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2021/07/assembly-end-2048x1536.jpg 2048w" sizes="auto, (max-width: 2500px) 100vw, 2500px" /></p>
<h2>Conclusion about data transfer via VLC</h2>
<p>The existing system for sending text messages by means of visual light signals was further developed so that all types of data can now be sent and received. The system works amazingly successfully. It is very robust and achieves a data rate of 1 kbps to 10 kbps. All incoming data packets can be directly assigned due to the intelligent structure of the data frame. Only an acknowledgement signal would be a useful addition. Such a signal would be a feedback from the receiver to the sender to inform the sender that all packets have arrived, or possibly a certain packet was faulty and must be sent again.</p>
<p>Also interesting for the future would be to investigate other types of modulation. In particular, I would like to explore color shift keying, which is specifically designed for visual light communication, and compare the resulting data rates.</p>
<p><img loading="lazy" decoding="async" class="zoooom aligncenter wp-image-972" src="https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-finish-scaled.jpg" alt="Datenübertragung per Licht Gehäuse Lifi VLC Datentransfer mittels VLC" width="2500" height="1125" srcset="https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-finish-scaled.jpg 2560w, https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-finish-300x135.jpg 300w, https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-finish-1024x461.jpg 1024w, https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-finish-768x346.jpg 768w, https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-finish-1536x691.jpg 1536w, https://nerd-corner.com/wp-content/uploads/2021/07/Assembly-finish-2048x922.jpg 2048w" sizes="auto, (max-width: 2500px) 100vw, 2500px" /></p>
<h2>Download files:</h2>
<ul>
<li><a  data-e-Disable-Page-Transition="true" class="download-link" title="" href="https://nerd-corner.com/download/977/?tmstv=1756247595" rel="nofollow" id="download-link-977" data-redirect="false" >
	Softwarecode Transceiver</a>
</li>
<li><a href="https://cults3d.com/en/3d-model/various/visible-light-communication-pi-housing" target="_blank" rel="noopener">STL files housing</a></li>
<li><a  data-e-Disable-Page-Transition="true" class="download-link" title="" href="https://nerd-corner.com/download/991/?tmstv=1756247595" rel="nofollow" id="download-link-991" data-redirect="false" >
	Pi Case with free pins (Creative Common License from Thingiverse)</a>
</li>
</ul>
<p>&nbsp;</p>
<p>The post <a href="https://nerd-corner.com/upgrade-data-transfer-via-vlc-and-lifi-pi-to-pi-transfer/">Upgrade: Data transfer via VLC and LiFi &#8211; Pi to Pi transfer</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nerd-corner.com/upgrade-data-transfer-via-vlc-and-lifi-pi-to-pi-transfer/feed/</wfw:commentRss>
			<slash:comments>8</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=1756247595" 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=1756247595" 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=1756247595" 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>
