<?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>Robot Archives &#8211; Make Some Stuff</title>
	<atom:link href="https://makesomestuff.org/tag/robot/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>Build Cool Electronics Projects!</description>
	<lastBuildDate>Sat, 27 Sep 2025 21:29:14 +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>Robot 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>Bluetooth-Controlled 2WD Robot</title>
		<link>https://makesomestuff.org/how-to-control-2wd-robot-wirelessly-through-processing/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-control-2wd-robot-wirelessly-through-processing</link>
					<comments>https://makesomestuff.org/how-to-control-2wd-robot-wirelessly-through-processing/#respond</comments>
		
		<dc:creator><![CDATA[Ahmed Ibrahim]]></dc:creator>
		<pubDate>Wed, 21 Aug 2019 06:30:55 +0000</pubDate>
				<category><![CDATA[Arduino Projects]]></category>
		<category><![CDATA[Bluetooth]]></category>
		<category><![CDATA[Robot]]></category>
		<guid isPermaLink="false">https://makesomestuff.org/?p=99</guid>

					<description><![CDATA[<p><a href="https://makesomestuff.org">Make Some Stuff</a><br />
<a href="https://makesomestuff.org/how-to-control-2wd-robot-wirelessly-through-processing/">Bluetooth-Controlled 2WD Robot</a></p>
<p>Wanna Control your Robot wirelessly through your laptop?! We gonna do that in this step-by-step tutorial Using the awesome Arduino board and Processing. Hardware Components Used Software Introduction In this tutorial, we gonna build a 2WD Robot controlled wirelessly from your laptop or PC through a simple GUI built on Processing IDE. We gonna divide [...]</p>
<p>The post <a href="https://makesomestuff.org/how-to-control-2wd-robot-wirelessly-through-processing/">Bluetooth-Controlled 2WD Robot</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/how-to-control-2wd-robot-wirelessly-through-processing/">Bluetooth-Controlled 2WD Robot</a></p>

<p class="has-text-align-left has-regular-font-size wp-block-paragraph">Wanna Control your Robot wirelessly through your laptop?! We gonna do that in this step-by-step tutorial Using the awesome Arduino board and Processing.</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="9912528396"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="Arduino Wireless Controlled Robot" width="770" height="433" src="https://www.youtube.com/embed/untpjVQAGTQ?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div></figure>



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



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



<ol class="wp-block-list">
<li><a href="https://www.ebay.com/itm/Original-Official-Genuine-Arduino-Uno-R3-ATmega328-MEGA328P-USB-Board-16MHz-I-O/162854440047?hash=item25eae18c6f:g:EyMAAOSwZlZaPN3n">Arduino Uno</a></li>



<li><a href="https://www.ebay.com/itm/2WD-Smart-Robot-Car-Chassis-Kit-Speed-encoder-Battery-Box-Arduino-2-motor-1-48/283477666132?hash=item420095e954:g:UvIAAOSw8q5c0pUW">2WD Robot Chassis Kit (Includes Two DC Motors).</a></li>



<li><a href="https://www.ebay.com/itm/New-L298N-DC-Stepper-Motor-Driver-Module-Dual-H-Bridge-Control-Board-for-Arduino/191674305541?epid=21024969493&amp;hash=item2ca0adcc05:g:Jb0AAOSwESNZ7v2s">L298N Dual H-bridge Motor Driver</a></li>



<li>7.4V 1500mAh Rechargeable battery</li>
</ol>



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



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



<ul class="wp-block-list">
<li><a href="https://www.arduino.cc/en/Main/Software">Arduino IDE</a></li>



<li><a href="https://processing.org/download/">Processing IDE</a></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">In this tutorial, we gonna build a 2WD Robot controlled wirelessly from your laptop or PC through a simple GUI built on Processing IDE. We gonna divide this tutorial into two main parts:</p>



<p class="has-regular-font-size wp-block-paragraph"><strong>Control the Two DC Motors from the Arduino Serial Monitor</strong></p>



<ul class="wp-block-list">
<li>How Does DC Motors Work?</li>



<li>What is the H-bridge circuit and why we need it?</li>



<li>what&#8217;s the L298N motor driver module and how to use it with the Arduino board.</li>



<li>What&#8217;s the Arduino Serial Monitor.</li>



<li>code explanation.</li>
</ul>



<p class="has-regular-font-size wp-block-paragraph"><strong>Control the Two DC Motors from the Processing&nbsp;Control Panel GUI</strong></p>



<ul class="wp-block-list">
<li>How to build our User Interface using Processing IDE.</li>



<li>What&#8217;s the HC-05 Bluetooth module and how to use it with Arduino.</li>



<li>code modification explanation.</li>
</ul>



<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="9912528396"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<h2 class="wp-block-heading">First Part: Control the Two DC Motors from the Arduino Serial Monitor</h2>



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



<h4 class="wp-block-heading has-text-align-left"><strong>Working Scenario </strong></h4>



<p class="has-text-align-left has-very-dark-gray-color has-text-color has-regular-font-size wp-block-paragraph">the user will control the two DC Motors from the Arduino serial monitor according to the characters he/she send.</p>



<ul class="wp-block-list">
<li>by sending the char &#8216;f&#8217;, the two motors will rotate <strong>FORWARD</strong>.</li>



<li>sending the char &#8216;b&#8217;, the two motors will rotate <strong>BACKWARD</strong>.</li>



<li>by sending the char &#8216;r&#8217;, the left motor will rotate <strong>FORWARD</strong> and the right motor will rotate <strong>BACKWARD</strong>.</li>



<li>sending the char &#8216;l&#8217;, the right motor will rotate <strong>FORWARD</strong> and the left motor will rotate <strong>BACKWARD</strong>.</li>



<li>by sending the char &#8216;s&#8217;, the two motors will <strong>STOP</strong> rotating.</li>
</ul>



<h4 class="wp-block-heading has-text-align-left"><strong>How DC Motor Works?</strong></h4>



<p class="has-regular-font-size wp-block-paragraph">Simply, DC motor is a component that converts electrical energy into mechanical energy. we will not dive deep into that Electromagnetism, induction, and magnetic field stuff. actually, I don&#8217;t care about that, what I care about is how to drive this dc motor thing.</p>


<div class="wp-block-image">
<figure class="aligncenter is-resized"><img data-recalc-dims="1" loading="lazy" decoding="async" width="201" height="251" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/momo.jpg?resize=201%2C251&#038;ssl=1" alt="Meme Lord Baby" class="wp-image-100" style="width:201px;height:251px"/><figcaption class="wp-element-caption">Meme Lord Baby</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">The DC motor will start rotating only when a current flow through it, the motor rotation direction depends on the current flow direction. (See Fig 1) By changing the polarity of the power source with the motor, motor rotation direction will get reversed. (NOTE: DC motors have no polarity).</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="520" height="272" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/motor-rotation-direction-and-polarity.jpg?resize=520%2C272&#038;ssl=1" alt="DC Motor Rotation direction and power source polarity" class="wp-image-101" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/motor-rotation-direction-and-polarity.jpg?w=520&amp;ssl=1 520w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/motor-rotation-direction-and-polarity.jpg?resize=300%2C157&amp;ssl=1 300w" sizes="auto, (max-width: 520px) 100vw, 520px" /><figcaption class="wp-element-caption">DC Motor Rotation direction and power source polarity</figcaption></figure>
</div>


<h4 class="wp-block-heading"><strong>How to drive the DC motor from the Awesome Arduino board?</strong></h4>



<p class="has-regular-font-size wp-block-paragraph">Actually, DC motors draw a large amount of current while rotating up to 500mA each (500mA in our case. but actually, it depends on the motor size and its power rating), but our Arduino board only can provide 40mA at 5V on its digital pins. so we need to use an external power source(battery) to provide the motors with the required power to operate properly without damaging the Arduino board. Also, we need to separate that power circuit(External power source) from the control circuit(Arduino Board).</p>



<ul class="wp-block-list">
<li>We will use a 7.4V 1.5Ah battery as a power source to provide the required power to our motors. (power circuit)</li>



<li>and of course, the Arduino UNO board to control the Motors. (Control circuit)</li>
</ul>



<p class="has-regular-font-size wp-block-paragraph">we can use a BJT Transistor like the 2N2222a NPN Transistor to separate the power circuit from the control circuit.&nbsp;<strong>Some 2N2222a Specs before using it:</strong></p>



<ul class="wp-block-list">
<li>Collector-Emitter Voltage is 30V.</li>



<li>The continuous collector current is 800mA.</li>



<li>Base current is 5mA max.</li>
</ul>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="634" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/wiring-Diagram.png?resize=770%2C634&#038;ssl=1" alt="Single DC Motor with Transistor" class="wp-image-125" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/wiring-Diagram.png?w=951&amp;ssl=1 951w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/wiring-Diagram.png?resize=800%2C659&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/wiring-Diagram.png?resize=300%2C247&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/wiring-Diagram.png?resize=768%2C632&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/wiring-Diagram.png?resize=675%2C556&amp;ssl=1 675w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Single DC Motor with Transistor</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph"><strong>In the Above circuit,</strong>&nbsp;We are using the transistor as a switch, when the voltage across the Base-emitter transistor is HIGH (5V) it will close the connection between the collector and the emitter. So, the current will flow through the motor which will make it rotates.<br><br>if the voltage across the Base-emitter transistor is LOW (0V) it will open the connection between the transistor collector and emitter and the motor will stop rotating.<br><br>don&#8217;t forget to use a current limiting resistor on the transistor base pin&nbsp;(1k Ohm)&nbsp;to prevent it from damaging. Also,<em> use a diode in parallel with your motor to protect your Arduino from any back EMF</em>&nbsp;<em>returning from the motor.</em><br><br>But this circuit will allow us to only control one direction of the motor ON and OFF. So, what if we want to control its rotation direction? we will need an H-bridge circuit.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="740" height="491" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/H-bridge-circuit.jpeg?resize=740%2C491&#038;ssl=1" alt="Single H-bridge Circuit" class="wp-image-126" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/H-bridge-circuit.jpeg?w=740&amp;ssl=1 740w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/H-bridge-circuit.jpeg?resize=300%2C199&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/H-bridge-circuit.jpeg?resize=675%2C448&amp;ssl=1 675w" sizes="auto, (max-width: 740px) 100vw, 740px" /><figcaption class="wp-element-caption">Single H-bridge Circuit</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">Simply, the H-bridge circuit inverts the direction of the current flow through the motor. this circuit contains four switching elements(transistors in our case) by activating two particular switches at the same time we can change the direction of the current flow thus change the motor rotation direction. for example:</p>



<ul class="wp-block-list">
<li>when Q1 &amp; Q4 are activated and the Q2 &amp; Q3 are deactivated, the current will flow from the VCC of the power source passing through the Q1 then to the motor(from the left terminal to the right terminal) then to Q4 then to the GND. which will make the motor to rotate in the clockwise direction.</li>



<li>when Q2 &amp; Q3 are activated and the Q1 &amp; Q4 are deactivated, the current will flow from the VCC of the power source passing through the Q3 then to the motor(from the right terminal to the left terminal) then to Q2 then to the GND. which will make the motor to rotate in the anti-clockwise direction.</li>
</ul>



<p class="has-regular-font-size wp-block-paragraph">So, using only two output pins(A, B) from the Arduino board you can control the state of the four switching elements(transistors) thus controlling the motor rotation direction.</p>



<ul class="wp-block-list">
<li>&#8216;A&#8217; pin Controls transistor Q1, and Q4.</li>



<li>&#8216;B&#8217; pin Controls transistor Q2, and Q3.</li>
</ul>



<p class="has-regular-font-size wp-block-paragraph"><strong>GUESS WHAT! </strong>I have some good news for you, you don&#8217;t need to build this H-bridge circuit from scratch. we will use the L298N H-bridge Motor driver module which gives us all these functionalities.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="580" height="575" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/L298N_motor_driver.png?resize=580%2C575&#038;ssl=1" alt="L298N Motor Driver Module" class="wp-image-127" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/L298N_motor_driver.png?w=580&amp;ssl=1 580w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/L298N_motor_driver.png?resize=100%2C100&amp;ssl=1 100w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/L298N_motor_driver.png?resize=150%2C150&amp;ssl=1 150w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/L298N_motor_driver.png?resize=300%2C297&amp;ssl=1 300w" sizes="auto, (max-width: 580px) 100vw, 580px" /><figcaption class="wp-element-caption">L298N Motor Driver Module</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">Simply, the L298N Motor driver module is a dual H-bridge circuit that allows you to&nbsp;<strong>feed</strong>&nbsp;the motors with the needed power from an external power source, also allows you to&nbsp;<strong>control</strong>&nbsp;the motors rotation direction from your Arduino board.</p>



<p class="has-regular-font-size wp-block-paragraph">the L298N Motor driver module is a two-channel driver which means that you can connect two different DC motors and control each one independently. the L298N Module can drive DC motors that have a voltage between 5-35V with 2A peak current at each channel.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="718" height="448" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/L298-Module-pinout.png?resize=718%2C448&#038;ssl=1" alt="L298N Module Pinout" class="wp-image-128" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/L298-Module-pinout.png?w=718&amp;ssl=1 718w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/L298-Module-pinout.png?resize=300%2C187&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/L298-Module-pinout.png?resize=675%2C421&amp;ssl=1 675w" sizes="auto, (max-width: 718px) 100vw, 718px" /><figcaption class="wp-element-caption">L298N Module Pinout</figcaption></figure>
</div>


<ul class="wp-block-list">
<li>Motor A &#8211;> First Motor Terminal.</li>



<li>Motor B &#8211;> Second Motor Terminal.</li>



<li>12V jumper &#8211;> if your using a power source more than 12V remove this jumper to not damage the onboard voltage regulator.</li>



<li>pin (Vs) &#8211;> is the pin where the motor power source is connected to, the input voltage should be between 5V and 35V.</li>



<li>Pin(GND) &#8211;> is the pin where both the GND of the battery and the GND of the Arduino board is connected on.</li>



<li>Power pin(5V IN/OUT) &#8211;> you can source 5V from this pin only if the 12V jumper is connected. but if the 12V jumper is disconnected you should feed the L298N IC with 5V input to operate properly.</li>



<li>Enable pins(Enable A) &#8211;> by sending a PWM signal from your Arduino PWM Output pin you can control the speed of motor A.</li>



<li>Enable pins(Enable B) &#8211;> by sending a PWM signal from your Arduino PWM Output pin you can control the speed of motor B.</li>



<li>Logic pins(input1 &amp; input2) &#8211;> by sending a digital signal from your Arduino digital Output pin you can control the rotation direction of the Motor A.</li>



<li>Logic pins(input3 &amp; input4) &#8211;> by sending a digital signal from your Arduino digital Output pin you can control the rotation direction of the Motor B.</li>
</ul>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="740" height="337" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/L298N-logic-Control.jpeg?resize=740%2C337&#038;ssl=1" alt="motor rotation direction Logic Control" class="wp-image-129" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/L298N-logic-Control.jpeg?w=740&amp;ssl=1 740w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/L298N-logic-Control.jpeg?resize=300%2C137&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/L298N-logic-Control.jpeg?resize=675%2C307&amp;ssl=1 675w" sizes="auto, (max-width: 740px) 100vw, 740px" /><figcaption class="wp-element-caption">motor rotation direction Logic Control</figcaption></figure>
</div>


<h4 class="wp-block-heading" id="toc-l298n-motor-driver-module-wiring-with-arduino-2">L298N Motor Driver Module Wiring With Arduino</h4>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="740" height="507" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Wiring-Diagram-one.jpeg?resize=740%2C507&#038;ssl=1" alt="Wiring Diagram" class="wp-image-130" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Wiring-Diagram-one.jpeg?w=740&amp;ssl=1 740w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Wiring-Diagram-one.jpeg?resize=300%2C206&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Wiring-Diagram-one.jpeg?resize=675%2C462&amp;ssl=1 675w" sizes="auto, (max-width: 740px) 100vw, 740px" /><figcaption class="wp-element-caption">Wiring Diagram</figcaption></figure>
</div>


<ul class="wp-block-list">
<li>connecting the four logic input pins(L298n Module logical pins) with any four Arduino digital output pins to control the motors rotation direction.</li>



<li>connecting the two enable pins with any two Arduino PWM output pins to control the motors rotation speed. (0 for lowest speed and 255 for highest speed).</li>



<li>Connect the +VE terminal of the battery to the +12V pin of the L298N Module, also connect the -VE terminal of the battery to the GND pin of the L298N module.<strong> Don&#8217;t forget to connect the Arduino GND pin as well to the L298N Module GND Pin.</strong></li>
</ul>



<h4 class="wp-block-heading"><strong>Sending/Receiving Data between the laptop and the Arduino board.</strong></h4>



<p class="has-regular-font-size wp-block-paragraph">Serial communication is the process of sending data one bit at a time, sequentially, over a communication channel or computer bus. Source:&nbsp;<a href="http://wikipedia.com/">Wikipedia.com</a><br><br>Let&#8217;s give an example, imagine that you have an Ultrasonic sensor(it&#8217;s a sensor that measures the distance between it and an object.) and you want to send this distance value to your computer to do some further actions. one simple solution is to connect your Arduino board with your computer via USB and send that data using Serial communication. And fortunately, that Arduino already has built-in functions to communicate with the serial port. You may also want to control your RC car motors remotely. in this case, you need to send your orders from your laptop or smartphone to the Arduino board also over the Serial communication.<br><br>To use Arduino serial port, you need to set the speed at which your computer will communicate with the Arduino board(it&#8217;s called baud rate). in your program inside the&nbsp;<em>void setup() function,</em>&nbsp;use the&nbsp;<em><strong><a href="https://www.arduino.cc/reference/en/language/functions/communication/serial/begin/">.begin</a></strong></em>&nbsp;function with the builtin object&nbsp;<em><strong><a href="https://www.arduino.cc/reference/en/language/functions/communication/serial/">Serial</a></strong></em>&nbsp;to set that speed. to see the valid baud rate values and for more details see the&nbsp;<a href="https://www.arduino.cc/reference/en/language/functions/communication/serial/">Arduino reference</a>.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="atomic" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Serial.begin(9600);</pre>



<h4 class="wp-block-heading"><strong>Some methods you need to know more about:</strong></h4>



<ul class="wp-block-list">
<li><strong><em><a href="https://www.arduino.cc/reference/en/language/functions/communication/serial/available/">Serial.available()</a></em></strong> &#8211;> Get the number of bytes (characters) available for reading from the serial port</li>



<li><strong><em><a href="https://www.arduino.cc/reference/en/language/functions/communication/serial/read/">Serial.read()</a></em></strong> &#8211;> Reads incoming serial data.</li>



<li><em><strong><a href="https://www.arduino.cc/reference/en/language/functions/communication/serial/println/">Serial.println()</a></strong></em> &#8211;> prints data to the serial port as human-readable text with a line break at the end.</li>



<li><em><strong><a href="https://www.arduino.cc/reference/en/language/functions/communication/serial/print/">Serial.print()</a></strong></em> &#8211;> same as the <strong>Serial.println()</strong> but without a line break at the end.</li>



<li><em><strong><a href="https://www.arduino.cc/reference/en/language/functions/communication/serial/write/">Serial.write()</a></strong></em> &#8211;> Writes binary data to the serial port. This data is sent as a byte or series of bytes.</li>
</ul>



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



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="twilight" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#define in1 4                                                           //defining const. variable named "in1" with value 0, which refers to the PICO D0.                
#define in2 5                                                           //defining const. variable named "in2" with value 1, which refers to the PICO D1.                
#define in3 7                                                           //defining const. variable named "in3" with value 2, which refers to the PICO D2.                
#define in4 8                                                           //defining const. variable named "in4" with value 3, which refers to the PICO D3.                
#define motorASpeedPin 9                
#define motorBSpeedPin 3                
char val;            
              
/*                
  forward function takes four arguments x, y, motorSpeed, speedPin.                
  this function returns nothing.                
  responsible for running motor A forward by a specific speed.                
*/             
             
void forward(int x, int y, int motorSpeed, int speedPin) {                
 digitalWrite(x, HIGH);                
 digitalWrite(y, LOW);                
 analogWrite(speedPin, motorSpeed);                
}           
               
/*                
  backward function takes four arguments x, y, motorSpeed, speedPin.                
  this function returns nothing.                
  responsible for running motor B backward with a specific speed.                
*/             
             
void backward(int x, int y, int motorSpeed, int speedPin) {                
 digitalWrite(x, LOW);                
 digitalWrite(y, HIGH);                
 analogWrite(speedPin, motorSpeed);                
}                
          
void right(int motorSpeed) {                
 forward(in1, in2, motorSpeed, motorASpeedPin);                
 backward(in3, in4, motorSpeed, motorBSpeedPin);                
}             
             
void left(int motorSpeed) {                
 forward(in3, in4, motorSpeed, motorBSpeedPin);                
 backward(in1, in2, motorSpeed, motorASpeedPin);                
}             
             
void stopAll() {                
 digitalWrite(in1, LOW);                
 digitalWrite(in2, LOW);                
 digitalWrite(in3, LOW);                
 digitalWrite(in4, LOW);                
}               
           
void setup() {                
 for (int i = 3 ; i &lt;= 5 ; i++) {                
   pinMode(i, OUTPUT);                
 }                
 for (int i = 7 ; i &lt;= 9 ; i++) {                
   pinMode(i, OUTPUT);                
 }                
 Serial.begin(9600);                
 Serial.println("Please enter 'f' to run the motor FORWARD, or 'b' to run the motor BACKWARD");                
 Serial.println("or 'r' to run the motor RIGHT, or 'l' to run the motor LEFT, or 's' to STOP all motors. ");                
}               
           
void loop() {                
 if (Serial.available() > 0) {                
   val = Serial.read();                
 }                
 if (val == 'f') {                
   forward(in1, in2, 255, motorASpeedPin);                
   forward(in3, in4, 255, motorBSpeedPin);                
   Serial.println("forward");                
 }                
 if (val == 'b') {                
   backward(in1, in2, 255, motorASpeedPin);                
   backward(in3, in4, 255, motorBSpeedPin);                
   Serial.println("backward");                
 }                
 if (val == 'r') {                
   right(255);                
   Serial.println("right");                
 }                
 if (val == 'l') {                
   left(255);                
   Serial.println("left");                
 }                
 if (val == 's') {                
   stopAll();                
   Serial.println("stopAll");                
 }                
}                </pre>



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



<p class="has-regular-font-size wp-block-paragraph">inside the&nbsp;<code>setup()</code>&nbsp;function where we set up our program,</p>



<ul class="wp-block-list">
<li>set the pins 3, 4, 5, 7, 8, 9 as output pins.</li>



<li>then start the Serial Communication between the Arduino and our computer at baud rate 9600 using the <em><code>.begin()</code></em> function.</li>



<li>then print this sentence one the Serial monitor is opened &#8220;<em>Please enter &#8216;f&#8217; to run the motor FORWARD, or &#8216;b&#8217; to run the motor BACKWARD or &#8216;r&#8217; to run the motor RIGHT, or &#8216;l&#8217; to run the motor LEFT, or &#8216;s&#8217; to STOP all motors.</em>&#8220;</li>
</ul>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="twilight" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">void setup() {                
 for (int i = 3 ; i &lt;= 5 ; i++) {                
   pinMode(i, OUTPUT);                
 }                
 for (int i = 7 ; i &lt;= 9 ; i++) {                
   pinMode(i, OUTPUT);                
 }                
 Serial.begin(9600);                
 Serial.println("Please enter 'f' to run the motor FORWARD, or 'b' to run the motor BACKWARD");                
 Serial.println("or 'r' to run the motor RIGHT, or 'l' to run the motor LEFT, or 's' to STOP all motors. ");                
}               </pre>



<p class="has-regular-font-size wp-block-paragraph">Inside the&nbsp;<code><em>loop()</em></code>&nbsp;function, which is going to repeat over and over as long as our program is running. we just need to read the data coming from the Serial monitor if there&#8217;s any. Then store it inside the &#8220;val&#8221; variable which we created earlier.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="twilight" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">if (Serial.available() > 0) {                
   val = Serial.read();                
 }   </pre>



