<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[My Stuff - JV Lobo]]></title><description><![CDATA[Tech, learning and tinkering.]]></description><link>https://jvlobo.com/</link><image><url>https://jvlobo.com/favicon.png</url><title>My Stuff - JV Lobo</title><link>https://jvlobo.com/</link></image><generator>Ghost 5.82</generator><lastBuildDate>Tue, 14 Apr 2026 22:28:14 GMT</lastBuildDate><atom:link href="https://jvlobo.com/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[Hacking a Timer Cube]]></title><description><![CDATA[I bought a timer cube to improve my productivity, but the time slots it had were not what I expected.
So I took it apart to "hack" it to use different ones.]]></description><link>https://jvlobo.com/hacking-a-timer-cube/</link><guid isPermaLink="false">61a254b5e68b4803f7d135a8</guid><category><![CDATA[Electronics]]></category><category><![CDATA[Productivity]]></category><dc:creator><![CDATA[JV Lobo]]></dc:creator><pubDate>Sun, 28 Nov 2021 13:36:52 GMT</pubDate><media:content url="https://jvlobo.com/content/images/2021/11/IMG_0951-2.png" medium="image"/><content:encoded><![CDATA[<img src="https://jvlobo.com/content/images/2021/11/IMG_0951-2.png" alt="Hacking a Timer Cube"><p>I was looking for a timer cube to try focusing more when I&apos;m working on something and also for taking breaks from time to time. In summary: to organize my time better. This tool consists of a small cube that has numbers on its four vertical faces. When you turn the cube a countdown timer starts from whatever number of minutes indicates the face that is pointing up.</p><p>This one on <a href="https://www.amazon.es/TFA-Dostmann-Digital-temporizador-pl%C3%A1stico/dp/B079HW6WT7?ref=jvlobo.com">Amazon</a> offers interesting time slots options for me: 5/15/30/60 minutes. It would offer me the flexibility to use it both for 100% focused work periods (usually 60 minutes) and to take 5 or 15 minutes breaks afterward. A similar working technique as the <a href="https://en.wikipedia.org/wiki/Pomodoro_Technique?ref=jvlobo.com">Pomodoro</a> one.</p><p>The cube was available in different colors and I really liked the black one, so I chose it and finished my order.<br>In a couple of days, I received it at home, but when I took it out of the box I was disappointed: the time slots were not what I was expecting &#x1F615;<br>This one came with 3/5/7/10 minutes which, for my use case, is not practical.<br>I went right away to check on Amazon and I saw that, depending on the color, they have different time slots &#x1F926;&#x1F3FD;&#x200D;&#x2642;&#xFE0F;. I guess one has to check the descriptions better when buying something.</p><p>Any normal person would have put it back inside the box and returned it to Amazon, but not me...<br>First, Amazon does not have warehouses here so returning something is a bit more complicated (you have to pay to ship it or take it to one of those pick-up points). And second, after seeing they offer many different cubes with different time slots, I thought that internally they would be the same with the only difference of having some kind of &quot;switch&quot; on the electronics to specify what time slots to use.</p><p>Curiosity got the better of me, so let&apos;s get to work. I had to open this little cube to see what was inside.</p><p>I think taking this apart has been the most complicated thing. It is very compact and it doesn&apos;t have any screws. It took me a little while to see where to start without causing too much damage to the plastics.<br>Finally, I saw on the back some grooves that made me think that there was a plastic part covering a section.</p><figure class="kg-card kg-image-card"><img src="https://jvlobo.com/content/images/2021/11/IMG_0931-2.png" class="kg-image" alt="Hacking a Timer Cube" loading="lazy"></figure><p>With plastic spudger pry tools and a big lot of patience, I managed to get it out, although it did not seem like I had achieved much. I couldn&apos;t see where to go from there. But then I was able to remove the translucent plastics that cover the LEDs and see a little more where to go.</p><figure class="kg-card kg-image-card"><img src="https://jvlobo.com/content/images/2021/11/IMG_0930-2.png" class="kg-image" alt="Hacking a Timer Cube" loading="lazy"></figure><p>Inserting the blade of an x-acto knife from the side, I was able to take off the main piece of the cube that covers all the electronics.</p><p>Analyzing the PCB, which is quite simple, I can see that there are a couple of rows with four small contact pads each and that the last column was connected &#x1F914;&#x1F914;This is what I was looking for since what I was referring to earlier is that there was some type of &quot;selector&quot; to change the configuration.</p><figure class="kg-card kg-image-card"><img src="https://jvlobo.com/content/images/2021/11/IMG_0922-1.png" class="kg-image" alt="Hacking a Timer Cube" loading="lazy"></figure><p>To check if it really works as I think, I &quot;disconnect&quot; the last column by unsoldering it and put the batteries back in, and ... BINGO !! I was right. Now the time slots that are 10/20/30/60 minutes &#x1F44F;&#x1F3FD;</p><p>Out of curiosity (which is what has brought me to this point), the interesting thing would be to go soldering / desoldering different combinations of columns to see how many options there are. I think it should work as a binary table. There are 4 bits that can be ON / OFF, so there would be 16 different combinations, but I think they are too many ...</p><p>To make the task easier, I solder a pair of sockets with four inputs each. I connect the first one to any pin of the first row (this row is connected entirely to the same line). In the second, each pad goes to a pin. Now, with some small jumpers, I can connect and disconnect each column.</p><figure class="kg-card kg-image-card kg-width-wide"><img src="https://jvlobo.com/content/images/2021/11/IMG_0924-1.png" class="kg-image" alt="Hacking a Timer Cube" loading="lazy"></figure><p>I make a small table and I try the 16 possible combinations and, to my surprise, there are many different ones, 15 in total since the first and last are the same.</p><figure class="kg-card kg-image-card"><img src="https://jvlobo.com/content/images/2021/11/DEFA15FC-658B-4132-B1DE-53975A6D8D7F.png" class="kg-image" alt="Hacking a Timer Cube" loading="lazy"></figure><!--kg-card-begin: markdown--><table>
<thead>
<tr>
<th>Configuration</th>
<th>Time slots</th>
</tr>
</thead>
<tbody>
<tr>
<td>&#x274E; &#x274E; &#x274E; &#x274E;</td>
<td>10/20/30/60</td>
</tr>
<tr>
<td>&#x274E; &#x274E; &#x274E; &#x2705;</td>
<td>3/5/7/10</td>
</tr>
<tr>
<td>&#x274E; &#x274E; &#x2705; &#x274E;</td>
<td>15/20/25/30</td>
</tr>
<tr>
<td>&#x274E; &#x274E; &#x2705; &#x2705;</td>
<td>5/10/20/30</td>
</tr>
<tr>
<td>&#x274E; &#x2705; &#x274E; &#x274E;</td>
<td>3/5/10/15</td>
</tr>
<tr>
<td>&#x274E; &#x2705; &#x274E; &#x2705;</td>
<td>5/10/15/60</td>
</tr>
<tr>
<td>&#x274E; &#x2705; &#x2705; &#x274E;</td>
<td>10/30/50/60</td>
</tr>
<tr>
<td>&#x274E; &#x2705; &#x2705; &#x2705;</td>
<td>15/30/45/60</td>
</tr>
<tr>
<td>&#x2705; &#x274E; &#x274E; &#x274E;</td>
<td>1/5/10/15</td>
</tr>
<tr>
<td>&#x2705; &#x274E; &#x274E; &#x2705;</td>
<td>5/15/30/60</td>
</tr>
<tr>
<td>&#x2705; &#x274E; &#x2705; &#x274E;</td>
<td>1/5/10/30</td>
</tr>
<tr>
<td>&#x2705; &#x274E; &#x2705; &#x2705;</td>
<td>15/20/45/60</td>
</tr>
<tr>
<td>&#x2705; &#x2705; &#x274E; &#x274E;</td>
<td>5/10/45/60</td>
</tr>
<tr>
<td>&#x2705; &#x2705; &#x274E; &#x2705;</td>
<td>5/10/15/20</td>
</tr>
<tr>
<td>&#x2705; &#x2705; &#x2705; &#x274E;</td>
<td>30/45/60/90</td>
</tr>
<tr>
<td>&#x2705; &#x2705; &#x2705; &#x2705;</td>
<td>10/20/30/60</td>
</tr>
</tbody>
</table>
<!--kg-card-end: markdown--><p>Knowing that there are even different combinations to those offered when they sell the cube, I think the one that may interest me the most is the <strong>15/30/45/60</strong> (I would have liked to have a 15/30/60/90). So I connect the last three columns.</p><figure class="kg-card kg-image-card"><img src="https://jvlobo.com/content/images/2021/11/IMG_0929-1.png" class="kg-image" alt="Hacking a Timer Cube" loading="lazy"></figure><p>The solder joins some of the pads of the first row but it does not matter because, as I said before, this row is connected entirely to the same line.</p><p>I reassemble the cube. The problem now is that the numbers on the four faces are not the same as the ones I just set.<br>Since I have a 3D printer, it occurs to me to do a quick design with the new numbers. Some kind of patch that I can stick on top.</p><p>I print it with a technique to have more than one color in the same piece, so you can see the numbers much better.</p><figure class="kg-card kg-image-card kg-width-wide"><img src="https://jvlobo.com/content/images/2021/11/IMG_0937-1.png" class="kg-image" alt="Hacking a Timer Cube" loading="lazy"></figure><p>The only thing left is to glue them on the corresponding faces and enjoy my &quot;new&quot; timer cube &#x1F601;</p><figure class="kg-card kg-image-card"><img src="https://jvlobo.com/content/images/2021/11/IMG_0943-1.png" class="kg-image" alt="Hacking a Timer Cube" loading="lazy"></figure><p>Final result:</p><figure class="kg-card kg-embed-card"><iframe width="356" height="200" src="https://www.youtube.com/embed/6q0l4BIFMOo?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></figure>]]></content:encoded></item><item><title><![CDATA[5 tips for shipping side projects with a full-time job]]></title><description><![CDATA[Creating something is not easy.
I will tell you five tips I follow in order to perform better and embrace the spare moments as much as possible. I hope it helps you the way it helps me 🙂]]></description><link>https://jvlobo.com/5-tips-for-shipping-side-projects-with-a-full-time-job/</link><guid isPermaLink="false">5f26d393d513bd6c741b1030</guid><category><![CDATA[Motivation]]></category><category><![CDATA[Productivity]]></category><category><![CDATA[Side Project]]></category><dc:creator><![CDATA[JV Lobo]]></dc:creator><pubDate>Mon, 03 Aug 2020 17:43:53 GMT</pubDate><media:content url="https://images.unsplash.com/photo-1483058712412-4245e9b90334?ixlib=rb-1.2.1&amp;q=80&amp;fm=jpg&amp;crop=entropy&amp;cs=tinysrgb&amp;w=2000&amp;fit=max&amp;ixid=eyJhcHBfaWQiOjExNzczfQ" medium="image"/><content:encoded><![CDATA[<img src="https://images.unsplash.com/photo-1483058712412-4245e9b90334?ixlib=rb-1.2.1&amp;q=80&amp;fm=jpg&amp;crop=entropy&amp;cs=tinysrgb&amp;w=2000&amp;fit=max&amp;ixid=eyJhcHBfaWQiOjExNzczfQ" alt="5 tips for shipping side projects with a full-time job"><p><em>This post contains affiliate links. For more information, see my disclosures <a href="https://jvlobo.com/disclaimer/">here</a>.</em></p><p>Creating something is not easy. Probably everyone that has done it before will tell you that. It gets even more difficult when you don&apos;t have all the time you would like because you are selling your time to someone else.</p><p>That is my case: I have been working for others for more than 5 years and I have always tried to get the most out of my free time to work on my own projects and create new things.</p><p>One of my latest side projects is <a href="https://codetalks.tv/?ref=jvlobo.com">codetalks.tv</a> where we are about to reach 600 registered users and 4.5k tech videos. We built CodeTalksTV in around 4 months while working full time and these are the 5 tips I followed in order to perform better and embrace the spare moments as much as possible. I hope it helps you, the way it helps me &#x1F642;</p><h2 id="everything-has-to-do-with-motivation-how-to-find-it">Everything has to do with motivation: how to find it</h2><h3 id="internal-motivation">Internal motivation</h3><p>I define internal motivation as the one that you already have from the moment that you are thinking about starting a side project. However, it is not only the willingness of &quot;wanting to do something&quot;. Because, that something has to be a project that you are super passionate about, otherwise, you will not dedicate the necessary time and you will leave it aside at the first chance you get.</p><h3 id="external-motivation">External motivation</h3><p>Internal motivation goes hand in hand with external motivation. For me, external motivation is the crazy assortment of resources that, nowadays, you have at your hands which can be really helpful in giving you the strength to work on your project day after day.</p><p>In my case, I consume content that is closely connected to the world of entrepreneurship, indie hackers and technology such as blogs, podcasts, books, newsletters, videos, communities...</p><p>I think it is always of great help to hear success stories from other entrepreneurs and to hear how they have created something from scratch. Personally, this type of stories motivate me a lot, because if these people can do it, why wouldn&#x2019;t I be able to do it too?</p><p>Here is a list of resources I use to get that extra piece of motivation I need:</p><!--kg-card-begin: markdown--><ul>
<li>
<p>Podcasts</p>
<ul>
<li><strong><a href="https://open.spotify.com/show/4ex8hmrHCPvPohKJb3wsuC?si=FN9L2NIoS_-HveuHxt4LXA&amp;ref=jvlobo.com">IndieHackers:</a></strong> very detailed interviews with people who are building projects where they explain literally everything on how they built them and how the projects are doing after their launch.</li>
<li><strong><a href="https://open.spotify.com/show/5JxcIaIkN8zx3Zy7yD9snv?si=lEu35klxT7-aN6QiHwVyEA&amp;ref=jvlobo.com">Rework:</a></strong> podcast from <a href="https://basecamp.com/?ref=jvlobo.com">Basecamp</a>, the company. I really like how they do things in a different way.</li>
<li><strong><a href="https://open.spotify.com/show/1tgqafxZAB0Bjd8nkwVtE4?si=ulPN8-kdS9qXSnKSLOLHUg&amp;ref=jvlobo.com">Y Combinator:</a></strong> looks like it has been inactive for a while, but still interesting to listen to the episodes they still have on Spotify Podcasts.</li>
</ul>
</li>
<li>
<p>Newsletters</p>
<ul>
<li><strong><a href="https://bloggingfordevs.com/?ref=jvlobo.com">Blogging For Devs:</a></strong> I really like Monica&apos;s content and she is building an awesome community of devs who like to create content. 100% recommended!</li>
<li><strong><a href="https://engineergrowth.substack.com/?ref=jvlobo.com">Engineer Growth:</a></strong> interesting and very actionable tips to grow your project or business.</li>
<li><strong><a href="https://growthinsider.substack.com/?ref=jvlobo.com">Growth Insider:</a></strong> also an interesting resource for actionable tips. Lately, they&apos;re doing some cool case studies about well-known apps and services.</li>
</ul>
</li>
<li>
<p>Books</p>
<ul>
<li><strong><a href="https://amzn.to/2BSzyVZ?ref=jvlobo.com">Deep Work:</a></strong> this is one of the latest books I&apos;ve read and I got super inspired by how people get into that deep mental state where they can work without any interruptions. No social media,  no messaging, <em>no distractions</em>. This is one of my goals.</li>
<li><strong><a href="https://amzn.to/318E8bm?ref=jvlobo.com">Elon Musk biography:</a></strong> Elon... always inspiring for me.</li>
<li><strong><a href="https://amzn.to/2D7eL1P?ref=jvlobo.com">Founders at Work: Stories of Startups&apos; Early Days:</a></strong> a deep look at how some big business started.</li>
<li><strong><a href="https://amzn.to/3k7peLi?ref=jvlobo.com">Zero To One:</a></strong> I think this one is very well known but still a good one to have on the list.</li>
<li><strong><a href="https://amzn.to/39SkGU9?ref=jvlobo.com">The $100 Startup:</a></strong> good motivation to start your own thing.</li>
<li><strong><a href="https://amzn.to/31gHOI2?ref=jvlobo.com">ReWork:</a></strong> like the podcast, also from Basecamp. This is a good book on how to do work &quot;differently&quot;, which is the way they do it.</li>
<li><strong><a href="https://amzn.to/3k7tE4D?ref=jvlobo.com">It Doesn&#x2019;t Have to Be Crazy at Work:</a></strong> also by Basecamp and also about how they work differently. Love these people! haha</li>
</ul>
</li>
<li>
<p>Videos</p>
<ul>
<li><strong><a href="https://www.youtube.com/channel/UCpExuV8qJMfCaSQNL1YG6bQ?ref=jvlobo.com">YouTube Channel: Better than Yesterday:</a></strong> always important to keep learning and growing as a person.</li>
<li><strong><a href="https://youtu.be/fAz8rLQmbKw?ref=jvlobo.com">Elon Musk - Gangsta&apos;s Paradise:</a></strong> at this point you probably know I get motivated by Elon Musk and his work &#x1F602; I find this short video very inspiring.</li>
<li><strong><a href="https://www.youtube.com/results?search_query=ted+talks+motivation&amp;ref=jvlobo.com">YouTube search: Ted Talks motivation:</a></strong> I couldn&apos;t recommend a single Ted Talk because I&apos;ve watched many of them and each one motivates you in a different way.</li>
<li><strong><a href="https://www.youtube.com/c/AbsoluteMotivation/videos?ref=jvlobo.com">YouTube Channel: Absolute Motivation:</a></strong> &quot;random&quot; motivation, is also good motivation.</li>
</ul>
</li>
<li>
<p>Other resources</p>
<ul>
<li><strong><a href="https://growth.design/case-studies/?ref=jvlobo.com">Growth.design Case Studies:</a></strong> this recommendation is one of the last but definitely one of the best. Every case study of these guys is a piece of art. And the tips they provide are pure gold.</li>
<li><strong><a href="https://www.indiehackers.com/?ref=jvlobo.com">IndieHackers:</a></strong> as with the podcast, the entire platform is a very good resource to get inspired and connect with like-minded people.</li>
</ul>
</li>
</ul>
<!--kg-card-end: markdown--><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://jvlobo.com/content/images/2020/08/Screenshot-2020-08-03-at-17.43.15.png" class="kg-image" alt="5 tips for shipping side projects with a full-time job" loading="lazy"><figcaption>growth.design case studies</figcaption></figure><h2 id="announce-it-to-the-world-">Announce it to the world.</h2><p>In my honest opinion it is a worthy way to put some pressure on yourself in order to not give up once you&#x2019;ve started a project.</p><p>Ok, <em>maybe</em> not to the world, but going public can simply mean telling a good friend, your partner, or a family member. If you are part of a community like IndieHackers you can start a project and then keep updating it with <strong><a href="https://www.indiehackers.com/milestones?ref=jvlobo.com">milestones</a> </strong>which I think is a great way to feel that accountability.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://jvlobo.com/content/images/2020/08/Screenshot-2020-08-03-at-17.05.20.png" class="kg-image" alt="5 tips for shipping side projects with a full-time job" loading="lazy"><figcaption>IndieHackers Milestones</figcaption></figure><p>If social networks are where you feel the most comfortable, it is also a good place to say that you are starting a personal project.</p><p>Also, if you have a personal blog you could get a side benefit from writing about your side project: content marketing. That way, if you get people to follow your progress, you can get potential customers or users because they know the effort you are putting into building something that they may want to use.</p><p>The idea is to keep showing progress, feel the need that you &quot;owe&quot; something to someone, and you have to keep working to show new things.</p><h2 id="do-not-waste-time">Do. NOT. Waste. Time</h2><p>Time is limited. And having a full-time job does not help your gig, as you probably spend most of your active hours working for others. That&apos;s why making the most of your free time is crucial. If you don&apos;t have too many obligations apart from your work, you might be surprised that you have more free time than you think.</p><p>Taking into account that a day has 24 hours, of which you work an average of 8 hours, and depending on whether you have to get around to go to the office or not add 1 or 2 more hours of commute: 10 hours. An average person should get enough rest by sleeping for about 8 hours. This is 18 &quot;busy&quot; hours, which leaves you 5 hours each day to take advantage of. In addition to weekends, with a good organization, you can do many things with this free time. Of course, I&#x2019;m assuming you don&#x2019;t have children or people to take care of, as it can be trickier that way. But a tip I have is: get the most out of your weekends, and the couple of hours you might have after putting the kids to sleep.</p><p>These types of calculations are done many times to see that we really have free hours a day, but obviously each person has its life and each day is different. What is very clear to me is this: if you really want to do something and you have the right motivation, you are going to get the most out of every free minute you have in your day. Imagine that you put 2 hours per day into your project, those hours will add up to 60 hours per month. And <strong>60</strong> is better than <strong>0</strong>.</p><p>In addition to make the most of your day, be mindful of when you are the most productive during the day. There are people who have more energy and a more active mind at certain times of the day so <strong>find your perfect time</strong>.</p><p>For example, while we were building <a href="https://codetalks.tv/?ref=jvlobo.com">CodeTalks</a> I was living in Australia and I used to wake up very early, around 5 or 6 am since during the summer months it dawns very early and at a very good temperature. These conditions gave me a whole lot of energy, hence I always took a couple of hours to get my hands deep into this project before I had to go to my actual job.</p><p>I&apos;m aware of how easy it is to say this but then how difficult it is to actually accomplish it. Getting home after a long day at the office the last thing you want to do is to get back to coding or researching, sometimes your brain is just off and asking for some YouTube or funny memes.</p><p>There are some methods you can follow to do better. Personally I like to write down a list of things I want to accomplish and feel the reward of crossing out items of this list. <em>Make sure you keep it short so you don&#x2019;t lose motivation</em>. And then, to inject me some quick dopamine into my brain, it&#x2019;s nice to get some small breaks to do something non-work related.</p><p>I really like this small app a friend of mine built: <a href="http://dopamine.netlify.app/?ref=jvlobo.com">Dopamine</a>. With this app, you can start a timer when you are working and you&apos;ll earn some &quot;dopamine points&quot; that you can spend on YouTube, social media, or somewhere else. So basically for every 60 minutes of work you get 15 dopamine points to spend. Every dopamine point equals 1 minute. I think it is an interesting concept to balance working and enjoyment time.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://jvlobo.com/content/images/2020/08/Screenshot-2020-08-03-at-17.54.02-copy-2.png" class="kg-image" alt="5 tips for shipping side projects with a full-time job" loading="lazy"><figcaption>Dopamine app</figcaption></figure><h2 id="take-care-of-your-body">Take care of your body</h2><p>In a word: <strong>move.</strong></p><p>Whether it is going to/coming from work walking or doing some exercise at the end of the day.</p><p>I personally enjoy going back home walking from the office (around 25-30min) as well as going for a run to take a break between work and get on with my project.</p><p>I think it&#x2019;s very important to clearly separate your working day at the office and your &quot;working day&quot; on your side project. It will allow you to be much more productive after work.</p><p>We also underestimate the importance of good sleep. More than 5 years ago I bought one of those smart bands so I could track my sleep (among other things) and it has been very interesting to see how the amount of time I spend sleeping correlates to how sharp and energized I feel the next day. I have also been able to know the exact amount of sleep I need to be fresh the next day: ~7:30h of total sleep with ~2hours of deep sleep. If I get that amount of sleep I&apos;m sure I&apos;ll be good and full of energy for the day &#x1F4AA;&#x1F3FE;</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://jvlobo.com/content/images/2020/08/IMG_CC5CC3C9F775-1-1.jpeg" class="kg-image" alt="5 tips for shipping side projects with a full-time job" loading="lazy"><figcaption>My average sleeping time in a week</figcaption></figure><p>I recommend you do something like that. If you don&apos;t have a smart band or don&apos;t want to spend money on one (although you can <a href="https://amzn.to/31iuKlH?ref=jvlobo.com">get one for cheap</a>) you can do it with <a href="https://www.lifehack.org/816199/best-sleep-tracker?ref=jvlobo.com">your smartphone</a>.</p><h2 id="take-care-of-your-mind">Take care of your mind</h2><p>Just like exercising helps to clear the mind and stretch the muscles, I think it is also important to take mental breaks from time to time.</p><p>If one day you feel like doing nothing when you leave the office, no problem! it is also necessary to relax the mind so as not to burn yourself.</p><p>Watch some Netflix, meet with a friend for a coffee (or beer!)... it&apos;s up to you, whatever helps you relax your mind. You can also try <a href="https://www.womenshealthmag.com/health/g25178771/best-meditation-apps/?ref=jvlobo.com">meditation apps</a>.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://jvlobo.com/content/images/2020/08/calm-app.jpg" class="kg-image" alt="5 tips for shipping side projects with a full-time job" loading="lazy"><figcaption>Calm App - Sleep, Meditation and Relaxation</figcaption></figure><hr><p>My goal with this article is that you can get that extra motivation to start working on your projects too. Hopefully, I achieved it &#x1F91E;&#x1F3FD;</p><p>I would love to hear your ideas and projects so I encourage you to write something down in the comments or contact me at my email!</p>]]></content:encoded></item><item><title><![CDATA[How to make clock-in at work easier with the ESP32 board - Part 2]]></title><description><![CDATA[At work we use Calamari.io to track working time. I built a box, with the ESP32 board inside, to make clock-in and clock-out easier and more interesting. This is the second part of the article.]]></description><link>https://jvlobo.com/esp32-clock-in-with-calamari-io-part-2/</link><guid isPermaLink="false">5ed54921cbe5be7b00db8f86</guid><category><![CDATA[Electronics]]></category><category><![CDATA[ESP32]]></category><dc:creator><![CDATA[JV Lobo]]></dc:creator><pubDate>Tue, 02 Jun 2020 17:38:43 GMT</pubDate><media:content url="https://jvlobo.com/content/images/2020/06/calamari_post_image_smaller-min-2.png" medium="image"/><content:encoded><![CDATA[<img src="https://jvlobo.com/content/images/2020/06/calamari_post_image_smaller-min-2.png" alt="How to make clock-in at work easier with the ESP32 board - Part 2"><p><em>This post contains affiliate links. For more information, see my disclosures <a href="https://jvlobo.com/disclaimer/">here</a>.</em></p><p>As I mentioned in the previous article, in this second part I am going to install a battery in the system and also design a box to organise everything.</p><figure class="kg-card kg-bookmark-card kg-card-hascaption"><a class="kg-bookmark-container" href="https://jvlobo.com/esp32-clock-in-with-calamari-io-part-1/"><div class="kg-bookmark-content"><div class="kg-bookmark-title">How to make clock-in at work easier with the ESP32 board - Part 1</div><div class="kg-bookmark-description">At work we use Calamari.io to track working time. I built a box, with the ESP32 board inside, to make clock-in and clock-out easier and more interesting.</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://jvlobo.com/favicon.png" alt="How to make clock-in at work easier with the ESP32 board - Part 2"><span class="kg-bookmark-author">My Stuff - JV Lobo</span><span class="kg-bookmark-publisher">JV Lobo</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://jvlobo.com/content/images/2020/06/calamari_post_image_optimized-2.png" alt="How to make clock-in at work easier with the ESP32 board - Part 2"></div></a><figcaption>Don&apos;t miss the first part!</figcaption></figure><p>&#x1F50B; To power the system I thought about reusing an old iPhone battery that I had lying around.</p><p>If you take a closer look at an iPhone battery, at first you may think that it has a strange connection and that it cannot be reused, but it really is a lithium battery like any other, with its positive and negative terminals, only they are hidden under the adhesive tape.</p><p>If we remove this tape, you can clearly see the two terminals and the small board that Apple uses along with its connector.</p><p>It is only needed to remove this part and check which one is the positive terminal and which one is the negative (with the help of a <a href="https://amzn.to/2MkG5dM?ref=jvlobo.com">multimeter</a>) and solder a pair of wires:</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://jvlobo.com/content/images/2020/06/iPhone_battery_optimized-3.png" class="kg-image" alt="How to make clock-in at work easier with the ESP32 board - Part 2" loading="lazy"><figcaption>Reusing and old iPhone battery</figcaption></figure><p>But of course, with this we can provide power to the circuit until the battery charge is used up, but then what? How can we recharge the battery? &#x1F50C;</p><p>For this there are some small boards called <a href="https://amzn.to/300NlU6?ref=jvlobo.com">lithium battery charging modules</a>, which usually come with mini-USB or micro-USB input, and soldering the terminals to this module serve to recharge the battery. They also include charge and discharge protection.<br>This board comes with two output terminals that are the ones that we will connect to our circuit.</p><p>The assembly scheme would look something like this:</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://jvlobo.com/content/images/2020/06/battery_connection_optimized-2.png" class="kg-image" alt="How to make clock-in at work easier with the ESP32 board - Part 2" loading="lazy"><figcaption>Battery connection</figcaption></figure><p>&#x1F469;&#x1F3FD;&#x200D;&#x1F3A8; The next step is to design the box in 3D.</p><p>About a year ago I bought the <a href="https://amzn.to/2U3q9AV?ref=jvlobo.com">Ender 3 Pro</a> and I have been printing in 3D ever since but when I have designed things I have always done it on <a href="http://tinkercad.com/?ref=jvlobo.com">Tinkercad</a> which is very easy to use and offers quite good results. For this project I wanted to learn how to use <a href="https://www.autodesk.com/products/fusion-360/overview?ref=jvlobo.com">Fusion 360</a> which offers more possibilities and with which you can make somewhat more complex designs.</p><p>The first thing I do when I&apos;m going to design something is obviously take measurements &#x1F4D0;. I always use my <a href="https://amzn.to/2Bi8wGU?ref=jvlobo.com">caliper</a>, the most accurate tool for this task.</p><p>I took the measurements of all the components that will go inside the box. I am going to use two large buttons, the ones used in old arcade machines. I will also put a switch to turn the system on and off. I will install a small vibration motor so that, after pressing any of the buttons, I will receive confirmation when the action has been carried out correctly.</p><p>For the box I had a fairly simple structure in mind: rectangular with two button holes on the top, a micro-USB port on one side for charging and a switch to turn the system on or off on the other side.</p><p>After quite a few hours learning and designing with Fusion 360 I came up with something that I was comfortable with &#x1F44D;&#x1F3FE;:</p><figure class="kg-card kg-embed-card kg-card-hascaption"><iframe width="480" height="270" src="https://www.youtube.com/embed/LoApmADyqFw?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe><figcaption>Fusion 360 design process</figcaption></figure><p>This is a three-piece design:</p><ul><li>The upper part, where the buttons go, and that has enough height to house the components inside.</li><li>A part with supports to host the electronic components and with space underneath to accommodate the battery.</li><li>The bottom lid, used to close the box and put the screws that will also go through the other two parts so that everything is securely fastened.</li></ul><p>When I design this type of pieces in 3D, instead of designing and printing everything at once without knowing if they are going to fit well (which takes a long time and uses too much filament), what I usually do is print small sections that I consider &quot;critical&quot;. They are parts that because of where they are or the way I have designed them, I am not sure if they will turn out as I have in my mind &#x1F914;. Because when you are designing, everything is &quot;perfect&quot;, but once it is printed it doesn&apos;t turn out as it does in the design. Also there are things that may not be well designed or need to be redesigned to make them look better. You also have to take into account the tolerances between different pieces that fit or are next to each other, because the printed material is not perfect, and usually it will have a greater thickness than the one you have designed.</p><p>In this design, for example: the part such as the holes for the buttons, the part where the components are mounted, &#xA0;the top part in the area where it connects to the other two parts or the part of the logo and the letters. These parts to my understanding were the most critical ones and I printed small sections to be able to check and correct errors. And thank goodness I did it, because I had to redesign certain parts &#x1F605;.</p><p>Here you can see the measurements I took and the parts I printed to check and correct in the design:</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://jvlobo.com/content/images/2020/06/IMG_8723.JPG" class="kg-image" alt="How to make clock-in at work easier with the ESP32 board - Part 2" loading="lazy"><figcaption>Measurements and test prints</figcaption></figure><p>Finally, with all the parts well designed I was able to print everything, which took quite some time &#x23F3;:</p><ul><li><strong>Top piece</strong>: about <strong>11 hours</strong> and about <strong>20 meters</strong> of filament.</li><li><strong>Centerpiece</strong>: about <strong>4 hours</strong> and about <strong>6 meters</strong> of filament.</li><li><strong>Bottom piece</strong>: about <strong>7 hours</strong> and about <strong>11 meters</strong> of filament.</li><li><strong>Letters and logo</strong>: less than <strong>1 hour</strong> and over <strong>1 meter</strong> of filament.</li></ul><figure class="kg-card kg-embed-card kg-card-hascaption"><iframe width="480" height="270" src="https://www.youtube.com/embed/NCH0nlL9CwA?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe><figcaption>3D print with a duration of 11 hours</figcaption></figure><p>After printing all the pieces I had to sand them, especially the front part where the logo and letters go.</p><p>Finally the moment I was looking forward: the final assembly! &#x1F468;&#x1F3FD;&#x200D;&#x1F527;</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://jvlobo.com/content/images/2020/06/fullsizeoutput_2319.jpeg" class="kg-image" alt="How to make clock-in at work easier with the ESP32 board - Part 2" loading="lazy"><figcaption>All the components ready to be assembled</figcaption></figure><p>Although the buttons are different, they are still connected to the same pins as in the prototype: <code>26</code> to start/end the shift and <code>27</code> to start/end the lunch break. The vibration motor will be connected to pin <code>17</code>.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://jvlobo.com/content/images/2020/06/Calamari_Box_Schema_bb_transparent.png" class="kg-image" alt="How to make clock-in at work easier with the ESP32 board - Part 2" loading="lazy"><figcaption>Wiring diagram</figcaption></figure><p>The tip of my soldering iron is very worn, which made it difficult for me to make a good solder.<br>After much soldering and connecting cables:</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://jvlobo.com/content/images/2020/06/fullsizeoutput_231d.jpeg" class="kg-image" alt="How to make clock-in at work easier with the ESP32 board - Part 2" loading="lazy"><figcaption>All the parts connected</figcaption></figure><p>With everything connected, and before closing the box, I had to make some adjustments to the code.</p><p>First, to control the vibration motor. It is very simple, I just configured pin <code>17</code> as output and each time a button is pressed, separate signals are sent to the motor in different time ranges so that it makes a vibration pattern. I have created two patterns: one for when the shift or the lunch break starts and the other for when it ends. You can see it in version 2 of the source code that I will leave in a link at the end of the article.</p><p>Besides, since the system is going to be connected to the battery and since it is only going to perform the action when one of the buttons is pressed, ideally it should not be working all the time. For this you can make use of the deep sleep function of the ESP32 &#x1F4A4;. It is very simple to configure, the idea is that once the system boots, it goes into sleep mode, and only wakes up when one of the buttons is pressed. Depending on the button pressed, it will perform the corresponding action and once it is finished, it returns to deep sleep mode.</p><figure class="kg-card kg-bookmark-card kg-card-hascaption"><a class="kg-bookmark-container" href="https://randomnerdtutorials.com/esp32-deep-sleep-arduino-ide-wake-up-sources/?ref=jvlobo.com"><div class="kg-bookmark-content"><div class="kg-bookmark-title">ESP32 Deep Sleep with Arduino IDE and Wake Up Sources | Random Nerd Tutorials</div><div class="kg-bookmark-description">Complete guide for the ESP32 Deep Sleep mode with Arduino IDE and different wake up sources: timer wake up, touch wake up, and external wake up (with examples).</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://i2.wp.com/randomnerdtutorials.com/wp-content/uploads/2018/03/n-favicon-2018.png?fit=16%2C16&amp;ssl=1" alt="How to make clock-in at work easier with the ESP32 board - Part 2"><span class="kg-bookmark-author">Random Nerd Tutorials</span><span class="kg-bookmark-publisher">Alain</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://i1.wp.com/randomnerdtutorials.com/wp-content/uploads/2019/02/esp32-deep-sleep-arduino-ide.jpg?fit=840%2C473&amp;ssl=1" alt="How to make clock-in at work easier with the ESP32 board - Part 2"></div></a><figcaption>It was of great help for configuring deep mode</figcaption></figure><p>And this is it, once the new code was uploaded to the board, it was time to put the screws in and see the final result.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://jvlobo.com/content/images/2020/06/fullsizeoutput_2324.jpeg" class="kg-image" alt="How to make clock-in at work easier with the ESP32 board - Part 2" loading="lazy"><figcaption>Final result</figcaption></figure><p>And here you can find the new part of the code, it is in the <code>v2</code> branch.</p><figure class="kg-card kg-bookmark-card"><a class="kg-bookmark-container" href="https://github.com/jvlobo/esp32-calamari.io-api/tree/v2?ref=jvlobo.com"><div class="kg-bookmark-content"><div class="kg-bookmark-title">jvlobo/esp32-calamari.io-api</div><div class="kg-bookmark-description">Clocking in and out in Calamari.io with the ESP32 development board - jvlobo/esp32-calamari.io-api</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://github.githubassets.com/favicons/favicon.svg" alt="How to make clock-in at work easier with the ESP32 board - Part 2"><span class="kg-bookmark-author">GitHub</span><span class="kg-bookmark-publisher">jvlobo</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://avatars0.githubusercontent.com/u/5671420?s=400&amp;v=4" alt="How to make clock-in at work easier with the ESP32 board - Part 2"></div></a></figure><p>The final test:</p><figure class="kg-card kg-embed-card"><iframe width="480" height="270" src="https://www.youtube.com/embed/vhSgYKIwZEE?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></figure><p>It works!! &#x1F389;</p>]]></content:encoded></item><item><title><![CDATA[How to make clock-in at work easier with the ESP32 board - Part 1]]></title><description><![CDATA[At work we use Calamari.io to track working time. I built a box, with the ESP32 board inside, to make clock-in and clock-out easier and more interesting. This is the first part of the article.]]></description><link>https://jvlobo.com/esp32-clock-in-with-calamari-io-part-1/</link><guid isPermaLink="false">5ead8d6c77288568f500cecd</guid><category><![CDATA[Electronics]]></category><category><![CDATA[ESP32]]></category><dc:creator><![CDATA[JV Lobo]]></dc:creator><pubDate>Tue, 02 Jun 2020 17:32:40 GMT</pubDate><media:content url="https://jvlobo.com/content/images/2020/06/calamari_post_image_smaller-min-1.png" medium="image"/><content:encoded><![CDATA[<img src="https://jvlobo.com/content/images/2020/06/calamari_post_image_smaller-min-1.png" alt="How to make clock-in at work easier with the ESP32 board - Part 1"><p><em>This post contains affiliate links. For more information, see my disclosures <a href="https://jvlobo.com/disclaimer/">here</a>.</em></p><p>In 2019, a regulation came into force in Europe by which companies are required to have a <a href="https://www.euronews.com/2019/05/15/all-companies-must-record-employees-working-hours-eu-court-rules?ref=jvlobo.com">daily record of the hours of their employees</a>.</p><p>There are many online tools to keep track of this. At <a href="https://desygner.com/?ref=jvlobo.com">Desygner</a> we use <a href="https://calamari.io/?ref=jvlobo.com">Calamari.io</a>.</p><p>We use Slack as a communication tool and we have commands for clocking in / out from Calamari.<br>The problem is that sometimes I forget to write the command in Slack to start or end my working day &#x1F926;&#x1F3FD;&#x200D;&#x2642;&#xFE0F;</p><p>Thinking about solutions to make it easier, and since I like to tinker with electronics, I thought about building a small device with a couple of buttons with which I could start and end my shift and register the lunch break. All I needed was for Calamari to offer an API to communicate with, and <a href="https://developers.calamari.io/?ref=jvlobo.com">they have one</a>! &#x1F44F;&#x1F3FD;</p><p>Now, it was time to choose where to start building this system. Previously, I had used <a href="https://wikipedia.org/wiki/Arduino?ref=jvlobo.com">Arduino</a> for electronics projects but now I was going to need WiFi connection and the cheapest option of this brand is the <a href="https://amzn.to/3ds5Y7w?ref=jvlobo.com">Arduino Nano 33 IoT</a> at around $25 on Amazon. Several people had recommended me to use the ESP32 board that also includes WiFi and Bluetooth and you can find it on <a href="https://amzn.to/2TXKSG4?ref=jvlobo.com">Amazon</a> for $10.</p><p>This was the chosen one:</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://jvlobo.com/content/images/2020/05/Esp32DevkitCNewChip1x_1600x-2_optimized.png" class="kg-image" alt="How to make clock-in at work easier with the ESP32 board - Part 1" loading="lazy"><figcaption>ESP32 Board</figcaption></figure><p>This was my first time working with the ESP32 board, so after the first steps to get it working with my computer and <a href="https://wikipedia.org/wiki/Arduino_IDE?ref=jvlobo.com">Arduino IDE</a>, the next thing I wanted to do was connect it to the WiFi network.</p><p>My first idea was to have an app or web with which to connect via Bluetooth to the board, and once there, through an interface, be able to select the network to connect it to and write the password. It sounded great! However, after searching a lot about how to connect the ESP32 board via WiFi I did not find anything similar already done. So I opted for a simpler option: hardcode the name and password of the WiFi network in the code. The downside of this is that every time I want to shift networks I need to change the code and compile it back to the board.</p><!--kg-card-begin: markdown--><pre><code class="language-arduino">#include &quot;WiFi.h&quot; //ESP32 WiFi library

