<?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>Raspberry Pi Archives &#8211; Make Some Stuff</title>
	<atom:link href="https://makesomestuff.org/tag/raspberry-pi/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>Build Cool Electronics Projects!</description>
	<lastBuildDate>Sat, 27 Sep 2025 21:38:01 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/11/cropped-icon2.png?fit=32%2C32&#038;ssl=1</url>
	<title>Raspberry Pi Archives &#8211; Make Some Stuff</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">165766821</site>	<item>
		<title>IoT Using Raspberry Pi and Firebase and Android</title>
		<link>https://makesomestuff.org/iot-using-raspberry-pi-and-firebase-and-android/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=iot-using-raspberry-pi-and-firebase-and-android</link>
					<comments>https://makesomestuff.org/iot-using-raspberry-pi-and-firebase-and-android/#respond</comments>
		
		<dc:creator><![CDATA[Ahmed Ibrahim]]></dc:creator>
		<pubDate>Thu, 03 Oct 2019 11:32:17 +0000</pubDate>
				<category><![CDATA[Raspberry Pi Projects]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Firebase]]></category>
		<category><![CDATA[IoT]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<guid isPermaLink="false">https://makesomestuff.org/?p=448</guid>

					<description><![CDATA[<p><a href="https://makesomestuff.org">Make Some Stuff</a><br />
<a href="https://makesomestuff.org/iot-using-raspberry-pi-and-firebase-and-android/">IoT Using Raspberry Pi and Firebase and Android</a></p>
<p>Ever asked how to control your home light system wirelessly over the Internet from any place in the world?! in this step-by-step tutorial we will learn how to do that. Used Components Component Name Quantity Raspberry Pi 3 Model B 1 Darlington Transistor TIP 122 3 2-screws Terminal Block 3 1K ohm Resistors 3 3-pins [...]</p>
<p>The post <a href="https://makesomestuff.org/iot-using-raspberry-pi-and-firebase-and-android/">IoT Using Raspberry Pi and Firebase and Android</a> appeared first on <a href="https://makesomestuff.org">Make Some Stuff</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><a href="https://makesomestuff.org">Make Some Stuff</a><br />
<a href="https://makesomestuff.org/iot-using-raspberry-pi-and-firebase-and-android/">IoT Using Raspberry Pi and Firebase and Android</a></p>

<p class="has-regular-font-size wp-block-paragraph">Ever asked how to control your home light system wirelessly over the Internet from any place in the world?! in this step-by-step tutorial we will learn how to do that.</p>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4043148098486780" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-4043148098486780" data-ad-slot="5056799298"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<figure class="aligncenter wp-embed-aspect-16-9 wp-has-aspect-ratio wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube"><div class="wp-block-embed__wrapper">
<iframe title="IoT using Raspberry Pi and firebase and android" width="770" height="433" src="https://www.youtube.com/embed/LoanD1NIfGA?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div><figcaption class="wp-element-caption">Final Project</figcaption></figure>



<h2 class="wp-block-heading">Used Components</h2>



<hr class="wp-block-separator has-css-opacity"/>



<figure class="is-style-regular wp-block-table"><table><tbody><tr><td><strong><span style="text-decoration: underline;">Component Name</span></strong></td><td><strong><span style="text-decoration: underline;">Quantity </span></strong></td></tr><tr><td><a href="https://www.raspberrypi.org/products/raspberry-pi-3-model-b/">Raspberry Pi 3 Model B</a></td><td>1</td></tr><tr><td><a href="https://www.ebay.com/itm/10PCS-TIP122-5A-100V-NPN-TO-220-Darlington-transistor/232424590421?hash=item361d95cc55:g:CI8AAOSwM8ZZeCJC">Darlington Transistor TIP 122 </a></td><td>3</td></tr><tr><td><a href="https://www.sparkfun.com/products/10571">2-screws Terminal Block</a></td><td>3</td></tr><tr><td><a href="https://www.sparkfun.com/products/14492">1K ohm Resistors</a></td><td>3</td></tr><tr><td><a href="https://www.sparkfun.com/products/9609">3-pins slide switch</a></td><td>1</td></tr><tr><td><a href="https://www.sparkfun.com/products/14017">20&#215;2 Female Pin Header </a></td><td>1</td></tr><tr><td><a href="https://www.pcbway.com/project/shareproject/IoT_Using_Raspberry_Pi_and_Firebase_and_Android.html">PCBWay Custom PCB Manufacturing</a></td><td>1</td></tr><tr><td><a href="https://www.ebay.com/itm/5V-12V24V-Lighting-Transformer-5A-10A-Switching-Power-Supply-60W-120W-150W-360W/233343017898?hash=item365453e3aa:m:m5ReQeegdY0R0CweUFJL9RQ">12V 5A Power Supply</a></td><td>1</td></tr><tr><td><a href="https://www.sparkfun.com/products/8431">Male-male Jumper wires</a></td><td>10</td></tr></tbody></table></figure>



<h2 class="wp-block-heading">Used Software</h2>



<hr class="wp-block-separator has-css-opacity"/>



<ul class="wp-block-list">
<li class=""><a href="https://www.autodesk.com/products/eagle/overview">Autodesk Eaglecad</a> (Optional).</li>



<li class=""><a href="https://firebase.google.com/docs/database">Firebase Database</a>.</li>



<li class="">Python Editor (Any Editor will work fine).</li>
</ul>



<h2 class="wp-block-heading">Introduction</h2>



<hr class="wp-block-separator has-css-opacity"/>



<p class="has-regular-font-size wp-block-paragraph">Today, we will learn how to control any RGB LED Strip ambient light wirelessly over Wifi using a custom-built Andoird application connected with the awesome Raspberry Pi board through the Firebase database.</p>



<p class="has-regular-font-size wp-block-paragraph">To build this project we need to deal with some stuff like how to build an android mobile app, how to build a firebase database server, how to connect the raspberry pi and the android app together through firebase, how to take different actions based on the incoming data, some power management, electronics Wiring, &#8230; <br>But yo hold on! Don&#8217;t worry we will cover all these topics in detail in today&#8217;s tutorial. So, bear with me and I promise it will be worth it.</p>



<h2 class="wp-block-heading">Project Overview/Features</h2>



<hr class="wp-block-separator has-css-opacity"/>



<p class="has-regular-font-size wp-block-paragraph">Simply, today we will build a smart device that allows the user to control his/her home ambient lighting system wirelessly over Wifi using any android smartphone, our project is divided into four main parts</p>



<ul class="wp-block-list">
<li class=""><strong>Android mobile application.<br></strong>the mobile app is the control panel which the user will interact with to send his/her commands to the lighting system.</li>



<li class=""><strong>Database.</strong><br>is the global server which acts as a postman who takes mails from one person to deliver it to someone else. Firebase database will receive some data from the mobile app and send it to the raspberry pi to take some actions like changing the LED strip light intensity or light color, and other many stuff.</li>



<li class=""><strong>Electronic and control circuit.</strong><br>the control circuit will be based on the raspberry pi board which running a python script reading the incoming data from the firebase database and according to these data will take some different actions.</li>



<li class=""><strong>Power management.</strong><br>it&#8217;s the most crucial part, it&#8217;s the part which responsible for providing the device with the necessary power to operate properly without damages.</li>
</ul>



<h2 class="wp-block-heading">How does the project work?</h2>



<hr class="wp-block-separator has-css-opacity"/>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="433" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/project-working-logic.png?resize=770%2C433&#038;ssl=1" alt="Project Working Logic" class="wp-image-461" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/project-working-logic.png?w=1920&amp;ssl=1 1920w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/project-working-logic.png?resize=800%2C450&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/project-working-logic.png?resize=300%2C169&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/project-working-logic.png?resize=768%2C432&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/project-working-logic.png?resize=1024%2C576&amp;ssl=1 1024w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/project-working-logic.png?resize=1026%2C577&amp;ssl=1 1026w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/project-working-logic.png?resize=675%2C380&amp;ssl=1 675w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/project-working-logic.png?w=1540&amp;ssl=1 1540w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Project Working Logic</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">Simply, the mobile app and the raspberry pi board are connected to the same firebase database. this database saves the data which comes from the mobile app and syncs it with the raspberry pi board in milliseconds, according to these data the raspberry pi board will take some specific actions like turning on the light, changing its brightness, and so on.</p>



<h2 class="wp-block-heading">Control Three LEDs brightness using GPIO PWM</h2>



<hr class="wp-block-separator has-css-opacity"/>



<p class="has-regular-font-size wp-block-paragraph">To control the RGB LED Strip light brightness you need to be familiar with the PWM technique in the raspberry pi world and how to use it. So, let&#8217;s start by a simple one and start controlling some normal 5mm LEDs brightness to get familiar with the PWM technique. As I promised you at the beginning of the tutorial, we will start it from scratch to understand every part of the project.</p>



<p class="has-regular-font-size wp-block-paragraph">PWM stands for &#8220;Pulse Width Modulation&#8221; which is used to generate analog values using a digital technique. PWM is usually used to control LEDs brightness, DC Motor speed control, Servo motor rotation angle and that happens by outputting some variable voltage level.<br><br>But as we all know that the RPi and any computer is entirely digital system. But at the same time, we need to generate some analog signals from it. So, we need to find a way to convert that digital output signal to an analog output signal. Here comes the PWM technique!</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="214" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/pwm-signal.png?resize=770%2C214&#038;ssl=1" alt="PWM signal Chart" class="wp-image-466" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/pwm-signal.png?w=815&amp;ssl=1 815w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/pwm-signal.png?resize=800%2C223&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/pwm-signal.png?resize=300%2C84&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/pwm-signal.png?resize=768%2C214&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/pwm-signal.png?resize=675%2C188&amp;ssl=1 675w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">PWM signal Chart</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">Most of the devices around us are responding relatively in the world of electronics slowly to the signal that they are getting. So, let&#8217;s take a normal DC motor as an example, let&#8217;s say that we need to run this DC motor at its half speed. So, we need to give it half of its voltage to run at half of its speed. Basically, we are only capable of giving a 3.3V(logic 1) or 0V (logic 0) we can&#8217;t give value in between because it&#8217;s a digital system as we said before. But here comes the PWM role to modulate the signal up(3.3V) for half the time and down(0V) for half the time with a square wave which is called the <strong>duty cycle</strong>. that process happens very very rapidly and the motor can&#8217;t respond instantaneously to the change of the voltage so it takes some time to accelerate and decelerate which results, the motor averaging the voltage to something near 1.6V and will run at half of its speed. And you can change the motor speed by changing the duty cycle value.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="542" height="342" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Duty_Cycle_Examples.png?resize=542%2C342&#038;ssl=1" alt="Duty cycle value change" class="wp-image-469" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Duty_Cycle_Examples.png?w=542&amp;ssl=1 542w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Duty_Cycle_Examples.png?resize=300%2C189&amp;ssl=1 300w" sizes="auto, (max-width: 542px) 100vw, 542px" /><figcaption class="wp-element-caption">Duty cycle value change</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">If we take a normal LED as an example we will do the same previous process applying PWM, but because the LED is a simple diode it responds fairly quickly (faster than the motor) to the change of the signal, so your eyes as a human will make the averaging thing. As a result, you will see the LED changing its brightness.</p>



<ul class="wp-block-list">
<li class=""><strong>Period:</strong> It&#8217;s the sum of the HIGH(3.3V) time and the LOW(0V) time.</li>



<li class=""><strong>Duty Cycle: </strong>Its the percentage of time where the signal was HIGH(3.3V) during the time of period.</li>
</ul>



<p class="has-regular-font-size wp-block-paragraph">Enough Theory! Let&#8217;s make some stuff. Let&#8217;s take a look at the wiring diagram.</p>



<h4 class="wp-block-heading">Wiring Diagram</h4>



<hr class="wp-block-separator has-css-opacity"/>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="923" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/three_LED_PWM.png?resize=770%2C923&#038;ssl=1" alt="Wiring Diagram" class="wp-image-473" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/three_LED_PWM.png?w=1116&amp;ssl=1 1116w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/three_LED_PWM.png?resize=800%2C959&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/three_LED_PWM.png?resize=250%2C300&amp;ssl=1 250w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/three_LED_PWM.png?resize=768%2C921&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/three_LED_PWM.png?resize=854%2C1024&amp;ssl=1 854w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/three_LED_PWM.png?resize=1026%2C1230&amp;ssl=1 1026w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/three_LED_PWM.png?resize=675%2C809&amp;ssl=1 675w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Wiring Diagram</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">The wiring diagram is very simple, connect each LED on a different PWM pin</p>



<figure class="is-style-stripes wp-block-table"><table><tbody><tr><td>Red LED</td><td>GPIO 12(PWM0)</td></tr><tr><td>Green LED</td><td>GPIO 18(PWM0)</td></tr><tr><td>Blue LED</td><td>GPIO 19(PWM1)</td></tr></tbody></table></figure>



<p class="has-regular-font-size wp-block-paragraph">The raspberry pi has two different schemes in numbering its GPIO pins. you can use either pin numbers<strong>(BOARD)</strong> or the Broadcom GPIO pin numbers<strong>(BCM)</strong>. <strong>You can only use one numbering scheme in each program</strong>.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="803" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/pi3_gpio_z4Rfmm2PRu.png?resize=770%2C803&#038;ssl=1" alt="RPi GPIO Pinout" class="wp-image-475" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/pi3_gpio_z4Rfmm2PRu.png?w=920&amp;ssl=1 920w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/pi3_gpio_z4Rfmm2PRu.png?resize=800%2C835&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/pi3_gpio_z4Rfmm2PRu.png?resize=288%2C300&amp;ssl=1 288w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/pi3_gpio_z4Rfmm2PRu.png?resize=768%2C801&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/pi3_gpio_z4Rfmm2PRu.png?resize=675%2C704&amp;ssl=1 675w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">RPi GPIO Pinout</figcaption></figure>
</div>


<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4043148098486780" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-4043148098486780" data-ad-slot="5056799298"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">GPIO Board: Referring to the pin by its number of the plug, the pin number on the physical board which printed on it. Example: PIN#1, PIN#2, …..<br>GPIO BCM: Referring to the pin by its &#8220;Broadcom SOC Channel&#8221; number, these are the numbers after the GPIO word. Example: GPIO12, GPIO19, ….</p>



<p class="wp-block-paragraph">Neither way is wrong, both ways are good and work well without any differences. You have to pick the one which you feel comfortable more with.</p>



<p class="has-regular-font-size wp-block-paragraph">The <strong>Raspberry Pi 3 Model B</strong> has two PWM channels (PWM0, PWM1) each channel has two different GPIO PWM pins available for use. </p>



<figure class="wp-block-table"><table><tbody><tr><td><strong>GPIO BCM</strong></td><td><strong>GPIO BOARD</strong></td><td><strong>PWM channel</strong></td></tr><tr><td>GPIO12</td><td>Pin#32</td><td>PWM0</td></tr><tr><td>GPIO18</td><td>Pin#12</td><td>PWM0</td></tr><tr><td>GPIO19</td><td>Pin#35</td><td>PWM1</td></tr><tr><td>GPIO13</td><td>pin#33</td><td>PWM1</td></tr></tbody></table></figure>



<p class="has-regular-font-size wp-block-paragraph">These three PWM pins <strong>GPIO12, GPIO 13, GPIO19</strong> are used by the <strong>A/V output audio jack</strong>. So, if you don&#8217;t need to use the A/V audio jack in your project, these three GPIO PWM pins will be free and available to get used. But you can&#8217;t use the A/V output Audio jack and these PWM pins at the same time. In today&#8217;s project, we don&#8217;t need to use the A/V audio jack so all the PWM pins will be free and available for us to use.</p>



<h4 class="wp-block-heading">Code </h4>



<hr class="wp-block-separator has-css-opacity"/>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">import RPi.GPIO as GPIO             #import the raspberry pi GPIO library, to be able to use them.
from time import sleep              #import the sleep library, which responsible to do the timing stuff.


redLED = 18				#red LED connected on PWM pin GPIO18
blueLED = 12            #blue LED connected on PWM pin GPIO12
greenLED = 19           #green LED connected on PWM pin GPIO19

GPIO.setwarnings(False)			#disable warnings
GPIO.setmode(GPIO.BCM)	        #set pin numbering system to the (Broadcom chip channel numbering).

GPIO.setup(redLED,GPIO.OUT)     #set the red LED pin(GPIO18) to an output pin.
GPIO.setup(blueLED,GPIO.OUT)    #set the blue LED pin(GPIO12) to an output pin.
GPIO.setup(greenLED,GPIO.OUT)   #set the green LED pin(GPIO19) to an output pin.

red_pwm = GPIO.PWM(redLED,1000)	       	      #create PWM instance with 1000Hz frequency.
blue_pwm = GPIO.PWM(blueLED,1000)             #create PWM instance with 1000Hz frequency.
green_pwm = GPIO.PWM(greenLED,1000)           #create PWM instance with 1000Hz frequency.

red_pwm.start(0)				              #start red LED PWM pin with 0% initial Duty Cycle (OFF).
blue_pwm.start(0)                             #start blue LED PWM pin with 0% initial Duty Cycle (OFF).
green_pwm.start(0)                            #start green LED PWM pin with 0% initial Duty Cycle (OFF).

print("AH Shit! Here we go again! Press CTRL+C to exit")    #Take Care, Meme LORD.

try:
    while True:                                         #the start of the actual program.
        for duty in range(0,101,1):                     #imolement a "for loop" responsible for increasing the red LED light brightness.
            red_pwm.ChangeDutyCycle(duty)               #provide duty cycle in the range 0-100.
            sleep(0.01)                                 #wait 0.01 sec. between each iteration.
        sleep(0.5)                                      #wait 0.5 sec. after the "for loop" is done.

        for duty in range(100,-1,-1):                   #implement a "for loop" responsible for decreasing the red LED light brightness.
            red_pwm.ChangeDutyCycle(duty)               #provide duty cycle in the range 100-0.
            sleep(0.01)                                 #wait 0.01 sec. between each iteration.
        sleep(0.5)                                      #wait 0.5 sec. after the "for loop" is done.
		
        for duty in range (0, 101, 1):                  #repeat the previous logic but this time with the blue LED.
            blue_pwm.ChangeDutyCycle(duty)
            sleep(0.01)
        sleep(0.5)

        for duty in range (100, -1, -1):                #repeat the previous logic but this time with the blue LED.
            blue_pwm.ChangeDutyCycle(duty)
            sleep(0.01)
        sleep(0.5)

        for duty in range(0,101,1):                     #repeat the previous logic but this time with the green LED.
            green_pwm.ChangeDutyCycle(duty)
            sleep(0.01)
        sleep(0.5)

        for duty in range(100,-1,-1):                   #repeat the previous logic but this time with the green LED.
            green_pwm.ChangeDutyCycle(duty)
            sleep(0.01)
        sleep(0.5)

except KeyboardInterrupt: 		# If CTRL+C is pressed, exit cleanly:
    red_pwm.stop() 			    # stop red PWM
    blue_pwm.stop()             # stop blue PWM
    green_pwm.stop()            # stop green  PWM
    GPIO.cleanup() 	            # cleanup all GPIO</pre>



<h4 class="wp-block-heading">Code Explanation</h4>



<hr class="wp-block-separator has-css-opacity"/>



<p class="has-regular-font-size wp-block-paragraph">The code is pretty simple and straightforward, first, we need to import two important modules to allow us to use the raspberry pi GPIO pins. Also, import the <strong>time</strong> module that will make the timing work for us. without importing this module you will not be able to use the <code>sleep()</code> method.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">import RPi.GPIO as GPIO
from time import sleep</pre>



<p class="has-regular-font-size wp-block-paragraph">then we need to initialize three variables called <code>redLED</code>, <code>blueLED</code>, <code>greenLED</code> referring to the three PWM pins that we will use to control our LEDs. Yeah as you noticed we are using the <strong>GPIO BCM</strong> <strong>numbering scheme</strong>.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">redLED = 18
blueLED = 12
greenLED = 19</pre>



<p class="has-regular-font-size wp-block-paragraph">Then we need to set the numbering scheme of raspberry pi pins to &#8220;GPIO BCM&#8221;, then set all the three pins as output pins.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">GPIO.setmode(GPIO.BCM)

GPIO.setup(redLED,GPIO.OUT)
GPIO.setup(blueLED,GPIO.OUT)
GPIO.setup(greenLED,GPIO.OUT)</pre>



<p class="has-regular-font-size wp-block-paragraph">create three PWM instances(instance for each pin) <code>red_pwm</code>, <code>blue_pwm</code>, <code>green_pwm </code>with 1000Hz frequency that will help us to generate the PWM signal. After that, we need to set the initial state of these pins to 0% duty cycle which means that the three pins will be OFF at the beginning of the program.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">red_pwm = GPIO.PWM(redLED,1000)
blue_pwm = GPIO.PWM(blueLED,1000)
green_pwm = GPIO.PWM(greenLED,1000)

red_pwm.start(0)
blue_pwm.start(0)
green_pwm.start(0)</pre>



<p class="has-regular-font-size wp-block-paragraph">Here is the fun part! inside the <code>while loop</code> we write the set of commands(program) that we need to keep executing forever until we force-stop it.<br><br>inside the <code>while loop</code> implement a &#8220;for loop&#8221; it&#8217;s initial value 0, at every iteration it will increment by 1 until it reaches 100. This <code>for loop</code> responsible for increasing the red LED light brightness.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">while True:                                       
    for duty in range(0,101,1):
        red_pwm.ChangeDutyCycle(duty)
        sleep(0.01)
    sleep(0.5)</pre>



<p class="has-regular-font-size wp-block-paragraph">The second <code>for loop</code> it&#8217;s initial value 100, at every iteration will decrease by 1 until it reaches 0. this <code>for loop</code> is responsible for decreasing the red LED light brightness.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">    for duty in range(100,-1,-1):
        red_pwm.ChangeDutyCycle(duty)
        sleep(0.01)
    sleep(0.5)</pre>



<p class="has-regular-font-size wp-block-paragraph">then repeat the previous logic with the remaining two LEDs. After finishing your code, close and save it, run it by writing <code>python fileName.py</code> in the terminal. </p>



<p class="has-regular-font-size wp-block-paragraph">After running it, It&#8217;s expected to see this sentence got printed on the terminal <code>AH Shit! Here we go again! Press CTRL+C to exit</code> then the three LEDs light brightness will start to increase and decrease. </p>



<p class="has-regular-font-size wp-block-paragraph">I will assume that you did that and it&#8217;s working fine with you. VOILA! Officially you are now promoted to the next level. Let&#8217;s make it more interesting and control the beefy RGB LED Strip.</p>



<h2 class="wp-block-heading">Control RGB LED Strip Lighting  </h2>



<hr class="wp-block-separator has-css-opacity"/>



<p class="has-regular-font-size wp-block-paragraph">Actually, controlling an RGB LED it&#8217;s not very different from controlling a normal LED. RGB LED means red, green and blue LED which combines all these three LEDs in one combo. with these three different colors, you can produce almost any color by mixing them with different intensities. To adjust LED intensity we use the PWM technique.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="192" height="192" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/RGB.png?resize=192%2C192&#038;ssl=1" alt="single RGB LED" class="wp-image-496" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/RGB.png?w=192&amp;ssl=1 192w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/RGB.png?resize=100%2C100&amp;ssl=1 100w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/RGB.png?resize=150%2C150&amp;ssl=1 150w" sizes="auto, (max-width: 192px) 100vw, 192px" /><figcaption class="wp-element-caption">single RGB LED</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">For example, to generate a pure red color, we need to set the red LED to the highest intensity and the green, blue to the lowest intensity. To generate a white color we have to set all the three LEDs to the highest intensity. And By adjusting the intensity of each LED you will generate a new color.</p>



<h4 class="wp-block-heading">RGB LED Strip pinout</h4>



<hr class="wp-block-separator has-css-opacity"/>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="500" height="203" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/led_strips_astripend_t.jpg?resize=500%2C203&#038;ssl=1" alt="RGB LED Strip pinout" class="wp-image-501" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/led_strips_astripend_t.jpg?w=500&amp;ssl=1 500w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/led_strips_astripend_t.jpg?resize=300%2C122&amp;ssl=1 300w" sizes="auto, (max-width: 500px) 100vw, 500px" /><figcaption class="wp-element-caption">RGB LED Strip pinout</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">There are two main types of RGB LED strips. The common anode, and the common cathode. In the common anode RGB LED strip, the three LEDs share the same positive lead <strong>(Anode)</strong>, and in the common cathode RGB LED strip, the three LEDs share the same negative lead <strong>(Cathode)</strong>. As a result of that, the RGB LED strip has four leads, one for each LED (red, green, blue) and one common anode or common cathode.</p>



<p class="has-regular-font-size wp-block-paragraph">The RGB LED strip that we will use today is Common Anode.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="433" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/common-anode-and-common-cathode.png?resize=770%2C433&#038;ssl=1" alt="Difference between the common anode and common cathode" class="wp-image-503" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/common-anode-and-common-cathode.png?w=1920&amp;ssl=1 1920w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/common-anode-and-common-cathode.png?resize=800%2C450&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/common-anode-and-common-cathode.png?resize=300%2C169&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/common-anode-and-common-cathode.png?resize=768%2C432&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/common-anode-and-common-cathode.png?resize=1024%2C576&amp;ssl=1 1024w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/common-anode-and-common-cathode.png?resize=1026%2C577&amp;ssl=1 1026w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/common-anode-and-common-cathode.png?resize=675%2C380&amp;ssl=1 675w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/common-anode-and-common-cathode.png?w=1540&amp;ssl=1 1540w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Difference between the common anode and common cathode</figcaption></figure>
</div>


<h4 class="wp-block-heading">Power Management</h4>



<hr class="wp-block-separator has-css-opacity"/>



<p class="has-regular-font-size wp-block-paragraph">Before we connect the RGB LED strip with raspberry pi we need to ask ourselves, Does the raspberry pi board able to provide the beefy RGB LED strip with the needed power to operate properly? The short answer is, of course not. </p>



<p class="has-regular-font-size wp-block-paragraph">If you are a math nerd let&#8217;s do some calculations. we need to know how much current our RGB LED Strip is going to draw. each RGB cell contains three LEDs<strong>(red, green, blue)</strong> each LED in the cell draws <strong>20mA</strong> at full intensity. So, each RGB cell will draw a current of total <strong>60mA</strong> at full intensity, the RGB LED Strip that we are using today contains <strong>20 cells/one meter</strong>, and we have a <strong>4-meter long strip</strong>. So, Which means that the total drawn current at maximum intensity is equal to:<br><strong><em>4(Meter)*20(cell/meter)*60(mA) = 4800MA.</em></strong></p>



<p class="has-regular-font-size wp-block-paragraph">this amount of drawn current will vary depending on the intensity of the LED brightness that you are working with, but we made the calculations at the highest values to work freely and be on the safe side. Now we need a power source that can provide us with those <strong>4.8A</strong> at <strong>12V</strong>.</p>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4043148098486780" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-4043148098486780" data-ad-slot="5056799298"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-regular-font-size wp-block-paragraph">The best option I found for that job, is a power supply/converter that converts an AC power to DC, the power supply/converter that we will use today offers 5A at 12VDC which is exactly what we need.</p>



<h4 class="wp-block-heading">The Power Supply Connections</h4>



<hr class="wp-block-separator has-css-opacity"/>



<p class="has-regular-font-size wp-block-paragraph">A power supply is an electrical device that converts one type of electrical type to another. In our case, we will convert a 220VAC to 12VDC.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="578" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/IMG_1686.jpg?resize=770%2C578&#038;ssl=1" alt="The power supply pinout" class="wp-image-511" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/IMG_1686.jpg?w=2048&amp;ssl=1 2048w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/IMG_1686.jpg?resize=600%2C450&amp;ssl=1 600w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/IMG_1686.jpg?resize=800%2C600&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/IMG_1686.jpg?resize=300%2C225&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/IMG_1686.jpg?resize=768%2C576&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/IMG_1686.jpg?resize=1024%2C768&amp;ssl=1 1024w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/IMG_1686.jpg?resize=1026%2C770&amp;ssl=1 1026w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/IMG_1686.jpg?resize=675%2C506&amp;ssl=1 675w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/IMG_1686.jpg?resize=480%2C360&amp;ssl=1 480w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/IMG_1686.jpg?w=1540&amp;ssl=1 1540w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">The power supply pinout</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">From the left side, the first three terminals are the input from the AC power source:</p>



<ul class="wp-block-list">
<li class=""><strong>L:</strong> life.</li>



<li class=""><strong>N:</strong> neutral.</li>



<li class=""><strong>GND:</strong> earth.</li>
</ul>



<p class="has-regular-font-size wp-block-paragraph">The last four terminals are the 12VDC output, the first two terminals are the <strong>GND</strong> and the second two terminals are <strong>positive</strong>.</p>



<ul class="wp-block-list">
<li class=""><strong>V-:</strong> GND.</li>



<li class=""><strong>V+:</strong> positive.</li>
</ul>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="578" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/IMG_1681.jpg?resize=770%2C578&#038;ssl=1" alt="Power Supply Connections" class="wp-image-508" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/IMG_1681.jpg?w=1170&amp;ssl=1 1170w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/IMG_1681.jpg?resize=600%2C450&amp;ssl=1 600w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/IMG_1681.jpg?resize=800%2C600&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/IMG_1681.jpg?resize=300%2C225&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/IMG_1681.jpg?resize=768%2C576&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/IMG_1681.jpg?resize=1024%2C768&amp;ssl=1 1024w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/IMG_1681.jpg?resize=1026%2C770&amp;ssl=1 1026w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/IMG_1681.jpg?resize=675%2C506&amp;ssl=1 675w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/IMG_1681.jpg?resize=480%2C360&amp;ssl=1 480w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Power Supply Connections</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">And we connect them as follow:</p>



<ul class="wp-block-list">
<li class=""><strong>Brown wire (AC Power source):</strong> L (Power supply).</li>



<li class=""><strong>Blue wire (AC Power source):</strong> N (Power supply).</li>



<li class=""><strong>Green wire (AC Power source):</strong> Earth (Power supply).</li>
</ul>



<p class="has-regular-font-size wp-block-paragraph">And the red, and the black wire are the 12VDC output:</p>



<ul class="wp-block-list">
<li class=""><strong>Red Wire: </strong>12VDC Output (V+).</li>



<li class=""><strong>Black Wire:</strong> GND Output (V-).</li>
</ul>



<h4 class="wp-block-heading">Wiring Diagram</h4>



<hr class="wp-block-separator has-css-opacity"/>



<figure class="wp-block-image"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="568" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/LED-Strip.png?resize=770%2C568&#038;ssl=1" alt="RGB LED Strip wiring diagram" class="wp-image-505" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/LED-Strip.png?w=2048&amp;ssl=1 2048w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/LED-Strip.png?resize=800%2C590&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/LED-Strip.png?resize=300%2C221&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/LED-Strip.png?resize=768%2C566&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/LED-Strip.png?resize=1024%2C755&amp;ssl=1 1024w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/LED-Strip.png?resize=1026%2C756&amp;ssl=1 1026w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/LED-Strip.png?resize=675%2C498&amp;ssl=1 675w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/LED-Strip.png?w=1540&amp;ssl=1 1540w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">RGB LED Strip wiring diagram</figcaption></figure>



<p class="has-regular-font-size wp-block-paragraph">As we stated before, the RGB LED strip needs 4.8A at 12VDC to operate properly. But at the same time, the Raspberry pi board can&#8217;t provide all that power to the RGB LED strip. So, we need a component that can take orders from the Raspberry pi board but provide power from the external 12VDC power supply.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="770" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Tip_122-800x800.jpg?resize=770%2C770&#038;ssl=1" alt="TIP122 NPN Transistor" class="wp-image-517" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Tip_122-800x800.jpg?resize=800%2C800&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Tip_122-800x800.jpg?resize=100%2C100&amp;ssl=1 100w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Tip_122-800x800.jpg?resize=150%2C150&amp;ssl=1 150w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Tip_122-800x800.jpg?resize=300%2C300&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Tip_122-800x800.jpg?resize=768%2C768&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Tip_122-800x800.jpg?resize=675%2C675&amp;ssl=1 675w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">TIP122 NPN Transistor</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">Here comes the TIP122 Darlington transistor, this transistor can drive high power loads by using a small amount of current and voltage.</p>



<p class="has-regular-font-size wp-block-paragraph">The TIP122 transistor can handle current up to 5A<strong>(Continous)</strong> and 8A<strong>(Peak)</strong> which satisfies our needs.</p>



<h4 class="wp-block-heading">TIP122 Transistor Pinout</h4>



<hr class="wp-block-separator has-css-opacity"/>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="450" height="461" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/TIP122-Darlington-NPN-Transistor.jpg?resize=450%2C461&#038;ssl=1" alt="TIP122 pinout" class="wp-image-516" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/TIP122-Darlington-NPN-Transistor.jpg?w=450&amp;ssl=1 450w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/TIP122-Darlington-NPN-Transistor.jpg?resize=293%2C300&amp;ssl=1 293w" sizes="auto, (max-width: 450px) 100vw, 450px" /><figcaption class="wp-element-caption">TIP122 pinout</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">TIP122 Transistor acts like a switch that can drive loads with higher electrical requirements, so by a small amount of current and voltage can drive a high power load, at this example we gonna use the TIP122 which completes the LED strip circuit with the 12-volt power supply, the TIP122 has three legs(base, collector, emitter). The collector will get connected to the load(LED strip), and the emitter will get connected to the ground. And by a small amount of current on the base pin, will close the circuit between the collector and the emitter.</p>



<h2 class="wp-block-heading">Make it More Professional</h2>



<hr class="wp-block-separator has-css-opacity"/>



<p class="has-regular-font-size wp-block-paragraph">What about transferring our breadboard circuit to a professional <strong>printed circuit board&nbsp;(PCB)</strong>&nbsp;to make our project more rigid and solid.</p>



<h4 class="wp-block-heading">Raspberry Pi HAT files (PCB)</h4>



<hr class="wp-block-separator has-css-opacity"/>



<p class="wp-block-paragraph">I designed the project circuit using Autodesk Eagle software. all the PCB files are open-source you can access it from that link. We love open source <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<div class="aligncenter wp-block-button"><a class="wp-block-button__link wp-element-button" href="https://www.pcbway.com/project/shareproject/IoT_Using_Raspberry_Pi_and_Firebase_and_Android.html">pcb files</a></div>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="337" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/two-layers.png?resize=770%2C337&#038;ssl=1" alt="PCB bottom and top layer" class="wp-image-645" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/two-layers.png?w=1170&amp;ssl=1 1170w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/two-layers.png?resize=800%2C350&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/two-layers.png?resize=300%2C131&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/two-layers.png?resize=768%2C336&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/two-layers.png?resize=1024%2C448&amp;ssl=1 1024w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">PCB bottom and the top layer</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph"><strong>You can order your own PCB From&nbsp;<a href="https://www.pcbway.com/">PCBWay</a>&nbsp;company these guys have a very good reputation in this field and they ship to more than 170 countries around the world with reasonable prices. all you have to do is to open the project&nbsp;PCB files link&nbsp;and click “Add to cart”. That’s it!</strong></p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="357" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-03-at-3.52.38-AM.png?resize=770%2C357&#038;ssl=1" alt="PCB Files" class="wp-image-648" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-03-at-3.52.38-AM.png?w=1170&amp;ssl=1 1170w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-03-at-3.52.38-AM.png?resize=800%2C371&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-03-at-3.52.38-AM.png?resize=300%2C139&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-03-at-3.52.38-AM.png?resize=768%2C356&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-03-at-3.52.38-AM.png?resize=1024%2C475&amp;ssl=1 1024w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">PCB Files</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">This PCB can get mounted over the Raspberry pi board easily as a normal raspberry pi HAT, it will organize your wiring and will make your project easier to debug.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="578" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/IMG_5100.jpg?resize=770%2C578&#038;ssl=1" alt="Custom PCB Raspberry Pi HAT" class="wp-image-678" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/IMG_5100.jpg?w=1170&amp;ssl=1 1170w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/IMG_5100.jpg?resize=600%2C450&amp;ssl=1 600w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/IMG_5100.jpg?resize=800%2C600&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/IMG_5100.jpg?resize=300%2C225&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/IMG_5100.jpg?resize=768%2C576&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/IMG_5100.jpg?resize=1024%2C768&amp;ssl=1 1024w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Custom PCB Raspberry Pi HAT</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">With that slide switch, you can turn on and off the RGB LED Strip power.</p>



<h4 class="wp-block-heading">Raspberry Pi Enclosure</h4>



<hr class="wp-block-separator has-css-opacity"/>



<p class="wp-block-paragraph">I designed a laser cutting enclosure using Autodesk fusion 360, feel free to download the DXF files from that link.</p>



<div class="aligncenter wp-block-button"><a class="wp-block-button__link has-background wp-element-button" href="https://drive.google.com/open?id=1QmRRjlBHuWzjAIe_6h9ZnT-xhDQ9o_yR" style="border-radius:100px;background-color:#00a99d">enclosure files</a></div>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="578" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Raspberry-Pi-Enclosure.jpg?resize=770%2C578&#038;ssl=1" alt="Raspberry Pi Enclosure" class="wp-image-663" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Raspberry-Pi-Enclosure.jpg?w=1170&amp;ssl=1 1170w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Raspberry-Pi-Enclosure.jpg?resize=600%2C450&amp;ssl=1 600w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Raspberry-Pi-Enclosure.jpg?resize=800%2C600&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Raspberry-Pi-Enclosure.jpg?resize=300%2C225&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Raspberry-Pi-Enclosure.jpg?resize=768%2C576&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Raspberry-Pi-Enclosure.jpg?resize=1024%2C768&amp;ssl=1 1024w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Raspberry Pi Enclosure</figcaption></figure>
</div>


<h4 class="wp-block-heading">Code</h4>



<hr class="wp-block-separator has-css-opacity"/>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#We will use the same previous Code without any changes.</pre>



<h4 class="wp-block-heading">Code Explanation</h4>



<hr class="wp-block-separator has-css-opacity"/>



<p class="has-regular-font-size wp-block-paragraph">The same previous explanation since we are using the same code with the same logic.</p>



<p class="has-regular-font-size wp-block-paragraph">After finishing the wiring and your code, close and save it, Run your program by writing <code>python fileName.py</code> in your terminal. Like the last example, After running your program, It&#8217;s expected to see this sentence got printed on the terminal <code>AH Shit! Here we go again! Press CTRL+C to exit</code> then the three LEDs light brightness will start to increase and decrease.</p>



<p class="has-regular-font-size wp-block-paragraph">After getting sure that everything is working as expected, let&#8217;s level it up and build our firebase database.</p>



<h2 class="wp-block-heading">Building The Firebase Database</h2>



<hr class="wp-block-separator has-css-opacity"/>



<p class="has-regular-font-size wp-block-paragraph">The Firebase Realtime Database is a cloud-hosted database. Data is stored as JSON and synchronized in realtime to every connected client. If you want to know more check out <a href="https://firebase.google.com/docs/database">this link</a>. </p>



<p class="has-regular-font-size wp-block-paragraph">As we stated before, the realtime database will receive some data from the mobile app based on the user interaction and will sync it with the raspberry pi in milliseconds. So, to be able to use firebase you need to sign in using your normal Gmail account. then go to your project console to create a new project.</p>



<p class="has-regular-font-size wp-block-paragraph">First things first, you need to create a new project in your console.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="393" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-26-at-6.30.39-PM.png?resize=770%2C393&#038;ssl=1" alt="your console" class="wp-image-523" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-26-at-6.30.39-PM.png?w=2048&amp;ssl=1 2048w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-26-at-6.30.39-PM.png?resize=800%2C409&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-26-at-6.30.39-PM.png?resize=300%2C153&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-26-at-6.30.39-PM.png?resize=768%2C392&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-26-at-6.30.39-PM.png?resize=1024%2C523&amp;ssl=1 1024w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-26-at-6.30.39-PM.png?resize=1026%2C524&amp;ssl=1 1026w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-26-at-6.30.39-PM.png?resize=675%2C345&amp;ssl=1 675w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-26-at-6.30.39-PM.png?w=1540&amp;ssl=1 1540w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">your console</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">Then, give a name to your project</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="388" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/unnamed-file.png?resize=770%2C388&#038;ssl=1" alt="Name Your Project" class="wp-image-524" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/unnamed-file.png?w=2048&amp;ssl=1 2048w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/unnamed-file.png?resize=800%2C404&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/unnamed-file.png?resize=300%2C151&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/unnamed-file.png?resize=768%2C387&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/unnamed-file.png?resize=1024%2C516&amp;ssl=1 1024w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/unnamed-file.png?resize=1026%2C517&amp;ssl=1 1026w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/unnamed-file.png?resize=675%2C340&amp;ssl=1 675w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/unnamed-file.png?w=1540&amp;ssl=1 1540w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Name Your Project</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">We don&#8217;t need to set up google analytics now</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="427" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/firebase-analytics-setup.png?resize=770%2C427&#038;ssl=1" alt="Creating the project" class="wp-image-525" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/firebase-analytics-setup.png?w=2048&amp;ssl=1 2048w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/firebase-analytics-setup.png?resize=800%2C443&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/firebase-analytics-setup.png?resize=300%2C166&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/firebase-analytics-setup.png?resize=768%2C426&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/firebase-analytics-setup.png?resize=1024%2C567&amp;ssl=1 1024w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/firebase-analytics-setup.png?resize=1026%2C569&amp;ssl=1 1026w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/firebase-analytics-setup.png?resize=675%2C374&amp;ssl=1 675w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/firebase-analytics-setup.png?w=1540&amp;ssl=1 1540w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Creating the project</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">After creating your project successfully, your project overview page should look something like this. From the left menu, We need to select &#8220;Database&#8221;</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="387" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-14-at-7.05.15-AM.png?resize=770%2C387&#038;ssl=1" alt="Project overview page" class="wp-image-526" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-14-at-7.05.15-AM.png?w=2048&amp;ssl=1 2048w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-14-at-7.05.15-AM.png?resize=800%2C402&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-14-at-7.05.15-AM.png?resize=300%2C151&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-14-at-7.05.15-AM.png?resize=768%2C386&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-14-at-7.05.15-AM.png?resize=1024%2C515&amp;ssl=1 1024w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-14-at-7.05.15-AM.png?resize=1026%2C516&amp;ssl=1 1026w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-14-at-7.05.15-AM.png?resize=675%2C339&amp;ssl=1 675w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-14-at-7.05.15-AM.png?w=1540&amp;ssl=1 1540w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Project overview page</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">We will choose &#8220;Realtime database&#8221; and click the &#8220;Create Database&#8221; button</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="388" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-14-at-7.05.59-AM.png?resize=770%2C388&#038;ssl=1" alt="Create a Realtime Database" class="wp-image-529" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-14-at-7.05.59-AM.png?w=1170&amp;ssl=1 1170w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-14-at-7.05.59-AM.png?resize=800%2C403&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-14-at-7.05.59-AM.png?resize=300%2C151&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-14-at-7.05.59-AM.png?resize=768%2C387&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-14-at-7.05.59-AM.png?resize=1024%2C516&amp;ssl=1 1024w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-14-at-7.05.59-AM.png?resize=1026%2C517&amp;ssl=1 1026w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-14-at-7.05.59-AM.png?resize=675%2C340&amp;ssl=1 675w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Create a Realtime Database</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">After that, select &#8220;Test Mode&#8221; and click &#8220;Enable&#8221;</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="490" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-14-at-7.06.20-AM.png?resize=770%2C490&#038;ssl=1" alt="Test Mode" class="wp-image-527" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-14-at-7.06.20-AM.png?w=1170&amp;ssl=1 1170w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-14-at-7.06.20-AM.png?resize=800%2C509&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-14-at-7.06.20-AM.png?resize=300%2C191&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-14-at-7.06.20-AM.png?resize=768%2C489&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-14-at-7.06.20-AM.png?resize=1024%2C652&amp;ssl=1 1024w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-14-at-7.06.20-AM.png?resize=1026%2C653&amp;ssl=1 1026w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/Screen-Shot-2019-09-14-at-7.06.20-AM.png?resize=675%2C430&amp;ssl=1 675w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Test Mode</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">Now, your Realtime database should look something like this.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="387" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-dfShot-2019-09-14-at-7.06.40-AM.png?resize=770%2C387&#038;ssl=1" alt="Your Database dashboard" class="wp-image-667" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-dfShot-2019-09-14-at-7.06.40-AM.png?w=1170&amp;ssl=1 1170w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-dfShot-2019-09-14-at-7.06.40-AM.png?resize=800%2C402&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-dfShot-2019-09-14-at-7.06.40-AM.png?resize=300%2C151&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-dfShot-2019-09-14-at-7.06.40-AM.png?resize=768%2C386&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-dfShot-2019-09-14-at-7.06.40-AM.png?resize=1024%2C515&amp;ssl=1 1024w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption"><em>Your Database dashboard</em></figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">After building the Realtime Database, we need to build the mobile app that will send the data to the firebase database.</p>



<h2 class="wp-block-heading"> Building The Android Mobile APP</h2>



<hr class="wp-block-separator has-css-opacity"/>



<p class="has-regular-font-size wp-block-paragraph">Now we need to build the mobile app that the user will use to control the RGB LED Strip from, we used the amazing tool the &#8220;MIT APP Inventor&#8221; to build it. It&#8217;s fast and very easy to use.</p>



<p class="has-regular-font-size wp-block-paragraph">App inventor lets you develop android mobile applications using a web browser and a physical mobile phone or just the emulator, the MIT app inventor saves your projects in their clouds to keep tracking your work</p>



<p class="has-regular-font-size wp-block-paragraph">First, you need to go to the MIT app inventor <a href="http://appinventor.mit.edu/explore/">official website</a> and login with your Gmail account, then press on the “create apps” button, then start building your mobile app. Easy HA!</p>



<p class="has-regular-font-size wp-block-paragraph">To build your mobile app using the app inventor tool, you should deal with two main parts</p>



<ul class="wp-block-list">
<li class="">The design of the app.</li>



<li class="">The programming of the app.</li>
</ul>



<h4 class="wp-block-heading">The App Design</h4>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="320" height="480" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/SC20190923-190644.png?resize=320%2C480&#038;ssl=1" alt="The app design" class="wp-image-593" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/SC20190923-190644.png?w=320&amp;ssl=1 320w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/09/SC20190923-190644.png?resize=200%2C300&amp;ssl=1 200w" sizes="auto, (max-width: 320px) 100vw, 320px" /><figcaption class="wp-element-caption">The app design</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">The mobile application consists of <strong>Six buttons</strong> to control the lighting mode(Mode One, Mode Two, &#8230;), <strong>three sliders</strong> to control each LED color lighting intensity, and a <strong>button</strong> named<strong> &#8220;power button&#8221; </strong>to control the state of the LEDs(turning it ON or OFF). The most important part here is to add the &#8220;firebaseDB&#8221; client components to the app to allow us sending data to our firebase database project that we created before.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="283" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.42.44-PM.png?resize=770%2C283&#038;ssl=1" alt="Adding the FirebaseDB component to the app" class="wp-image-598" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.42.44-PM.png?w=1066&amp;ssl=1 1066w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.42.44-PM.png?resize=800%2C294&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.42.44-PM.png?resize=300%2C110&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.42.44-PM.png?resize=768%2C282&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.42.44-PM.png?resize=1024%2C377&amp;ssl=1 1024w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Adding the FirebaseDB component to the app</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">After adding the &#8220;FirebaseDB&#8221; component to the app, we need to put our created Firebase database URL to the mobile application &#8220;FirebaseDB&#8221; component to specify where does the data will get saved, the Firebase database URL can be found here.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="200" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.45.42-PM-1.png?resize=770%2C200&#038;ssl=1" alt="Firebase database URL" class="wp-image-601" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.45.42-PM-1.png?w=1170&amp;ssl=1 1170w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.45.42-PM-1.png?resize=800%2C208&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.45.42-PM-1.png?resize=300%2C78&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.45.42-PM-1.png?resize=768%2C200&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.45.42-PM-1.png?resize=1024%2C266&amp;ssl=1 1024w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Firebase database URL</figcaption></figure>
</div>

<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="512" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.49.31-PM.png?resize=770%2C512&#038;ssl=1" alt="Connecting the app with the firebase" class="wp-image-600" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.49.31-PM.png?w=1038&amp;ssl=1 1038w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.49.31-PM.png?resize=800%2C532&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.49.31-PM.png?resize=300%2C199&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.49.31-PM.png?resize=768%2C511&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.49.31-PM.png?resize=1024%2C681&amp;ssl=1 1024w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.49.31-PM.png?resize=270%2C180&amp;ssl=1 270w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.49.31-PM.png?resize=370%2C245&amp;ssl=1 370w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Connecting the app with the firebase</figcaption></figure>
</div>


<h4 class="wp-block-heading">The Programming Of The App</h4>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="746" height="1066" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-09-26-at-7.13.08-PM.png?resize=746%2C1066&#038;ssl=1" alt="The App Code" class="wp-image-596" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-09-26-at-7.13.08-PM.png?w=746&amp;ssl=1 746w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-09-26-at-7.13.08-PM.png?resize=210%2C300&amp;ssl=1 210w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-09-26-at-7.13.08-PM.png?resize=717%2C1024&amp;ssl=1 717w" sizes="auto, (max-width: 746px) 100vw, 746px" /><figcaption class="wp-element-caption">The App Code</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">After designing the interface of our app we need to give it life, adding some functionality to each button and slider.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="215" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.39.02-PM.png?resize=770%2C215&#038;ssl=1" alt="sending data to the database" class="wp-image-597" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.39.02-PM.png?w=1062&amp;ssl=1 1062w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.39.02-PM.png?resize=800%2C223&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.39.02-PM.png?resize=300%2C84&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.39.02-PM.png?resize=768%2C214&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.39.02-PM.png?resize=1024%2C285&amp;ssl=1 1024w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">sending data to the database</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">Let&#8217;s take the <strong>&#8220;Mode One&#8221;</strong> button as an example to see how the logic works. When the user clicks on the &#8220;Mode One&#8221; button it will send the value <strong>&#8220;mode1&#8221;</strong> with the tag <strong>&#8220;lightMode&#8221;</strong> to the firebase database project that we created before. and if we opened the firebase database dashboard page we will see that new entry got added to our database. <strong>Congrats!</strong></p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="142" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-7.01.37-PM-1.png?resize=770%2C142&#038;ssl=1" alt="" class="wp-image-606" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-7.01.37-PM-1.png?w=1170&amp;ssl=1 1170w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-7.01.37-PM-1.png?resize=800%2C148&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-7.01.37-PM-1.png?resize=300%2C55&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-7.01.37-PM-1.png?resize=768%2C142&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-7.01.37-PM-1.png?resize=1024%2C189&amp;ssl=1 1024w" sizes="auto, (max-width: 770px) 100vw, 770px" /></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">But, when the user clicks the <strong>&#8220;Mode Two&#8221;</strong> button the &#8220;lightMode&#8221; tag value will get updated to the new value which in this case will be <strong>&#8220;mode2&#8221;</strong>.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="199" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-7.04.40-PM.png?resize=770%2C199&#038;ssl=1" alt="Mode Two button" class="wp-image-607" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-7.04.40-PM.png?w=1104&amp;ssl=1 1104w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-7.04.40-PM.png?resize=800%2C207&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-7.04.40-PM.png?resize=300%2C78&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-7.04.40-PM.png?resize=768%2C199&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-7.04.40-PM.png?resize=1024%2C265&amp;ssl=1 1024w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Mode Two button</figcaption></figure>
</div>

<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="161" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-7.05.45-PM.png?resize=770%2C161&#038;ssl=1" alt="Updated data" class="wp-image-605" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-7.05.45-PM.png?w=1170&amp;ssl=1 1170w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-7.05.45-PM.png?resize=800%2C168&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-7.05.45-PM.png?resize=300%2C63&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-7.05.45-PM.png?resize=768%2C161&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-7.05.45-PM.png?resize=1024%2C214&amp;ssl=1 1024w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Updated data</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">The same logic applies to the remaining buttons, when the user clicks on a button, a specific piece of data will get sent to the database depending on what button the user clicked.</p>



<h4 class="wp-block-heading">Building the app APK file</h4>



<hr class="wp-block-separator has-css-opacity"/>



<p class="wp-block-paragraph">download the following <strong>.aia</strong> file and import it to your &#8220;MIT app inventor&#8221; account projects dashboard, it will open up the project source, <strong>don&#8217;t forget to update the &#8220;FirebaseURL&#8221; to your firebase project database URL.</strong></p>



<p class="wp-block-paragraph">You can download the .aia source file from that link.</p>



<div class="aligncenter wp-block-button"><a class="wp-block-button__link has-background wp-element-button" href="https://drive.google.com/open?id=1uGUct6ddtGVaS_aYOXB2k6JPw_WVf7_M" style="border-radius:100px;background-color:#00a99d">mobile app .aia file</a></div>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="512" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.49.31-PM.png?resize=770%2C512&#038;ssl=1" alt="updating the firebase URL" class="wp-image-600" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.49.31-PM.png?w=1038&amp;ssl=1 1038w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.49.31-PM.png?resize=800%2C532&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.49.31-PM.png?resize=300%2C199&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.49.31-PM.png?resize=768%2C511&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.49.31-PM.png?resize=1024%2C681&amp;ssl=1 1024w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.49.31-PM.png?resize=270%2C180&amp;ssl=1 270w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.49.31-PM.png?resize=370%2C245&amp;ssl=1 370w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">updating the firebase URL</figcaption></figure>
</div>


<p class="wp-block-paragraph">Then <strong>build the app APK file</strong> and download it to your computer, then send the APK file to your mobile and install it.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="118" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-03-at-4.13.20-AM.png?resize=770%2C118&#038;ssl=1" alt="save the APK file to your computer" class="wp-image-652" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-03-at-4.13.20-AM.png?w=1170&amp;ssl=1 1170w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-03-at-4.13.20-AM.png?resize=800%2C123&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-03-at-4.13.20-AM.png?resize=300%2C46&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-03-at-4.13.20-AM.png?resize=768%2C118&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-03-at-4.13.20-AM.png?resize=1024%2C157&amp;ssl=1 1024w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">save the APK file to your computer</figcaption></figure>
</div>


<h2 class="wp-block-heading">Programming The Raspberry Pi</h2>



<hr class="wp-block-separator has-css-opacity"/>



<p class="has-regular-font-size wp-block-paragraph">After building the mobile app and sending data successfully from it to the database, the raspberry pi will read that data from the <strong>&#8220;firebase database&#8221;</strong> and according to the read data, it will take different actions like changing the lighting mode or increasing the brightness and so on.</p>



<h4 class="wp-block-heading">Installing The Pyrebase Module</h4>



<hr class="is-style-default wp-block-separator has-css-opacity"/>



<p class="has-regular-font-size wp-block-paragraph">Before we start writing any code, we need to install the <strong>&#8220;Pyrebase&#8221;</strong> python module on the raspberry pi board to allow us to communicate with the &#8220;Firebase Database&#8221; servers. Because by default the &#8220;Firebase&#8221; doesn&#8217;t support the &#8220;Python Programming Language&#8221; So, some cool guys wrote a python module to allow the python developers to use &#8220;Firebase&#8221; easily. If you are a Python NERD you can check out the module documentation on their <a href="https://github.com/thisbejim/Pyrebase#database"><strong>Github page</strong></a>.</p>



<p class="has-regular-font-size wp-block-paragraph">We will use &#8220;pip&#8221; to install the &#8220;Pyrebase&#8221; module. So, check to see if you currently have pip installed by running the command in the terminal.</p>



<pre class="wp-block-code"><code>pip --version</code></pre>



<p class="has-regular-font-size wp-block-paragraph">If it is not currently installed, you can install pip by running the following command</p>



<pre class="wp-block-code"><code>curl https://bootstrap.pypa.io/get-pip.py | python</code></pre>



<p class="has-regular-font-size wp-block-paragraph">After getting sure that we have &#8220;pip&#8221; on our raspberry pi board, we will start installing <strong>&#8220;Pyrebase&#8221;</strong> by running this command, and don&#8217;t worry if it takes some time.</p>



<pre class="wp-block-code"><code>sudo pip3 install Pyrebase</code></pre>



<p class="has-regular-font-size wp-block-paragraph">After finishing installing the &#8220;Pyrebase&#8221; module, we are now ready to write the final python script that will read data from the &#8220;Firebase database&#8221; to take some different actions according to that data.</p>



<h4 class="wp-block-heading">Code</h4>



<hr class="wp-block-separator has-css-opacity"/>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#OK!
#Author: Ahmed Ibrahim
#Date: 2/10/2019
#Website: makesomestuff.org

import RPi.GPIO as GPIO                                                                         #import the RPi.GPIO module to allow us use the board GPIO pins.
import pyrebase                                                                                 #import the pyrebase module which allows us to communicate with the firebase servers.
from time import sleep                                                                          #import the time modulde to allow us do the delay stuff.

config = {                                                              #define a dictionary named config with several key-value pairs that configure the connection to the database.
  "apiKey": "ENTER YOUR API KEY",
  "authDomain": "ENTER YOUR AUTH DOMAIN URL",
  "databaseURL": "ENTER YOUR DATABASE URL",
  "storageBucket": "ENTER YOUR STORAGE BUGET URL"
}

firebase = pyrebase.initialize_app(config)                              #initialize the communication with the "firebase" servers using the previous config data.

redLED = 12                                                                                    #the "redLED" variable refers to the GPIO pin 12 which the red LED is connected on.
blueLED = 19                                                                                   #the "blueLED" variable refers to the GPIO pin 19 which the blue LED is connected on.
greenLED = 18                                                                                  #the "greenLED" variable refers to the GPIO pin 18 which the green LED is connected on.

GPIO.setmode(GPIO.BCM)                                                                         #Set the GPIO Scheme numbering system to the BCM mode.
GPIO.setwarnings(False)                                                                        #disable warnings

GPIO.setup(redLED,GPIO.OUT)                                                                    #set the "redLED" variable pin (12) as an output pin.
GPIO.setup(blueLED,GPIO.OUT)                                                                   #set the "blueLED" variable pin (19) as an output pin.
GPIO.setup(greenLED,GPIO.OUT)                                                                  #set the "greenLED" variable pin (18) as an output pin.

red_pwm = GPIO.PWM(redLED,1000)                                                                #create PWM instance named "red_pwm" with frequency 1000.
blue_pwm = GPIO.PWM(blueLED,1000)                                                              #create PWM instance named "blue_pwm" with frequency 1000.
green_pwm = GPIO.PWM(greenLED,1000)                                                            #create PWM instance named "green_pwm" with frequency 1000.

red_pwm.start(0)                                                                               #start the program with 0% duty cycle (red LED will be OFF).
blue_pwm.start(0)                                                                              #start the program with 0% duty cycle (blue LED will be OFF).
green_pwm.start(0)                                                                             #start the program with 0% duty cycle (green LED will be OFF).

print("AH Shit! Here we go again! Press CTRL+C to exit")                                       #print "AH Shit! Here we go again! Press CTRL+C to exit" at the beginning of the program.

# function name: mode6
# arguments:
#   redIntensity: the brightness intensity of the red LED.
#   greenIntensity: the brightness intensity of the green LED.
#   blueIntensity: the brightness intensity of the blue LED.
# return: this funtion return nothing.
# this function is responsible for the pattern of the lighting mode. Feel free to change the lighting pattern as you want.
def mode6 (redIntensity, greenIntensity, blueIntensity):
    for duty in range (0, redIntensity, 1):
        red_pwm.ChangeDutyCycle(duty)
        sleep(0.01)
    sleep(0.3)
    for duty in range (redIntensity - 1, -1, -1):
        red_pwm.ChangeDutyCycle(duty)
        sleep(0.01)
    sleep(0.3)
    for duty in range (0, blueIntensity, 1):
        blue_pwm.ChangeDutyCycle(duty)
        sleep(0.01)
    sleep(0.3)
    for duty in range (blueIntensity - 1, -1, -1):
        blue_pwm.ChangeDutyCycle(duty)
        sleep(0.01)
    sleep(0.3)
    for duty in range (0, greenIntensity, 1):
        green_pwm.ChangeDutyCycle(duty)              #provide duty cycle in the range 0-100.
        sleep(0.01)
    sleep(0.3)
    for duty in range (greenIntensity - 1, -1 ,-1):
       green_pwm.ChangeDutyCycle(duty)               #provide duty cycle in the range 0-100
       sleep(0.01)
    sleep(0.3)

# function name: mode5
# arguments:
#   redIntensity: the brightness intensity of the red LED.
#   greenIntensity: the brightness intensity of the green LED.
#   blueIntensity: the brightness intensity of the blue LED.
# return: this funtion return nothing.
# this function is responsible for the pattern of the lighting mode. Feel free to change the lighting pattern as you want.
def mode5(redIntensity, greenIntensity, blueIntensity):
    for duty in range (0, redIntensity, 1):
        red_pwm.ChangeDutyCycle(duty)
        sleep(0.001)
    sleep(0.3)
    for duty in range (redIntensity - 1, -1, -1):
        red_pwm.ChangeDutyCycle(duty)
        sleep(0.001)
    sleep(0.3)
    for duty in range (0, blueIntensity, 1):
        blue_pwm.ChangeDutyCycle(duty)
        sleep(0.001)
    sleep(0.3)
    for duty in range (blueIntensity - 1 , -1, -1):
        blue_pwm.ChangeDutyCycle(duty)
        sleep(0.001)
    sleep(0.3)
    for duty in range (0, greenIntensity, 1):
        green_pwm.ChangeDutyCycle(duty)              #provide duty cycle in the range 0-100.
        sleep(0.001)
    sleep(0.3)
    for duty in range (greenIntensity - 1 , -1, -1):
       green_pwm.ChangeDutyCycle(duty)               #provide duty cycle in the range 0-100
       sleep(0.001)
    sleep(0.3)

# function name: mode4
# arguments:
#   redIntensity: the brightness intensity of the red LED.
#   greenIntensity: the brightness intensity of the green LED.
#   blueIntensity: the brightness intensity of the blue LED.
# return: this funtion return nothing.
# this function is responsible for the pattern of the lighting mode. Feel free to change the lighting pattern as you want.
def mode4(redIntensity, greenIntensity, blueIntensity):
    for duty in range (0, redIntensity, 1):
        red_pwm.ChangeDutyCycle(duty)
        sleep(0.01)
    sleep(0.5)
    green_pwm.ChangeDutyCycle(0)
    sleep(0.2)
    green_pwm.ChangeDutyCycle(greenIntensity - 1)

    for duty in range (0, blueIntensity, 1):
        blue_pwm.ChangeDutyCycle(duty)
        sleep(0.01)
    sleep(0.5)
    blue_pwm.ChangeDutyCycle(0)
    sleep(0.2)
    blue_pwm.ChangeDutyCycle(blueIntensity - 1)

    for duty in range (0,greenIntensity,1):
        green_pwm.ChangeDutyCycle(duty)
        sleep(0.01)
    sleep(0.5)
    red_pwm.ChangeDutyCycle(0)
    sleep(0.2)
    red_pwm.ChangeDutyCycle(redIntensity - 1)

    red_pwm.ChangeDutyCycle(0)
    green_pwm.ChangeDutyCycle(0)
    blue_pwm.ChangeDutyCycle(0)

# function name: mode3
# arguments:
#   redIntensity: the brightness intensity of the red LED.
#   greenIntensity: the brightness intensity of the green LED.
#   blueIntensity: the brightness intensity of the blue LED.
# return: this funtion return nothing.
# this function is responsible for the pattern of the lighting mode. Feel free to change the lighting pattern as you want.
def mode3(redIntensity, greenIntensity, blueIntensity):
    red_pwm.ChangeDutyCycle(0)
    green_pwm.ChangeDutyCycle(0)
    blue_pwm.ChangeDutyCycle(0)

    red_pwm.ChangeDutyCycle(redIntensity - 1)
    blue_pwm.ChangeDutyCycle(blueIntensity - 1)
    green_pwm.ChangeDutyCycle(greenIntensity - 1)

# function name: mode2
# arguments:
#   redIntensity: the brightness intensity of the red LED.
#   greenIntensity: the brightness intensity of the green LED.
#   blueIntensity: the brightness intensity of the blue LED.
# return: this funtion return nothing.
# this function is responsible for the pattern of the lighting mode. Feel free to change the lighting pattern as you want.
def mode2(redIntensity, greenIntensity, blueIntensity):
    red_pwm.ChangeDutyCycle(0)
    green_pwm.ChangeDutyCycle(0)
    blue_pwm.ChangeDutyCycle(0)

    blue_pwm.ChangeDutyCycle(blueIntensity - 1)
    sleep(0.1)
    blue_pwm.ChangeDutyCycle(0)
    sleep(0.1)
    green_pwm.ChangeDutyCycle(greenIntensity - 1)
    sleep(0.1)
    green_pwm.ChangeDutyCycle(0)
    sleep(0.1)
    red_pwm.ChangeDutyCycle(redIntensity - 1)
    sleep(0.1)
    red_pwm.ChangeDutyCycle(0)
    sleep(0.1)

# function name: mode1
# arguments:
#   redIntensity: the brightness intensity of the red LED.
#   greenIntensity: the brightness intensity of the green LED.
#   blueIntensity: the brightness intensity of the blue LED.
# return: this funtion return nothing.
# this function is responsible for the pattern of the lighting mode. Feel free to change the lighting pattern as you want.
def mode1(redIntensity, greenIntensity, blueIntensity):
    red_pwm.ChangeDutyCycle(redIntensity - 1)
    sleep(0.02)
    red_pwm.ChangeDutyCycle(0)
    sleep(0.02)
    red_pwm.ChangeDutyCycle(redIntensity - 1)
    sleep(0.02)
    red_pwm.ChangeDutyCycle(0)
    sleep(0.02)

    green_pwm.ChangeDutyCycle(greenIntensity - 1)
    sleep(0.02)
    green_pwm.ChangeDutyCycle(0)
    sleep(0.02)
    green_pwm.ChangeDutyCycle(greenIntensity - 1)
    sleep(0.02)
    green_pwm.ChangeDutyCycle(0)
    sleep(0.02)

    blue_pwm.ChangeDutyCycle(blueIntensity - 1)
    sleep(0.02)
    blue_pwm.ChangeDutyCycle(0)
    sleep(0.02)
    blue_pwm.ChangeDutyCycle(blueIntensity - 1)
    sleep(0.02)
    blue_pwm.ChangeDutyCycle(0)
    sleep(0.02)

try:
    while True:                                                                              #the beginning of the main program.

        database = firebase.database()                                             #take an instance from the firebase database which is pointing to the root directory of your database.
        RGBControlBucket = database.child("RGBControl")                            #get the child "RGBControl" path in your database and store it inside the "RGBControlBucket" variable.
        powerState = RGBControlBucket.child("powerState").get().val()                        #read the power state value from the tag "powerState" which is a node inside the database.
#        print("power state is: " + str(powerState))

                                                                                             # if the "powerState" variable value is equal to "true"
        if "true" in powerState.lower():
            database = firebase.database()                                         #take an instance from the firebase database which is pointing to the root directory of your database.
            RGBControlBucket = database.child("RGBControl")                        #get the child "RGBControl" path in your database and store it inside the "RGBControlBucket" variable.
            redLightIntensity = RGBControlBucket.child("redLightIntensity").get().val()  #read the red LED intensity value from the tag "redLightIntensity" which is a node inside the database then store that value inside the "redLightIntensity" variable.
            
#            print("red Light Intensity is: " + str(redLightIntensity))

            database = firebase.database()                                         #take an instance from the firebase database which is pointing to the root directory of your database.
            RGBControlBucket = database.child("RGBControl")                        #get the child "RGBControl" path in your database and store it inside the "RGBControlBucket" variable.
            blueLightIntensity = RGBControlBucket.child("blueLightIntensity").get().val()  #read the blue LED intensity value from the tag "blueLightIntensity" which is a node inside the database then store that value inside the "blueLightIntensity" variable.
            
#            print("blue Light Intensity is: " + str(blueLightIntensity))

            database = firebase.database()                                         #take an instance from the firebase database which is pointing to the root directory of your database.
            RGBControlBucket = database.child("RGBControl")                        #get the child "RGBControl" path in your database and store it inside the "RGBControlBucket" variable.
            greenLightIntensity = RGBControlBucket.child("greenLightIntensity").get().val()  #read the green LED intensity value from the tag "greenLightIntensity" which is a node inside the database then store that value inside the "greenLightIntensity" variable.
            
#            print("green Light Intensity is: " + str(greenLightIntensity))

            database = firebase.database()                                         #take an instance from the firebase database which is pointing to the root directory of your database.
            RGBControlBucket = database.child("RGBControl")                        #get the child "RGBControl" path in your database and store it inside the "RGBControlBucket" variable.
            lightPresetMode = RGBControlBucket.child("lightMode").get().val()  #read the light preset mode value from the tag "lightMode" which is a node inside the database then store that value inside the "lightPresetMode" variable.
            
#            print("light preset mode is: " + str(lightPresetMode))
            #           if the variable "lightPresetMode" value is equal to "mode6", call the mode6 function.
            if "mode6" in lightPresetMode.lower():
                mode6(int(redLightIntensity), int(greenLightIntensity), int(blueLightIntensity))
            #           if the variable "lightPresetMode" value is equal to "mode5", call the mode5 function.
            elif "mode5" in lightPresetMode.lower():
                mode5(int(redLightIntensity), int(greenLightIntensity), int(blueLightIntensity))
            #           if the variable "lightPresetMode" value is equal to "mode4", call the mode4 function.
            elif "mode4" in lightPresetMode.lower():
                mode4(int(redLightIntensity), int(greenLightIntensity), int(blueLightIntensity))
            #           if the variable "lightPresetMode" value is equal to "mode3", call the mode3 function.
            elif "mode3" in lightPresetMode.lower():
                mode3(int(redLightIntensity), int(greenLightIntensity), int(blueLightIntensity))
            #           if the variable "lightPresetMode" value is equal to "mode2", call the mode2 function.
            elif "mode2" in lightPresetMode.lower():
                mode2(int(redLightIntensity), int(greenLightIntensity), int(blueLightIntensity))
            #           if the variable "lightPresetMode" value is equal to "mode1", call the mode1 function.
            elif "mode1" in lightPresetMode.lower():
                mode1(int(redLightIntensity), int(greenLightIntensity), int(blueLightIntensity))
    #                   if the variable "lightPresetMode" value is not equal to any of the above values, print "DAMN, the power state is: false" on the terminal for debugging purposes.
        else:
            print("DAMN, the power state is: " + powerState)


except KeyboardInterrupt: # If CTRL+C is pressed, exit cleanly:
    red_pwm.stop() # stop red PWM
    blue_pwm.stop() # stop blue PWM
    green_pwm.stop() # stop green PWM
    GPIO.cleanup() # cleanup all GPIO</pre>



<h4 class="wp-block-heading">Code Explanation</h4>



<hr class="wp-block-separator has-css-opacity"/>



<p class="has-regular-font-size wp-block-paragraph">the most important part here is to connect your python script to the &#8220;Firebase database&#8221; servers to be able to read the data from it. We define a dictionary named <code>config</code> with several key-value pairs that configure the connection to the database. The apiKey, authDomain, databaseUrl, and storageBucket values needed to connect to your database can be found in the Firebase console.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="python" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">config = {                                                              #define a dictionary named config with several key-value pairs that configure the connection to the database.
  "apiKey": "ENTER YOUR PROJECT API KEY",
  "authDomain": "ENTER YOUR AUTH DOMAIN URL",       # "projectId.firebaseapp.com"
  "databaseURL": "ENTER YOUR DATABASE URL",         # "https://databaseName.firebaseio.com"
  "storageBucket": "ENTER YOUR STORAGE BUGET URL"   # "projectId.appspot.com"
}</pre>



<p class="has-regular-font-size wp-block-paragraph">To find the <strong>&#8220;API Key&#8221;</strong>, <strong>&#8220;authDomain&#8221;</strong>, <strong>&#8220;databaseURL&#8221;</strong>, <strong>&#8220;storageBucket&#8221;</strong> values, go to your database dashboard click on the gear icon, then &#8220;Project settings&#8221;.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="129" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-9.39.15-PM.png?resize=770%2C129&#038;ssl=1" alt="Getting the API key" class="wp-image-616" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-9.39.15-PM.png?w=1170&amp;ssl=1 1170w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-9.39.15-PM.png?resize=800%2C134&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-9.39.15-PM.png?resize=300%2C50&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-9.39.15-PM.png?resize=768%2C129&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-9.39.15-PM.png?resize=1024%2C172&amp;ssl=1 1024w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Getting the API key</figcaption></figure>
</div>


<figure class="wp-block-image"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="465" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-9.41.29-PM.png?resize=770%2C465&#038;ssl=1" alt="getting the project ID" class="wp-image-619" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-9.41.29-PM.png?resize=1024%2C618&amp;ssl=1 1024w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-9.41.29-PM.png?resize=800%2C483&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-9.41.29-PM.png?resize=300%2C181&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-9.41.29-PM.png?resize=768%2C463&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-9.41.29-PM.png?w=1170&amp;ssl=1 1170w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">getting the project ID</figcaption></figure>



<p class="has-regular-font-size wp-block-paragraph">Then you will find your project <strong>API key</strong>. Copy and paste it inside your python script. To find the <strong>&#8220;authDomain&#8221;</strong> you need to get the <strong>project ID</strong>, after getting your <strong>Project ID</strong> your <strong>&#8220;authDomain&#8221;</strong> will be like this <strong>&#8220;projectId.firebaseapp.com&#8221;</strong>.<br>your <strong>&#8220;storageBucket&#8221;</strong> will be like this <strong>&#8220;projectId.appspot.com&#8221;</strong>.</p>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4043148098486780" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-4043148098486780" data-ad-slot="5056799298"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">and to get your <strong>&#8220;databaseURL&#8221;</strong> go to your project <strong>database dashboard</strong> and copy that URL. That&#8217;s It!</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="200" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.45.42-PM-1.png?resize=770%2C200&#038;ssl=1" alt="Database URL" class="wp-image-601" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.45.42-PM-1.png?w=1170&amp;ssl=1 1170w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.45.42-PM-1.png?resize=800%2C208&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.45.42-PM-1.png?resize=300%2C78&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.45.42-PM-1.png?resize=768%2C200&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/Screen-Shot-2019-10-02-at-6.45.42-PM-1.png?resize=1024%2C266&amp;ssl=1 1024w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Database URL</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">If you want more code explanation, please read the code comments it&#8217;s well documented.</p>



<h4 class="wp-block-heading">How does It Work?</h4>



<hr class="wp-block-separator has-css-opacity"/>



<p class="has-regular-font-size wp-block-paragraph">After finishing the wiring and your code, close and save it, Run your program by writing <code>python3 fileName.py</code> in your terminal. <br>Like the last example, After running your program, It&#8217;s expected to see this sentence got printed on the terminal <code>AH Shit! Here we go again! Press CTRL+C to exit</code> then you will be able to control the LED Strip from your mobile app, Voila!</p>



<p class="wp-block-paragraph"><strong>Note: You must run your program using python3, because the &#8220;pyrebase&#8221; module only works with python3 any other python version will not work.</strong></p>



<h4 class="wp-block-heading">Troubleshooting</h4>



<hr class="wp-block-separator has-css-opacity"/>



<p class="has-regular-font-size wp-block-paragraph">If you see that error message when you run your program</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="512" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/erScreen-Shot-2019-09-14-at-8.24.03-AM.png?resize=770%2C512&#038;ssl=1" alt="program running error" class="wp-image-632" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/erScreen-Shot-2019-09-14-at-8.24.03-AM.png?w=1170&amp;ssl=1 1170w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/erScreen-Shot-2019-09-14-at-8.24.03-AM.png?resize=800%2C532&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/erScreen-Shot-2019-09-14-at-8.24.03-AM.png?resize=300%2C199&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/erScreen-Shot-2019-09-14-at-8.24.03-AM.png?resize=768%2C511&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/erScreen-Shot-2019-09-14-at-8.24.03-AM.png?resize=1024%2C681&amp;ssl=1 1024w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/erScreen-Shot-2019-09-14-at-8.24.03-AM.png?resize=270%2C180&amp;ssl=1 270w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/erScreen-Shot-2019-09-14-at-8.24.03-AM.png?resize=370%2C245&amp;ssl=1 370w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">program running error</figcaption></figure>
</div>


<p class="wp-block-paragraph">don&#8217;t worry open your terminal and execute that commands </p>



<pre class="wp-block-code"><code>pip install --upgrade pyasn1-modules
</code></pre>



<p class="wp-block-paragraph"> this command will install your missing modules.</p>



<h2 class="wp-block-heading">Running The Program Automatically On Startup</h2>



<hr class="wp-block-separator has-css-opacity"/>



<p class="has-regular-font-size wp-block-paragraph">We don&#8217;t need to run the program manually by ourselves every time we boot up our raspberry pi board, it will be a good idea if we get our program to run automatically whenever the raspberry pi boots.</p>



<p class="has-regular-font-size wp-block-paragraph">After the desktop environment starts (LXDE-pi, in this case), it runs whatever commands it finds in the profile&#8217;s&nbsp;<em>autostart</em>&nbsp;script, which is located at&nbsp;<em>/home/pi/.config/lxsession/LXDE-pi/autostart</em>&nbsp;for our Raspberry Pi.</p>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4043148098486780" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-4043148098486780" data-ad-slot="5056799298"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="wp-block-paragraph">First, we need to create a .desktop File, Open a terminal, and execute the following commands to create an&nbsp;<em>autostart</em>&nbsp;directory (if one does not already exist) and edit a .desktop file for our project code</p>



<pre class="wp-block-code"><code>mkdir /home/pi/.config/autostart
nano /home/pi/.config/autostart/IoTUsingRaspberryPi.desktop
</code></pre>



<p class="has-regular-font-size wp-block-paragraph">Copy in the following text into the&nbsp;&#8220;IoTUsingRaspberryPi.desktop&#8221;&nbsp;file. Feel free to change the&nbsp;<em>Name</em>&nbsp;and&nbsp;<em>Exec</em>&nbsp;variables to your particular application.</p>



<pre class="wp-block-code"><code>&#91;Desktop Entry]
Type=Application
Name=IoTUsingRaspberryPiAndFirebase
Exec=/usr/bin/python3 /your program absolute path/programName.py
</code></pre>



<p class="has-regular-font-size wp-block-paragraph">That&#8217;s it! Now, at every time you boot up your raspberry pi, the program will start running automatically.</p>



<h4 class="wp-block-heading">Troubleshooting </h4>



<hr class="wp-block-separator has-css-opacity"/>



<p class="has-regular-font-size wp-block-paragraph"><strong>&nbsp;your script does not run as soon as you see the desktop?!  </strong></p>



<p class="wp-block-paragraph">there could be several issues. First, make sure that you have logged in (autostart does not start until you have logged in). You could also try enabling auto-login in&nbsp;<code>raspi-config</code>. Second, make sure you are using the absolute directory path (e.g.&nbsp;<code>/home/pi/IoTUsingRaspberryPi.py</code>). Third, make sure that you are using the python version 3 not anything else.</p>



<h2 class="wp-block-heading">My Setup</h2>



<hr class="wp-block-separator has-css-opacity"/>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="578" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/IMG_5105.jpg?resize=770%2C578&#038;ssl=1" alt="Project Setup" class="wp-image-679" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/IMG_5105.jpg?w=1170&amp;ssl=1 1170w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/IMG_5105.jpg?resize=600%2C450&amp;ssl=1 600w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/IMG_5105.jpg?resize=800%2C600&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/IMG_5105.jpg?resize=300%2C225&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/IMG_5105.jpg?resize=768%2C576&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/10/IMG_5105.jpg?resize=1024%2C768&amp;ssl=1 1024w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Project Setup</figcaption></figure>
</div>


<h2 class="wp-block-heading">Final</h2>



<hr class="wp-block-separator has-css-opacity"/>



<p class="has-regular-font-size wp-block-paragraph">We are done! in today’s tutorial, we learned how to build a simple mobile app using MIT App inventor. Also, we learned how to control RGD LED strips using the raspberry pi board, and how to communicate with the firebase database servers through a python script. Lastly, how to control an RGB LED strip wirelessly from anywhere in the world.</p>



<p class="has-regular-font-size wp-block-paragraph"><strong>Lastly, if you have any questions drop it in the comments section below, I will be more than happy to hear from you</strong></p>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4043148098486780" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-4043148098486780" data-ad-slot="5056799298"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://makesomestuff.org/iot-using-raspberry-pi-and-firebase-and-android/">IoT Using Raspberry Pi and Firebase and Android</a> appeared first on <a href="https://makesomestuff.org">Make Some Stuff</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://makesomestuff.org/iot-using-raspberry-pi-and-firebase-and-android/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">448</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Minified using Disk

Served from: makesomestuff.org @ 2026-06-23 23:11:44 by W3 Total Cache
-->