<p class="has-regular-font-size wp-block-paragraph">after reading the data,</p>



<ul class="wp-block-list">
<li>if the received character is &#8216;<strong>f</strong>&#8216;. call the <strong>forward</strong> function and print &#8220;<strong>forward</strong>&#8221; on the serial monitor to make the debugging process easier.</li>



<li>the received character is &#8216;<strong>r</strong>&#8216; call the <strong>right</strong> function and print &#8220;<strong>right</strong>&#8221; on the serial monitor to make the debugging process easier.</li>



<li>if the received character is &#8216;<strong>l</strong>&#8216; call the <strong>left</strong> function and print &#8220;<strong>left</strong>&#8221; on the serial monitor to make the debugging process easier.</li>



<li>the received character is &#8216;<strong>s</strong>&#8216; call the <strong>stopAll</strong> function and print &#8220;<strong>stopAll</strong>&#8221; on the serial monitor to make the debugging process easier.</li>



<li>if the received character is &#8216;<strong>b</strong>&#8216; call the <strong>backward</strong> function and print &#8220;<strong>backward</strong>&#8221; on the serial monitor to make the debugging process easier.</li>
</ul>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="twilight" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">if (val == 'f') {                
   forward(in1, in2, 255, motorASpeedPin);                
   forward(in3, in4, 255, motorBSpeedPin);                
   Serial.println("forward");                
 }                
 if (val == 'b') {                
   backward(in1, in2, 255, motorASpeedPin);                
   backward(in3, in4, 255, motorBSpeedPin);                
   Serial.println("backward");                
 }                
 if (val == 'r') {                
   right(255);                
   Serial.println("right");                
 }                
 if (val == 'l') {                
   left(255);                
   Serial.println("left");                
 }                
 if (val == 's') {                
   stopAll();                
   Serial.println("stopAll");                
 }                
}                </pre>