WiFi.mode(WIFI_STA);
WiFi.begin(&quot;Wifi_SSID&quot;, &quot;WiFiPassword&quot;);

uint8_t i = 0;
while (WiFi.status() != WL_CONNECTED) {
  delay(500);

  if ((++i % 16) == 0) {
    Serial.println(F(&quot; still trying to connect&quot;));
  }
}

Serial.print(F(&quot;Connected. My IP address is: &quot;));
Serial.println(WiFi.localIP());
</code></pre>
<!--kg-card-end: markdown--><figure class="kg-card kg-bookmark-card kg-card-hascaption"><a class="kg-bookmark-container" href="https://www.megunolink.com/articles/wireless/how-do-i-connect-to-a-wireless-network-with-the-esp32?ref=jvlobo.com"><div class="kg-bookmark-content"><div class="kg-bookmark-title">How do I connect to a wireless network with the ESP32? | Wireless | MegunoLink</div><div class="kg-bookmark-description">Create a simple Arduino library to store your WiFi network credentials. They&#x2019;ll be easy to use and you won&#x2019;t accidentally copy them to the Internet.</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://www.megunolink.com/wp-content/uploads/2015/09/FAVICON.png" alt="How to make clock-in at work easier with the ESP32 board - Part 1"><span class="kg-bookmark-author">MegunoLink</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://www.megunolink.com/wp-content/uploads/2018/09/esp32andwifi_small.jpg" alt="How to make clock-in at work easier with the ESP32 board - Part 1"></div></a><figcaption>This guide was helpful</figcaption></figure><p>Once connected to the network, the next important step was to find out how to communicate over the Internet, needed to be able to make calls to Calamari&apos;s API.</p><p>This, similar to the WiFi connection, is not a complex task since there are libraries that we can use to help us. In this case, I used the library <code>&lt;HTTPClient.h&gt;</code>.</p><p>For this first test of how to make HTTP calls I didn&apos;t want to mess with Calamari&apos;s API just yet, hence I used a service that offers a mock <a href="https://en.wikipedia.org/wiki/Representational_state_transfer?ref=jvlobo.com">REST API</a> for testing: <a href="https://jsonplaceholder.typicode.com/?ref=jvlobo.com">JSONPlaceholder</a>.</p><!--kg-card-begin: markdown--><pre><code class="language-arduino">#include &quot;HTTPClient.h&quot;