<p class="has-regular-font-size wp-block-paragraph">After Uploading and Running the Code, you have to open the Arduino Serial Monitor from this pin.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="740" height="185" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/SM.png?resize=740%2C185&#038;ssl=1" alt="Code Snippet" class="wp-image-132" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/SM.png?w=740&amp;ssl=1 740w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/SM.png?resize=300%2C75&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/SM.png?resize=675%2C169&amp;ssl=1 675w" sizes="auto, (max-width: 740px) 100vw, 740px" /><figcaption class="wp-element-caption">Code Snippet</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">Now, you should see this window</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="563" height="555" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/SM2.png?resize=563%2C555&#038;ssl=1" alt="Serial monitor output" class="wp-image-133" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/SM2.png?w=563&amp;ssl=1 563w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/SM2.png?resize=100%2C100&amp;ssl=1 100w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/SM2.png?resize=300%2C296&amp;ssl=1 300w" sizes="auto, (max-width: 563px) 100vw, 563px" /><figcaption class="wp-element-caption">Serial monitor output</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">Now, type &#8216;f&#8217; in the upper bar and press the &#8216;send&#8217; button or just press enter. you will notice that your motors are now running forward.</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="9912528396"></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"><strong>CONGRATS!</strong> now you are able to control your motors from the serial monitor. Let&#8217;s go to the second step!</p>



<h2 class="wp-block-heading" id="toc-second-part--control-the-two-dc-motors-from-the-processing-control-panel-gui-5">Second Part: Control the Two DC Motors from the Processing Control Panel GUI</h2>



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



<h4 class="wp-block-heading">Working Scenario</h4>



<p class="has-regular-font-size wp-block-paragraph">We will build a GUI control panel using Processing IDE to control the motors from it instead of the Serial Monitor. the way of communication between the Processing IDE and the Serial port(Arduino IDE) is also a Serial Communication. So, we will build our logic upon the same concepts that we discussed in&nbsp;<strong>part one.</strong>&nbsp;Luckily, Processing comes with a Serial library designed for just this kind of thing!<br><br>to be able to use the Serial communication on processing you have to set the speed at which your computer will communicate with the Serial port(Arduino IDE) which is called the baud rate. Remember how we set&nbsp;<code>Serial.begin(9600)</code>&nbsp;in Arduino? we will do the same thing with processing but with a little change in the syntax.</p>



<ul class="wp-block-list">
<li>First things first, you have to import the Serial library.</li>
</ul>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="286" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-4.34.09-PM.png?resize=770%2C286&#038;ssl=1" alt="Importing Serial Library" class="wp-image-139" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-4.34.09-PM.png?w=2024&amp;ssl=1 2024w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-4.34.09-PM.png?resize=800%2C297&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-4.34.09-PM.png?resize=300%2C111&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-4.34.09-PM.png?resize=768%2C285&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-4.34.09-PM.png?resize=1024%2C380&amp;ssl=1 1024w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-4.34.09-PM.png?resize=1026%2C381&amp;ssl=1 1026w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-4.34.09-PM.png?resize=675%2C251&amp;ssl=1 675w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-4.34.09-PM.png?w=1540&amp;ssl=1 1540w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Importing Serial Library</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">You should now see at the top of your sketch a line like</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="mootools" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">import processing.serial.*;</pre>