HTTPClient http;

http.begin(&quot;https://jsonplaceholder.typicode.com/posts/1&quot;);
int httpCode = http.GET();

if (httpCode &gt; 0) {
  String response = http.getString();
  Serial.println(httpCode);
  Serial.println(response);
} else {
  Serial.println(&quot;Error on HTTP request: &quot;);
  Serial.println(httpCode);
}

http.end();
</code></pre>
<!--kg-card-end: markdown--><figure class="kg-card kg-bookmark-card kg-card-hascaption"><a class="kg-bookmark-container" href="https://www.dfrobot.com/blog-917.html?ref=jvlobo.com"><div class="kg-bookmark-content"><div class="kg-bookmark-title">ESP32 Arduino Tutorial: Getting weather data from API</div><div class="kg-bookmark-description">In this esp32 tutorial, we will check how to use the ESP32 to request weather data from an API for a given city, using the Arduino core.</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://www.dfrobot.com/image/logo/icon-100x100.png" alt="How to make clock-in at work easier with the ESP32 board - Part 1"><span class="kg-bookmark-author">DFRobot</span><span class="kg-bookmark-publisher">DFRobot Apr 20 2018</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://image.dfrobot.com/image/topbanner/TOPbanner_%E7%94%BB%E6%9D%BF%201.jpg" alt="How to make clock-in at work easier with the ESP32 board - Part 1"></div></a><figcaption>I followed this guide</figcaption></figure><p>With everything set up, I was ready to make requests to the Calamari.io API.</p><p>I created a class to have everything tidier and make the operation easier within the code. I helped myself with <a href="https://www.arduino.cc/en/Hacking/LibraryTutorial?ref=jvlobo.com">this guide</a> to do it. You can see how I built it in the link at the end of the article with the repository on Github.</p><p>To use the class you just need to create an instance and pass four arguments, the base URL of the Calamari.io API, the username and password (information that Calamari provides when you activate the API) and the employee&apos;s email (in this case my corporate email).</p><p>The class has six methods available to use. I think the names are understandable enough:</p><ul><li>Shift: <code>shiftIsOn()</code>, <code>startShift()</code>, <code>stopShift()</code></li><li>Break: <code>breakIsOn()</code>, <code>startLunchBreak()</code>, <code>stopLunchBreak()</code></li></ul><p>After a bit of trial and error, I got everything working. I was only missing the hardware part: a button to start/end the shift &#x1F468;&#x1F3FD;&#x200D;&#x1F4BB; and another button to start/finish the lunch break &#x1F355;</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://jvlobo.com/content/images/2020/05/esp32_calamari-2_optimized-1.png" class="kg-image" alt="How to make clock-in at work easier with the ESP32 board - Part 1" loading="lazy"><figcaption>Final protoype assembly</figcaption></figure><p>The two buttons have one of the pins connected to ground through a resistor, <a href="https://learn.sparkfun.com/tutorials/pull-up-resistors/all?ref=jvlobo.com">here you can read</a> a good explanation of why it is necessary to use these resistors (pull-up or pull-down). The pins on the same side but at the bottom are connected to the GPIO inputs on the board: <code>26</code> for the first button (the one that starts/ends the shift) and <code>27</code> for the second button (the one that starts/ends the break). And the right pins are connected to the 3.3V output.</p><p>Finally, I only needed to take care of the code of when the buttons are pressed, so it can perform the necessary action depending on the button pressed.</p><!--kg-card-begin: markdown--><pre><code class="language-arduino">int pushShiftButton = digitalRead(26);
int pushBreakButton = digitalRead(27);

if(pushShiftButton) {
  if(calamari.shiftIsOn()) {
    Serial.println(&quot;Stop shift&quot;);
    calamari.stopShift();
  } else {
    Serial.println(&quot;Start shift&quot;);
    calamari.startShift();
  }

  delay(1000);
}

if(pushBreakButton) {
  if(calamari.breakIsOn()) {
    Serial.println(&quot;Stop lunch break&quot;);
    calamari.stopLunchBreak();
  } else {
    Serial.println(&quot;Start lunch break&quot;);
    calamari.startLunchBreak();
  }

  delay(1000);
}
</code></pre>
<!--kg-card-end: markdown--><p>When one of the buttons is pressed, for example the lunch break button, it is checked whether the break is currently taking place. If it is, then the method to stop it is called, and if not, the method to start it is called. Then there is a delay of 1 second in the code. This is done because otherwise, the code could be executed multiple times, even if we only pressed the button once since this piece of code is inside a loop that runs faster than it takes to press and remove your finger from the button.</p><p>And this is it, here you can see how it actually works &#x1F601;:</p><figure class="kg-card kg-embed-card kg-card-hascaption"><iframe width="480" height="270" src="https://www.youtube.com/embed/c2wnoLxiuXk?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe><figcaption>Working prototype</figcaption></figure><p>And this is the complete code on my Github:</p><figure class="kg-card kg-bookmark-card"><a class="kg-bookmark-container" href="https://github.com/jvlobo/esp32-calamari.io-api?ref=jvlobo.com"><div class="kg-bookmark-content"><div class="kg-bookmark-title">jvlobo/esp32-calamari.io-api</div><div class="kg-bookmark-description">Clocking in and out in Calamari.io with the ESP32 development board - jvlobo/esp32-calamari.io-api</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://github.githubassets.com/favicons/favicon.svg" alt="How to make clock-in at work easier with the ESP32 board - Part 1"><span class="kg-bookmark-author">GitHub</span><span class="kg-bookmark-publisher">jvlobo</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://avatars0.githubusercontent.com/u/5671420?s=400&amp;v=4" alt="How to make clock-in at work easier with the ESP32 board - Part 1"></div></a></figure><p>Stay tuned for the second part of this project, where I am going to create in 3D and print a box to make this system more compact and portable. I will also install a battery so I don&apos;t need to be powering it through the ESP32 USB port.</p><p><strong>Update:</strong> Second part is published now! &#x2B07;&#xFE0F;</p><figure class="kg-card kg-bookmark-card"><a class="kg-bookmark-container" href="https://jvlobo.com/esp32-clock-in-with-calamari-io-part-2/"><div class="kg-bookmark-content"><div class="kg-bookmark-title">How to make clock-in at work easier with ESP32 - Part 2</div><div class="kg-bookmark-description">At work we use Calamari.io to track working time. I built a box, with the ESP32 board inside, to make clock-in and clock-out easier and more interesting. This is the second part of the article.</div><div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://jvlobo.com/favicon.png" alt="How to make clock-in at work easier with the ESP32 board - Part 1"><span class="kg-bookmark-author">My Stuff - JV Lobo</span><span class="kg-bookmark-publisher">JV Lobo</span></div></div><div class="kg-bookmark-thumbnail"><img src="https://jvlobo.com/content/images/2020/06/calamari_post_image_optimized-3.png" alt="How to make clock-in at work easier with the ESP32 board - Part 1"></div></a></figure>]]></content:encoded></item><item><title><![CDATA[The difficult task of changing your seat while buying a train ticket online]]></title><description><![CDATA[In this post I talk about my adventures digging into the code trying to change my seat in a website with an unexpected behaviour. ]]></description><link>https://jvlobo.com/the-difficult-task-of-changing-your-seat-while-buying-a-train-ticket-online/</link><guid isPermaLink="false">5ea0ba58f57fff0f2b4e5561</guid><category><![CDATA[Debugging]]></category><category><![CDATA[Frontend]]></category><category><![CDATA[Javascript]]></category><dc:creator><![CDATA[JV Lobo]]></dc:creator><pubDate>Tue, 10 Mar 2020 20:09:00 GMT</pubDate><media:content url="https://jvlobo.com/content/images/2020/04/first_article_header_3_english.png" medium="image"/><content:encoded><![CDATA[<img src="https://jvlobo.com/content/images/2020/04/first_article_header_3_english.png" alt="The difficult task of changing your seat while buying a train ticket online"><p>I&apos;m living in Portugal now. The country has a good railway system and one of the transportation ways I like the most when I travel is the train, which makes it a great choice for me to move around.</p><p>I wanted to travel to the south of the country so I decided to book a ticket with the state-owned train company: <a href="https://cp.pt/?ref=jvlobo.com">Comboios de Portugal</a> and here is where my adventure begins.</p><p>The searching and selection process is quite easy and friendly but when I had to pick my seat is when things got interesting: it doesn&apos;t work!</p><figure class="kg-card kg-image-card"><img src="https://dev-to-uploads.s3.amazonaws.com/i/a0m3612ot502ew9eox13.gif" class="kg-image" alt="The difficult task of changing your seat while buying a train ticket online" loading="lazy"></figure><p>I refused to buy my ticket with the seat that you get assigned by default. I always like to choose one in which both of them are free, knowing that someone can buy the ticket for the seat next to me, but if I&apos;m lucky nobody will get the one next to me and I will travel more comfortably.</p><p>As a developer myself, I opened one of the best tools that we have at our disposal when we are building a website: <a href="https://developers.google.com/web/tools/chrome-devtools?ref=jvlobo.com">Chrome Developer Tools</a> in the hope of being able to dig a bit into the code and see what the problem was. Luckily for me, the web&apos;s Javascript code doesn&apos;t have any kind of <a href="https://dev.to/zicsus/writing-simple-obfuscation-and-minification-system-3395?ref=jvlobo.com">minification or obfuscation</a>.</p><p>The first thing I did was to look at the &#xA0;click event listeners for the seats:</p><figure class="kg-card kg-image-card"><img src="https://dev-to-uploads.s3.amazonaws.com/i/50eavx2g9zwlt6p9lq3j.png" class="kg-image" alt="The difficult task of changing your seat while buying a train ticket online" loading="lazy"></figure><p>I see that there are two events listening to the click of this button (I&apos;m not interested in all the others in jQuery or Bootstrap). This is the code of each one:</p><!--kg-card-begin: markdown--><pre><code class="language-javascript">// href # no jump to top
$(&quot;.slide-seats a&quot;).on(&quot;click&quot;, function(event) {
  event.preventDefault();
});

$(&quot;.slide-seats .item table a&quot;).on(&quot;click&quot;, function(event) {
  pickSeat($(this).find(&quot;img&quot;).attr(&quot;data-id&quot;));
});
</code></pre>
<!--kg-card-end: markdown--><p>Of the two I see, the one that catches my attention is the second one since it calls a function <code>pickSeat()</code></p><!--kg-card-begin: markdown--><pre><code class="language-javascript">function pickSeat(seat) {
  if (changeable) {
    var idx = getSeatIndex(seat);
    isOver = false;
    var stat = getStatus(seat);
    if (!changing &amp;&amp; idx != -1) {
      changing = true;
      toChangeIndex = idx;
      seats[toChangeIndex] = seat;
      img = $(&quot;.slide-seats .active&quot;).find(&quot;[data-id=&apos;&quot; + seat + &quot;&apos;]&quot;)[0];
      if (img != null) {// select
        var name = getImg(seat) + &apos;.4&apos;;
        img.src = prefix + name + suffix;
      }
    } else if (changing &amp;&amp; isSameTrain(seats[toChangeIndex], seat)
      &amp;&amp; (stat == &apos;0&apos; || stat == &apos;2&apos;)
      &amp;&amp; (idx == -1 || idx == toChangeIndex)) {
      changing = false;
      resetSeat(seats[toChangeIndex]);
      img = $(&quot;.slide-seats .active&quot;).find(&quot;[data-id=&apos;&quot; + seat + &quot;&apos;]&quot;)[0];
      if (img != null) {// selected
        var name = getImg(seat) + &apos;.2&apos;;
        img.src = prefix + name + suffix;
      }
      seats[toChangeIndex] = seat;
      toChangeIndex = -1;
    }
  }
}
</code></pre>
<!--kg-card-end: markdown--><p>Setting a breakpoint on the first line of this function, when I click on one of the entries I see that the <code>changeable</code> variable is <code>true</code> and it goes inside the conditional block. The first function called is <code>getSeatIndex()</code> passing the seat as a parameter:</p><!--kg-card-begin: markdown--><pre><code class="language-javascript">function getSeatIndex(id) {
  var id2 = id.split(&apos;:&apos;)[0];
  for (var x = 0; x &lt; seats.length; x++) {
    var id1 = seats[x].split(&apos;:&apos;)[0];
    if (id1 == id2)
      return x;
  }
  return -1;
}
</code></pre>
<!--kg-card-end: markdown--><p>If the seat is not found inside the array <code>seats</code> this function will return <code>-1</code>. As my intention is to enter inside the following condition in the main function <code>pickSeat()</code>, when it is inside the function of <code>getSeatIndex()</code> I manually add the seat that I want to select inside the <code>seats</code> array:</p><figure class="kg-card kg-image-card"><img src="https://dev-to-uploads.s3.amazonaws.com/i/tmqgdmn7g0tc4n2fac7f.gif" class="kg-image" alt="The difficult task of changing your seat while buying a train ticket online" loading="lazy"></figure><p>When the execution of the code reaches the line <code>if(!changing &amp;&amp; idx! = -1) {</code>, since we have modified the function <code>getSeatIndex()</code> the variable <code>idx</code> has a value of <code>1</code> which is different from <code>-1</code> and the variable <code>changing</code> is still <code>false</code> then it executes the code inside the conditional, which was what I was looking for.</p><p>When the execution of the <code>pickSeat()</code> function finishes I can see how the color of the seat changes to a light gray:</p><figure class="kg-card kg-image-card"><img src="https://dev-to-uploads.s3.amazonaws.com/i/t4adh9w7zfx89hog1efo.png" class="kg-image" alt="The difficult task of changing your seat while buying a train ticket online" loading="lazy"></figure><p>After these steps, naive of me I was expecting to continue with the process having my new seat selected, but when I click on next I get this error message:</p><figure class="kg-card kg-image-card"><img src="https://dev-to-uploads.s3.amazonaws.com/i/29kwpsvg5sstsgp2prbn.png" class="kg-image" alt="The difficult task of changing your seat while buying a train ticket online" loading="lazy"></figure><p>&#x1F914; Looks like it was not going to be as easy as I expected.</p><p>This message is displayed once you click on <code>Next route</code> (since it is a round trip ticket, I also have to select the seat for the return trip) so the next thing I do is to inspect the button. Like I did with the buttons on the seats I check the <code>Event Listeners</code> section, but for this button, I find nothing interesting.</p><p>However, when looking at the HTML element I find that a function is being called when the button is clicked:</p><figure class="kg-card kg-image-card"><img src="https://dev-to-uploads.s3.amazonaws.com/i/o9b9qurwznzao4wxsf6e.png" class="kg-image" alt="The difficult task of changing your seat while buying a train ticket online" loading="lazy"></figure><p>With no time to waste, I go back to the Javascript code to see what is happening inside this <code>change()</code> function</p><!--kg-card-begin: markdown--><pre><code class="language-javascript">function change() {
  if (changing) {
    AlertMessage(msg_select);
    return false;
  }
  focusNo = true;
  if (sameSeats())
    ConfirmMessage(msg_not_changed, &apos;doChange()&apos;);
  else
    ConfirmMessage(msg_changed, &apos;doChange()&apos;);
  return false;
}

function doChange() {
  changeTripSeatsValue();	
  enableUnload();
  document.getElementById(&apos;next&apos;).click();
}
</code></pre>
<!--kg-card-end: markdown--><p>The message I was seeing before was because the <code>changing</code> variable has a value of <code>true</code>, so inside the <code>change()</code> function that first conditional is being executed showing the message and returning <code>false</code>.<br>Just before this first <code>if</code> I change the value to <code>false</code>:</p><figure class="kg-card kg-image-card"><img src="https://dev-to-uploads.s3.amazonaws.com/i/0spp6608njfkfop0fkum.gif" class="kg-image" alt="The difficult task of changing your seat while buying a train ticket online" loading="lazy"></figure><p>I finish the code execution with the hope that now I would be able to move on to the next step with my selected seat but ... no!</p><p>Now an error message appears on the console:</p><figure class="kg-card kg-image-card"><img src="https://dev-to-uploads.s3.amazonaws.com/i/k4tn23ktoviltamh4tro.png" class="kg-image" alt="The difficult task of changing your seat while buying a train ticket online" loading="lazy"></figure><p>Something is broken now &#x1F630;.<br>I see that the error comes from the <code>sameSeats()</code> function which is the one called within the <code>change()</code> function in the second <code>if</code></p><!--kg-card-begin: markdown--><pre><code class="language-javascript">function sameSeats() {
  for (var x = 0; x &lt; seats.length; x++) {
    var a1 = seats[x].split(&apos;_&apos;);
    var s1 = a1[0] + &quot;_&quot; + a1[1] + &quot;_&quot; + a1[2];
    var a2 = oldSeats[x].split(&apos;_&apos;);
    var s2 = a2[0] + &quot;_&quot; + a2[1] + &quot;_&quot; + a2[2];
    if (s2 != s1)
      return false;
  }
  return true;
}
</code></pre>
<!--kg-card-end: markdown--><p>Seeing the code of this function and the error, seems clear what is happening. It is trying to use <code>split</code> in one of the elements of the <code>seats</code> array or the <code>oldSeats</code> array, and possibly using an index outside the array. Since the <code>for</code> loop goes from <code>0</code> until the size of the array <code>seats</code>, I&apos;m going to assume that this array is correct, so the error would be in the line</p><p><code>var a2 = oldSeats[x].split(&apos;_&apos;);</code></p><p>To confirm this I debug the code again.<br>If I add these two variables to the <em>Watch</em> section I can see how, indeed, my guess is correct:</p><figure class="kg-card kg-image-card"><img src="https://dev-to-uploads.s3.amazonaws.com/i/2sva8iy5ml883al5kf4i.png" class="kg-image" alt="The difficult task of changing your seat while buying a train ticket online" loading="lazy"></figure><p>With the breakpoint on the line <code>199</code>, as shown in the screenshot, I go to the console and type <code>oldSeats.push(&apos;184_4_64&apos;)</code> so that the <code>sameSeats()</code> function doesn&apos;t fail this time and returns <code>false</code>.</p><p>Finally the <code>doChange()</code> function is executed. This function is responsible for calling another one, which is the one that makes the actual change of the seat:</p><!--kg-card-begin: markdown--><pre><code class="language-javascript">function changeTripSeatsValue() {
  var newValue = &apos;&apos;;
  for (var x = 0; x &lt; seats.length; x++) {
    newValue = newValue + seats[x];
    if(x != seats.length - 1) {
      newValue = newValue + &apos;;&apos;;
    }
  }
  document.getElementById(&apos;tripSeats&apos;).value = newValue;
}
</code></pre>
<!--kg-card-end: markdown--><p>In this function, I put a breakpoint on the last line, which seems to be the important one since it is responsible for assigning the new seat as the value of an item with <code>tripSeats</code> id (I guess it is an <code>input</code>, possibly hidden, within a <code>form</code> element).</p><p>When the debugger stops in this line, I see how <code>newValue</code> has a slightly strange value assigned, so I decide to change it to the value of the seat I am trying to select, and by continuing with the execution of the code ... bingo!</p><p>I have finally been able to select my seat :)</p><figure class="kg-card kg-image-card"><img src="https://dev-to-uploads.s3.amazonaws.com/i/iqcjo64t5kdlv8ad2436.gif" class="kg-image" alt="The difficult task of changing your seat while buying a train ticket online" loading="lazy"></figure><h3 id="conclusions">Conclusions</h3><p>My purpose with this post is to document how I do a JavaScript code debugging process using Google Chrome developer tools. I think it is an interesting and very important process for any front-end developer.</p><p>In this case in particular with the Comboios de Portugal website, using vanilla Javascript (and some jQuery) and with a fairly easy to follow code, it has been a fun task because it is a code that I haven&apos;t written. This makes it more interesting and I took it as a challenge.</p><p>The funniest thing comes now: after having done all this process and having been able to select my seat I have continued testing things on this website and at one point I saw this message:</p><figure class="kg-card kg-image-card"><img src="https://dev-to-uploads.s3.amazonaws.com/i/wgoxytz13uhyfxo8oe3e.png" class="kg-image" alt="The difficult task of changing your seat while buying a train ticket online" loading="lazy"></figure><p>In summary... the selection of seats works so that you have to click first on the seat that you have been assigned automatically and then click on one of the empty seats. And yes, doing so works perfectly &#x1F926;&#x1F3FD;&#x200D;&#x2642;&#xFE0F;</p><p>I may be very clumsy, but since no one likes to accept his clumsiness I began to check other pages where you can book train and plane tickets. It turns out that in all the ones I tried the selection of seats is done in the way that I was instinctively trying: you just need to click on the empty seat.</p><p>In my opinion, this is the friendliest or easiest way to do it and the one that a person will instinctively try. I think it&apos;s a big <a href="https://hackernoon.com/what-is-ui-ux-design-1f01e9dbbf02?ref=jvlobo.com">UX</a> issue on this specific page.</p><p>Anyway, and despite the fact that my entire process to select the seat was not necessary, I had a lot of fun and I ended up being satisfied to have been able to achieve that &quot;challenge&quot;.</p>]]></content:encoded></item><item><title><![CDATA[Forget about watering your plants!]]></title><description><![CDATA[Looking for a project to do in my free time, I decided to build an automatic irrigation system with Arduino. I found this project interesting, useful and without much difficulty.

]]></description><link>https://jvlobo.com/forget-about-watering-your-plants/</link><guid isPermaLink="false">5ebdbb03468bd94c3352c8ed</guid><category><![CDATA[Electronics]]></category><category><![CDATA[Arduino]]></category><dc:creator><![CDATA[JV Lobo]]></dc:creator><pubDate>Fri, 15 Jun 2018 09:00:00 GMT</pubDate><media:content url="https://jvlobo.com/content/images/2020/05/watering_system_main_image.jpg" medium="image"/><content:encoded><![CDATA[<h2 id="automatic-irrigation-system-with-arduino">Automatic irrigation system with Arduino</h2><img src="https://jvlobo.com/content/images/2020/05/watering_system_main_image.jpg" alt="Forget about watering your plants!"><p><em>This post contains affiliate links. For more information, see my disclosures <a href="https://jvlobo.com/disclaimer/">here</a>.</em></p><h2 id="what-is-arduino">What is Arduino?</h2><blockquote>Arduino is an easy-to-use hardware and software based open source electronics platform. <a href="https://www.arduino.cc/en/Main/Products?ref=jvlobo.com" rel="noopener">Arduino boards</a> can receive input data such as light on a sensor, a push of a button or a Twitter message and turn it into an output to activate an engine, turn on a LED light or publish something online. You can tell your Arduino what to do by sending a series of instructions to the board&#x2019;s micro-controller.</blockquote><p>This is a definition taken from the <a href="https://www.arduino.cc/en/Guide/Introduction?ref=jvlobo.com#" rel="noopener">official Arduino website</a> where they explain what it is and what you can do with it.</p><p>I have always been passionate about technology at both the user and creative levels. As a developer, I have always focused on software (websites, mobile applications, etc.), although I have also been very interested in hardware and electronics.</p><p>At first it may sound a bit &#x2018;complicated&#x2019; to be encouraged to do some hardware projects, as it involves purchasing certain physical products and tools. However, if we develop programs, being all digital, it is much simpler and the cost is lower. All you need to do is download some software and start writing code.</p><p>Looking for a project to do in my free time, I decided to build an automatic irrigation system. I found this project interesting, useful and without much difficulty.</p><h2 id="what-are-we-going-to-need-components">What are we going to need? Components</h2><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://jvlobo.com/content/images/2020/05/watering_system_components.jpg" class="kg-image" alt="Forget about watering your plants!" loading="lazy"><figcaption>Components needed</figcaption></figure><p>I have acquired the necessary components for this project from Aliexpress, they come from China and it is the cheapest way to get them. These are normal components that you can find in any electronics, physical or online store.</p><!--kg-card-begin: markdown--><table>
<thead>
<tr>
<th>Name</th>
<th>USD</th>
<th>EUR</th>
<th>Link</th>
</tr>
</thead>
<tbody>
<tr>
<td>Water pump</td>
<td>$1.43</td>
<td>&#x20AC;1.18</td>
<td><a href="https://s.click.aliexpress.com/e/_dVB7MLm?ref=jvlobo.com">Mini submersible water pump</a></td>
</tr>
<tr>
<td>Relay</td>
<td>$0.53</td>
<td>&#x20AC;0.44</td>
<td><a href="https://s.click.aliexpress.com/e/_dYrkAkg?ref=jvlobo.com">5V Relay board</a></td>
</tr>
<tr>
<td>Silicone tube</td>
<td>$1.72</td>
<td>&#x20AC;1.42</td>
<td><a href="https://s.click.aliexpress.com/e/_dTrrPok?ref=jvlobo.com">Food grade transparent hose</a></td>
</tr>
<tr>
<td>Humidity sensor</td>
<td>$0.58</td>
<td>&#x20AC;0.48</td>
<td><a href="https://s.click.aliexpress.com/e/_BfAhSBbE?ref=jvlobo.com">Humidity sensor module for Arduino</a></td>
</tr>
<tr>
<td>Arduino Pro Mini</td>
<td>$3.08</td>
<td>&#x20AC;2.54</td>
<td><a href="https://s.click.aliexpress.com/e/_dZ626gC?ref=jvlobo.com">Arduino Pro Mini ATMega328</a></td>
</tr>
<tr>
<td>Transistors</td>
<td>$0.89</td>
<td>&#x20AC;0.73</td>
<td><a href="https://s.click.aliexpress.com/e/_dXeb6KG?ref=jvlobo.com">IRF540 MOS Transistor N channel</a></td>
</tr>
<tr>
<td>Voltage Regulators</td>
<td>$0.91</td>
<td>&#x20AC;0.75</td>
<td><a href="https://s.click.aliexpress.com/e/_dVaJU7m?ref=jvlobo.com">10PCS Voltage Regulator</a></td>
</tr>
<tr>
<td>Breadboard</td>
<td>$1.08</td>
<td>&#x20AC;0.90</td>
<td><a href="https://s.click.aliexpress.com/e/_Bf9fmhle?ref=jvlobo.com">Mini breadboard</a></td>
</tr>
<tr>
<td>Wires</td>
<td>$0.66</td>
<td>&#x20AC;0.55</td>
<td><a href="https://s.click.aliexpress.com/e/_dX9QwLO?ref=jvlobo.com">40PCS jumper wire</a></td>
</tr>
</tbody>
</table>
<!--kg-card-end: markdown--><p>If we already have the necessary tools such as: soldering iron, tin, pliers and multimeter, the total cost of the components needed to assemble the system does not exceed <strong>11 USD</strong>.</p><h2 id="let-s-schematize-our-design-">Let&#x2019;s schematize our design!</h2><p>Once you have purchased the components, or even earlier, you can start designing the assembly of your circuit. The reason I say you can do it earlier is because there are certain tools to emulate your circuit. I have used the <a href="http://tinkercad.com/?ref=jvlobo.com" rel="noopener">tinkercad.com</a> platform, you can use it online and it is free. Not all the components that exist are there, but it is very useful to simulate parts of the circuit.</p><p>To make diagrams like the one below, I used the <a href="http://fritzing.org/home/?ref=jvlobo.com" rel="noopener">fritzing</a> tool. Unlike tinkercad, you will not have the possibility of simulating circuits but it offers a wide variety of components with which to carry out the assembly scheme.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://jvlobo.com/content/images/2020/05/watering_system_schematics.png" class="kg-image" alt="Forget about watering your plants!" loading="lazy"><figcaption>Schematic diagram</figcaption></figure><p>For the operation of the water pump, we will need to use a relay. You will need to connect it to one of the Arduino&#x2019;s digital outputs to turn it on or off, as it receives its power from the 9V battery, previously <strong>regulated to 6V with the L7806 voltage regulator</strong>.</p><p>The humidity sensor is connected to the Arduino analog input to send the measurement data. To turn the current to the sensor on/off we used an <strong>IRF540</strong> transistor, which we connected to one of Arduino&#x2019;s digital outputs. This is done to protect the moisture sensor, as far as possible, from electrolysis (corrosion) as the current is continuously circulating.</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://jvlobo.com/content/images/2020/05/watering_system_prototype.jpg" class="kg-image" alt="Forget about watering your plants!" loading="lazy"><figcaption>Prototype</figcaption></figure><h2 id="overview-of-the-code">Overview of the Code</h2><p>We will start by defining the input and output pins of the sensors.</p><p>Next we&#x2019;ll call a function to read the moisture in the soil. Here, I came to the conclusion of making five measurements and I got the average value, because when I activated the current flow to the sensor only at the moment of measuring, I realized that the measurements took a little while to stabilize.</p><p>After I have received the humidity level, if it is less than 35, we will call the function that activates the water pump for one second.</p><p>I used the <a href="https://github.com/rocketscream/Low-Power?ref=jvlobo.com" rel="noopener">LowPower</a> library to reduce power consumption a little. My intention is to optimize the system so that the system only works once a day and thus save more energy.</p><!--kg-card-begin: markdown--><pre><code class="language-arduino">#include &lt;LowPower.h&gt;