<ul class="wp-block-list">
<li>The next line we need to take an object from the Serial class, i will name it &#8220;port&#8221; <em>(you can name it as you want)</em> this Serial object allows you to listen to any Serial communication incoming data.</li>
</ul>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="twilight" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Serial port;</pre>



<p class="has-regular-font-size wp-block-paragraph">For our&nbsp;<code>setup()</code>&nbsp;method in Processing, we&#8217;re going to find the Serial port our Arduino is connected to and set up our Serial object to listen to that port.<br><br>just like Arduino has <code>setup()</code> and <code>loop()</code>, processing has <code>setup()</code> and <code>draw()</code> (instead of loop)<br><br><strong>For windows users</strong>, it will look something like this. you just have to change the &#8220;<code>COM6</code>&#8221; value according to your Arduino Serial port.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="twilight" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">port = new Serial(this, "COM6", 9600);</pre>



<h4 class="wp-block-heading">How to know my Arduino Serial port?</h4>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="350" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/UNO_Port.jpg?resize=770%2C350&#038;ssl=1" alt="Windows Serial port" class="wp-image-140" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/UNO_Port.jpg?w=800&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/UNO_Port.jpg?resize=300%2C137&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/UNO_Port.jpg?resize=768%2C349&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/UNO_Port.jpg?resize=675%2C307&amp;ssl=1 675w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Windows Serial port</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph"><strong>For macOS or Linux users</strong>, it will look something like this. you just have to change the &#8220;<code>/dev/tty.usbmodem143101</code>&#8221; value according to your Arduino Serial port.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="twilight" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">port = new Serial(this, "/dev/tty.usbmodem143101", 9600);</pre>



<h4 class="wp-block-heading">How to know my Arduino Serial port?</h4>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="299" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-5.08.11-AM.png?resize=770%2C299&#038;ssl=1" alt="macOS &amp; Linux Serial port" class="wp-image-141" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-5.08.11-AM.png?w=1737&amp;ssl=1 1737w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-5.08.11-AM.png?resize=800%2C311&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-5.08.11-AM.png?resize=300%2C117&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-5.08.11-AM.png?resize=768%2C298&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-5.08.11-AM.png?resize=1024%2C398&amp;ssl=1 1024w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-5.08.11-AM.png?resize=1026%2C399&amp;ssl=1 1026w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-5.08.11-AM.png?resize=675%2C262&amp;ssl=1 675w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-5.08.11-AM.png?w=1540&amp;ssl=1 1540w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">macOS &amp; Linux Serial port</figcaption></figure>
</div>


<h4 class="wp-block-heading">GUI: Working Scenario</h4>



<figure class="wp-block-image"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="546" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-3.18.32-AM.png?resize=770%2C546&#038;ssl=1" alt="Final GUI" class="wp-image-142" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-3.18.32-AM.png?w=1224&amp;ssl=1 1224w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-3.18.32-AM.png?resize=800%2C567&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-3.18.32-AM.png?resize=300%2C213&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-3.18.32-AM.png?resize=768%2C545&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-3.18.32-AM.png?resize=1024%2C726&amp;ssl=1 1024w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-3.18.32-AM.png?resize=1026%2C728&amp;ssl=1 1026w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-3.18.32-AM.png?resize=675%2C479&amp;ssl=1 675w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Final GUI</figcaption></figure>



<p class="has-regular-font-size wp-block-paragraph">Building the App GUI is pretty simple, we gonna divide it into three main parts to make it clear.</p>



<ul class="wp-block-list">
<li>Build the App Window.</li>
</ul>