#define MOISTURE_SENSOR A0
#define TRANSISTOR 6
#define RELAY 5

void setup() {
  Serial.begin(9600);
  pinMode(RELAY, OUTPUT);
  pinMode(TRANSISTOR, OUTPUT);
  digitalWrite(TRANSISTOR, LOW);
  digitalWrite(RELAY, HIGH);
  
}

void loop() {
  LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
  
  int moisture = readMoisture();
  if(moisture &lt; 35)
    water();
}

void water() {
  digitalWrite(RELAY, LOW);
  delay(1000);
  digitalWrite(RELAY, HIGH);
}

int readMoisture() {
  digitalWrite(TRANSISTOR, HIGH);
  delay(10000);
  int moistureLevel1 = checkMoisture();
  delay(2000);
  int moistureLevel2 = checkMoisture();
  delay(2000);
  int moistureLevel3 = checkMoisture();
  delay(2000);
  int moistureLevel4 = checkMoisture();
  delay(2000);
  int moistureLevel5 = checkMoisture();
  int averageMoisture = (moistureLevel1 + moistureLevel2 + moistureLevel3 + moistureLevel4 + moistureLevel5)/5;
  
  Serial.print(&quot;Average moisture: &quot;);
  Serial.print(averageMoisture);
  Serial.println(&quot;%&quot;);

  digitalWrite(TRANSISTOR, LOW);
  delay(5000);
  
  return averageMoisture;
}

int checkMoisture() {
  int sensorValue = analogRead(MOISTURE_SENSOR);
  int valuePercentage = map(sensorValue,1023,0,0,100);

  Serial.print(&quot;Mositure: &quot;);
  Serial.print(valuePercentage);
  Serial.print(&quot;% &quot;);
  Serial.print(&quot;(&quot;);
  Serial.print(sensorValue);
  Serial.println(&quot;)&quot;);

  return valuePercentage;
}
</code></pre>
<!--kg-card-end: markdown--><h2 id="future-plans">Future Plans</h2><p>What this article has shown is just a first approach to the construction of this automatic irrigation system, but I have some improvements in mind that might be interesting to implement in the future.</p><ul><li>I wish everything was smaller and more compact. You could start by welding the components onto a <a href="https://s.click.aliexpress.com/e/_dWmBlPi?ref=jvlobo.com">board</a> and even design a homemade or a more professional one.</li><li>Another component that would be interesting to add to the system is a <a href="https://s.click.aliexpress.com/e/_dSqXFzq?ref=jvlobo.com">water level sensor</a>. The problem with this one is that it&#x2019;s not too big. If our reservoir is a bit deep, it would be impossible to measure the total water level. An <a href="https://s.click.aliexpress.com/e/_d7mE8xe?ref=jvlobo.com">ultrasound sensor</a> can also be used to measure the distance. By installing it at the top of the tank, pointing downwards, we would be able to measure the water level in the tank. Once obtained, we may install a LED that will indicate when the water is below the established level and will indicate that the tank must be refilled.</li><li>One improvement that I think is important is to try to reduce the energy consumption of the system. For this purpose, we can carry out <a href="http://www.home-automation-community.com/arduino-low-power-how-to-run-atmega328p-for-a-year-on-coin-cell-battery/?ref=jvlobo.com" rel="noopener">software and/or hardware modifications.</a></li><li>When it comes to professionalizing the system a bit, it would be a good idea to design a container with a storage space and a compartment to store the electronic system. It can be done with 3D printing.</li><li>Finally, the system can be equipped with a Bluetooth or WiFi connection to connect it to your mobile phone or home network and have a panel where you can control certain parameters and display some statistics at the same time.</li></ul><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://jvlobo.com/content/images/2020/05/watering_system_final_assembly.jpg" class="kg-image" alt="Forget about watering your plants!" loading="lazy"><figcaption>Final built</figcaption></figure><p>I am not an expert in the field so, I encourage you to write in the comments any improvement, modification, advice or doubt.</p><figure class="kg-card kg-embed-card kg-card-hascaption"><iframe width="480" height="270" src="https://www.youtube.com/embed/B3kmxAtOjEE?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe><figcaption>Working system</figcaption></figure>]]></content:encoded></item></channel></rss>