<p class="has-regular-font-size wp-block-paragraph">Building the App Window means Defining the dimension of the display window width and height in units of pixels and setting its color. Also, we will create a simple text to place it on the top of the window as a title.</p>



<ul class="wp-block-list">
<li>Placing the buttons on the window.</li>
</ul>



<p class="has-regular-font-size wp-block-paragraph">After building the App window, we need to create five buttons and position them on the App window to allow the user to interact with the app easily, each button is responsible for sending a specific order to the Arduino board. For example, when the user presses the &#8220;forward&#8221; button the Processing IDE will send a specific character to the Arduino port via the Serial Communication. And according to this character, Arduino IDE will trigger a specific event&nbsp;<em>(Rotating the motors forward)</em>.</p>



<ul class="wp-block-list">
<li>Buttons Functionality.</li>
</ul>



<p class="has-regular-font-size wp-block-paragraph">After placing the buttons correctly on the App Window, we need to give each button a functionality. which means a specific event will get triggered according to which button is clicked. enough talking, let&#8217;s build some stuff!</p>



<h4 class="wp-block-heading">Build the App Window</h4>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="twilight" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">void setup() {              
 size(500, 300);              
}              
void draw() {              
 background(150, 0, 150);              
 fill(255);              
 text("Motor Control GUI", 195, 30);              
}   </pre>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="546" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-1.44.05-AM.png?resize=770%2C546&#038;ssl=1" alt="Empty Window" class="wp-image-144" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-1.44.05-AM.png?w=1224&amp;ssl=1 1224w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-1.44.05-AM.png?resize=800%2C567&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-1.44.05-AM.png?resize=300%2C213&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-1.44.05-AM.png?resize=768%2C545&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-1.44.05-AM.png?resize=1024%2C726&amp;ssl=1 1024w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-1.44.05-AM.png?resize=1026%2C728&amp;ssl=1 1026w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-1.44.05-AM.png?resize=675%2C479&amp;ssl=1 675w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Empty Window</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph"><strong>inside the&nbsp;</strong><code><strong>setup()</strong></code><strong>&nbsp;function</strong></p>



<ul class="wp-block-list">
<li>We used the <code>size(500, 300);</code> Method to create the App Window with 500px width and 300px height.</li>
</ul>



<p class="has-regular-font-size wp-block-paragraph"><strong>inside the&nbsp;</strong><code><strong>draw()</strong></code><strong>&nbsp;function</strong></p>



<ul class="wp-block-list">
<li>we used the <code>background(150, 0, 150);</code> method with these RGB values to set the background color of the Processing window, This method is typically used within the <code>draw()</code> function to clear the display window at the beginning of each frame.</li>



<li>then we used the <code>fill(255);</code> method to set the color of any subsequent component to the white color.</li>



<li>then we used the <code>text("Motor Control GUI", 195, 30);</code> method to create a text on the X-coordinate 195 and the Y-coordinate 30.</li>
</ul>



<p class="has-regular-font-size wp-block-paragraph">the coordinate system for pixels in a computer window, however, is reversed along the y-axis. (0,0) can be found at the top left with the positive direction to the right horizontally and down vertically.&nbsp;<em>(See the next Figure)</em></p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="517" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Computer-Screen-coordinate-system.png?resize=770%2C517&#038;ssl=1" alt="Computer Screen Coordinates System" class="wp-image-145" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Computer-Screen-coordinate-system.png?w=1331&amp;ssl=1 1331w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Computer-Screen-coordinate-system.png?resize=800%2C537&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Computer-Screen-coordinate-system.png?resize=300%2C202&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Computer-Screen-coordinate-system.png?resize=768%2C516&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Computer-Screen-coordinate-system.png?resize=1024%2C688&amp;ssl=1 1024w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Computer-Screen-coordinate-system.png?resize=1026%2C689&amp;ssl=1 1026w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Computer-Screen-coordinate-system.png?resize=675%2C453&amp;ssl=1 675w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Computer Screen Coordinates System</figcaption></figure>
</div>


<h4 class="wp-block-heading">Placing the buttons on the window</h4>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="twilight" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">import controlP5.*;                  //import ControlP5 library              
              
ControlP5 cp5;                       //create ControlP5 object              
              
void setup() {              
 size(500, 300);              
 cp5 = new ControlP5(this);          //take an object from the ControlP5 Class            
              
 cp5.addButton("forward")            //add new button            
   .setPosition(190, 50)              
   .setSize(120, 70)                    
   ;                 
 cp5.addButton("backward")           //add new button                    
   .setPosition(190, 210)              
   .setSize(120, 70)                    
   ;              
 cp5.addButton("right")              //add new button                  
   .setPosition(350, 130)            
   .setSize(120, 70)            
   ;              
 cp5.addButton("left")               //add new button             
   .setPosition(30, 130)                
   .setSize(120, 70)                   
   ;              
 cp5.addButton("stop")               //add new button                 
   .setPosition(190, 130)                
   .setSize(120, 70)             
   ;              
}              
void draw() {              
 background(150, 0, 150);              
 fill(255);              
 text("Motor Control GUI", 195, 30);              
}    </pre>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="546" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-3.18.32-AM.png?resize=770%2C546&#038;ssl=1" alt="Adding the buttons to the window" class="wp-image-142" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-3.18.32-AM.png?w=1224&amp;ssl=1 1224w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-3.18.32-AM.png?resize=800%2C567&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-3.18.32-AM.png?resize=300%2C213&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-3.18.32-AM.png?resize=768%2C545&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-3.18.32-AM.png?resize=1024%2C726&amp;ssl=1 1024w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-3.18.32-AM.png?resize=1026%2C728&amp;ssl=1 1026w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-3.18.32-AM.png?resize=675%2C479&amp;ssl=1 675w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Adding the buttons to the window</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">we will use the&nbsp;ControlP5 library&nbsp;which allows us to add some buttons to our App, this library uses not limited on buttons only, it also gives you many more features like adding sliders, checkboxes, radio buttons, canvas, drop-down lists, &#8230;</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="9912528396"></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">installing any library in Processing is very simple, you just need to go to the sketch tab-&gt; Import Library-&gt; Add Library.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="373" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-2.41.04-AM.png?resize=770%2C373&#038;ssl=1" alt="Adding a new library to processing" class="wp-image-146" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-2.41.04-AM.png?w=1446&amp;ssl=1 1446w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-2.41.04-AM.png?resize=800%2C387&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-2.41.04-AM.png?resize=300%2C145&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-2.41.04-AM.png?resize=768%2C372&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-2.41.04-AM.png?resize=1024%2C496&amp;ssl=1 1024w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-2.41.04-AM.png?resize=1026%2C497&amp;ssl=1 1026w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-2.41.04-AM.png?resize=675%2C327&amp;ssl=1 675w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Adding a new library to processing</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">After this window appears, search for ControlP5, then select the&nbsp;<strong>ControlP5</strong> library and press&nbsp;install. The installation process will take only a few minutes.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="700" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-2.41.10-AM.png?resize=770%2C700&#038;ssl=1" alt="Installing a new library" class="wp-image-147" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-2.41.10-AM.png?w=1724&amp;ssl=1 1724w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-2.41.10-AM.png?resize=800%2C728&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-2.41.10-AM.png?resize=300%2C273&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-2.41.10-AM.png?resize=768%2C699&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-2.41.10-AM.png?resize=1024%2C931&amp;ssl=1 1024w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-2.41.10-AM.png?resize=1026%2C933&amp;ssl=1 1026w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-2.41.10-AM.png?resize=675%2C614&amp;ssl=1 675w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-2.41.10-AM.png?w=1540&amp;ssl=1 1540w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Installing a new library</figcaption></figure>
</div>


<ul class="wp-block-list">
<li>Import the ControlP5 library to our sketch <code>import controlP5.*;</code></li>



<li>Take an Object from the ControlP5 class <code>ControlP5 cp5;</code> . I will name it &#8220;cp5&#8221; <em>(you can name it as you want)</em> this cp5 object allows you to use the ControlP5 library methods to add buttons, sliders, checkboxes, etc&#8230;</li>
</ul>



<p class="has-regular-font-size wp-block-paragraph"><strong>inside the&nbsp;</strong><code><strong>setup()</strong></code><strong>&nbsp;function</strong></p>



<ul class="wp-block-list">
<li>Set up the cp5 object cp5 = <code>new ControlP5(this);</code></li>



<li>adding buttons using the ControlP5 library is very simple, you just need to use the <code>.addButton("name")</code> method to give it a name. and use the <code>.setPosition(x, y)</code> method to position it on the screen, and the .<code>setSize(w, h)</code> method to set its dimensions. that&#8217;s it.</li>
</ul>



<h4 class="wp-block-heading">Buttons Functionality</h4>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="twilight" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">import controlP5.*;             //import ControlP5 library            
import processing.serial.*;     //import the Serial Library            
            
ControlP5 cp5;                  //create ControlP5 object            
Serial port;                    //create Serial object            
            
void setup() {              
size(500, 300);              
cp5 = new ControlP5(this);            
port = new Serial(this, "/dev/tty.usbmodem143101", 9600);            
            
cp5.addButton("forward")                  
  .setPosition(190, 50)              
  .setSize(120, 70)                    
  ;                 
cp5.addButton("backward")                    
  .setPosition(190, 210)              
  .setSize(120, 70)                    
  ;              
cp5.addButton("right")                  
  .setPosition(350, 130)            
  .setSize(120, 70)            
  ;              
cp5.addButton("left")             
  .setPosition(30, 130)                
  .setSize(120, 70)                   
  ;              
cp5.addButton("stop")                 
  .setPosition(190, 130)                
  .setSize(120, 70)             
  ;              
}              
            
void draw() {              
background(150, 0, 150);              
fill(255);              
text("Motor Control GUI", 195, 30);              
}             
             
void forward() {            
 port.write('f');            
}            
void backward() {            
 port.write('b');            
}            
void right() {            
 port.write('r');            
}            
void left() {            
 port.write('l');            
}            
void stop() {            
 port.write('s');            
} </pre>



<p class="has-regular-font-size wp-block-paragraph">We will implement 5 different methods, one method for each button. the method name should be the same name as the button. this method will get called once the button gets clicked.<br><br><strong>For Example,</strong> when we click the &#8220;right&#8221; button, the&nbsp;<code>right()</code>&nbsp;method will get called. So, the Processing IDE will send the character &#8216;r&#8217; to the Arduino Serial port via Serial Communication.</p>



<h4 class="wp-block-heading">How to use it</h4>



<ul class="wp-block-list">
<li>Now all you have to do is to connect your Arduino board using the USB cable with your laptop and upload the Arduino code.</li>



<li>Then run the Processing program and enjoy your Work!</li>
</ul>



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



<p class="has-regular-font-size wp-block-paragraph">Voilaaa! Now we are able to control the Motors from Processing through the Serial Communication, but what about getting rid of the ugly USB cable. Cool, Right!<br><br>To make it wireless we will use the HC-05 Bluetooth module which has wide use, it can set as slave or master as well (unlike the HC-06 module which can work only as a slave) which means that you can make a Bluetooth connection between two different Arduino boards. the HC-05 Bluetooth module is an SPP (Serial Port Protocol) module, which means that it communicates with the Arduino board via Serial communication.</p>



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


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="605" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/final-wiringEdited.png?resize=770%2C605&#038;ssl=1" alt="Adding the Bluetooth Module" class="wp-image-148" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/final-wiringEdited.png?w=1971&amp;ssl=1 1971w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/final-wiringEdited.png?resize=800%2C628&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/final-wiringEdited.png?resize=300%2C236&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/final-wiringEdited.png?resize=768%2C603&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/final-wiringEdited.png?resize=1024%2C804&amp;ssl=1 1024w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/final-wiringEdited.png?resize=1026%2C806&amp;ssl=1 1026w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/final-wiringEdited.png?resize=675%2C530&amp;ssl=1 675w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/final-wiringEdited.png?w=1540&amp;ssl=1 1540w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Adding the Bluetooth Module</figcaption></figure>
</div>


<h4 class="wp-block-heading">Processing Code Modification (macOS &amp; Linux)</h4>



<p class="has-regular-font-size wp-block-paragraph">we need to make a slight modification in our Processing Code, we need to update our port name&nbsp;<code>"/dev/tty.usbmodem143101"</code>&nbsp;to the new HC-05 port name.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="twilight" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">port = new Serial(this, "/dev/tty.usbmodem143101", 9600);</pre>



<ul class="wp-block-list">
<li><strong>First, </strong>you need to pair your laptop with the HC-05, after powering up your Arduino board go to your Bluetooth preference on your laptop and pair with the Bluetooth module, if asked you for a passcode enter &#8220;1234&#8221;.</li>
</ul>


<div class="wp-block-image">
<figure class="aligncenter"><img loading="lazy" decoding="async" width="1560" height="1088" src="https://i1.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-5.20.16-AM.png?fit=1024%2C714&amp;ssl=1" alt="Pair with the HC-05" class="wp-image-149" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-5.20.16-AM.png?w=1560&amp;ssl=1 1560w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-5.20.16-AM.png?resize=800%2C558&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-5.20.16-AM.png?resize=300%2C209&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-5.20.16-AM.png?resize=768%2C536&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-5.20.16-AM.png?resize=1024%2C714&amp;ssl=1 1024w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-5.20.16-AM.png?resize=1026%2C716&amp;ssl=1 1026w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-5.20.16-AM.png?resize=675%2C471&amp;ssl=1 675w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Pair with the HC-05</figcaption></figure>
</div>


<ul class="wp-block-list">
<li>Create a new Processing sketch and paste this code in the new sketch and run it, after running the program it will print all the available Serial Ports on the console, choose the HC-05-DevB port.</li>
</ul>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="twilight" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">import processing.serial.*;          
Serial port;          
          
void setup(){          
 printArray(Serial.list());          
}          
void draw(){          
} </pre>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="869" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-5.20.46-AM.png?resize=770%2C869&#038;ssl=1" alt="printing all the available Serial ports" class="wp-image-150" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-5.20.46-AM.png?w=1668&amp;ssl=1 1668w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-5.20.46-AM.png?resize=800%2C903&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-5.20.46-AM.png?resize=266%2C300&amp;ssl=1 266w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-5.20.46-AM.png?resize=768%2C867&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-5.20.46-AM.png?resize=908%2C1024&amp;ssl=1 908w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-5.20.46-AM.png?resize=1026%2C1158&amp;ssl=1 1026w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-5.20.46-AM.png?resize=675%2C762&amp;ssl=1 675w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/Screen-Shot-2019-08-21-at-5.20.46-AM.png?w=1540&amp;ssl=1 1540w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">printing all the available Serial ports</figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">So in my case, I will update this line</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="twilight" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">port = new Serial(this, "/dev/tty.usbmodem143101", 9600);</pre>



<p class="has-regular-font-size wp-block-paragraph">To</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="twilight" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">port = new Serial(this, "/dev/tty.HC-05-DevB", 9600);</pre>



<h4 class="wp-block-heading">Processing Code Modification (Windows)</h4>



<ul class="wp-block-list">
<li><strong>First,</strong> you need to pair your laptop with the HC-05, after powering up your Arduino board go to your Bluetooth preference on your laptop and pair with the Bluetooth module, if asked you for a passcode enter &#8220;1234&#8221;. the Bluetooth device needs to be set up to use a COM port, open up the Bluetooth settings and press <em>More Bluetooth Options</em>.</li>
</ul>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="770" height="502" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/1.png?resize=770%2C502&#038;ssl=1" alt="Pairing Bluetooth" class="wp-image-151" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/1.png?w=971&amp;ssl=1 971w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/1.png?resize=800%2C522&amp;ssl=1 800w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/1.png?resize=300%2C196&amp;ssl=1 300w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/1.png?resize=768%2C501&amp;ssl=1 768w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/1.png?resize=675%2C440&amp;ssl=1 675w" sizes="auto, (max-width: 770px) 100vw, 770px" /><figcaption class="wp-element-caption">Pairing Bluetooth</figcaption></figure>
</div>


<ul class="wp-block-list">
<li>Switch to the <em>COM Ports</em> tab and then press the <em>Add</em> button</li>
</ul>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="423" height="504" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/2.png?resize=423%2C504&#038;ssl=1" alt="Pairing Bluetooth" class="wp-image-152" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/2.png?w=423&amp;ssl=1 423w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/2.png?resize=252%2C300&amp;ssl=1 252w" sizes="auto, (max-width: 423px) 100vw, 423px" /><figcaption class="wp-element-caption"><em>Pairing Bluetooth</em></figcaption></figure>
</div>


<ul class="wp-block-list">
<li>In the <em>Add COM Port</em> dialog select the <em>Outgoing</em> radio button. Choose the <em>HC-05</em> device under <em>Device that will use the COM Port</em> drop-down and then click <em>OK</em>.</li>
</ul>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="492" height="360" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/3.png?resize=492%2C360&#038;ssl=1" alt="Pairing Bluetooth" class="wp-image-153" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/3.png?w=492&amp;ssl=1 492w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/3.png?resize=300%2C220&amp;ssl=1 300w" sizes="auto, (max-width: 492px) 100vw, 492px" /><figcaption class="wp-element-caption"><em>Pairing Bluetooth</em></figcaption></figure>
</div>


<ul class="wp-block-list">
<li>It will assign the device to a COM port, click <em>OK</em> out of the <em>Bluetooth settings</em></li>
</ul>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" width="423" height="504" src="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/4.png?resize=423%2C504&#038;ssl=1" alt="" class="wp-image-154" srcset="https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/4.png?w=423&amp;ssl=1 423w, https://i0.wp.com/makesomestuff.org/wp-content/uploads/2019/08/4.png?resize=252%2C300&amp;ssl=1 252w" sizes="auto, (max-width: 423px) 100vw, 423px" /><figcaption class="wp-element-caption"><em>Pairing Bluetooth</em></figcaption></figure>
</div>


<p class="has-regular-font-size wp-block-paragraph">So, in this case, I will update this line</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="twilight" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">port = new Serial(this, "/dev/tty.usbmodem143101", 9600);</pre>



<p class="has-regular-font-size wp-block-paragraph">To</p>



<pre class="EnlighterJSRAW" data-enlighter-language="java" data-enlighter-theme="twilight" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">port = new Serial(this, "COM10", 9600);</pre>



<h4 class="wp-block-heading">How to use it?</h4>



<ul class="wp-block-list">
<li>After uploading the code to the Arduino board, Remove the USB cable and power up the Arduino board using the external battery.</li>



<li>connect with the HC-05 Bluetooth module from your laptop (passcode 1234).</li>



<li>Modify the Processing Code Serial Port name According to your connected Serial Port name.</li>



<li>Run the Processing Code, AND ENJOY PLAYING!</li>
</ul>



<h2 class="wp-block-heading">Thanks!</h2>



<p class="has-regular-font-size wp-block-paragraph">TADA, WE ARE DONE! if you have any questions, don&#8217;t hesitate to drop them in the comments section. And if you like this tutorial, send me some memes on my</p>



<div class="wp-block-button aligncenter"><a class="wp-block-button__link has-background wp-element-button" href="https://www.facebook.com/AhmeddEbrahem" style="border-radius:100px;background-color:#00a99d">Facebook account</a></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="9912528396"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://makesomestuff.org/how-to-control-2wd-robot-wirelessly-through-processing/">Bluetooth-Controlled 2WD Robot</a> appeared first on <a href="https://makesomestuff.org">Make Some Stuff</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://makesomestuff.org/how-to-control-2wd-robot-wirelessly-through-processing/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">99</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-24 02:47:06 by W3 Total Cache
-->