IO IO IO: Binary numbers? No, input and output!

Hello fellas, it doesn’t feel like a week has passed. Hope you all do well, and stay sane! It has been crazy lately but I think we should normalize it as soon as possible because you know, this pandemic situation alone is crazy as hell, so don’t forget to wear your masks, wash your hands, and keep the distances. And guess what? I got a new assignment this week! Yeah I’m still using ESP32, but this time I got to do something more exciting, and even brighter! Like literally brighter because I’m going to use LED as the source of light (and wisdom).

Lights in traffic light

Input-Output

Maybe you have guessed it, that is the theme of our experiment this week (you don’t say?). Doing an input and output experiment on our ESP32 Microcontroller. In this experiment, I will try to tell you how ESP32 could receives inputs and gives outputs to another device through their GPIO(General Purpose Input/Output). You can see more about ESP32’s GPIO from the following image. Fun fact: the GPIO numbers aren’t so ordered, so keep this in mind.

GPIOs List

Okay without waiting any longer, I’ll just explain what we will do at this opportunity. So we’ll see how the ESP32 takes the input from a push-button. For your information, the input given by the push-button is binary, between 1/0, in this case the push-button will provide the opposite input when it is pressed and released. In addition, we will also see how the ESP32 will output the LED lights according to the input received.[1]

Before we went any further, you might have wondered, what do I need to keep up with this experiment, well no worries, I’ll show you the components needed for this experiment. There are some components from last week too namely:

  1. Arduino IDE
  2. ESP32 and Breadboard
  3. Micro USB Cable.
ESP32 and breadboard(left), Micro USB Cable(middle), Arduino IDE(right)

There are also some new components I used for this experiment. Those components are closely related to the input-output process which will be performed by the microcontroller. These components are vary in colour so you won’t get bored so fast looking at these components, some of them could even shine and light up your night 😜 Some of those are:

4. LED Light(s)

5. 10k and 330 Ohm resistor

6. Jumper cable (dupont wires)

7. Push Button

Resistor(left), Dupont wires(middle), LED and push button(right)

We are using some resistors in this experiment so the LED light won’t be too bright while electrified. Why shouldn’t we make the LED as bright as possible? Well I’ll make it simple for you, LED brightness is inversely proportional to the lifetime of an LED. In order to prolong the LED lifetime, we need to make the light a little bit dim.

I’m planning to make two variant of experiment this time because I’m feeling creative, haha. To be honest I just wanna see more LED being used because the colours are really vibrant. The difference is only at the amount of LED used in the experiment

First Variant

First variant’s diagram

Well as you can see there, I set 3.3 V power to the circuit through the positive part of the breadboard. The power connector (red wire) then will bring the current through the push-button and the GPIO4 will receive the input commanded by the push-button. I put a 10k Ohm resistor and connect it to the ground so the voltage would be divided and the current magnitude wouldn’t be so high.

As the GPIO4 receiving commands from the input (push-button) the GPIO5 will issue commands for the output according to the commands received from the input. The GPIO should be connected to the positive pole (anode) of the LED (the longer stick) and connect the negative pole (cathode) of the LED to the ground through 330 Ohm resistor so the current could be brought to ESP32’s ground (GND).[3]

Code written in Arduino IDE

First we need to initialise the GPIO we would want to use as constant integers as the input from the push-button and here i chose the GPIO4 and i chose GPIO5 for LED’s output commands. The button state is initialised with the number 0 which will give the command off when not pressed.

The setup void is also an initialising procedure. Serial.begin will set the data transfer rate, and the maximum rate supported by Arduino Uno is 115200 bits per second. The next 2 lines will determine which pin would be the input and the output, here the buttonPin would be the input and the ledPin would be the output.

Just like the name, loop void would be iterated. When the buttonPin is pressed, a command would be issued to turn the LED on (giving voltage to the LED), otherwise the LED would be switched off.

Let’s see how is it going,

[5]

It worked! let’s move to the next variant real quick, how if we wanna add more LED into the circuit, is it possible?

Second Variant

Diagram skema varian kedua

The second variant look just slightly different than the first one, because i just added one extra LED to the circuit so the circuit could look more colorful. Just like the first variant, we connect the positive pole (anode) to the GPIO, here i’m using GPIO21. The negative pole should be connected to the ground through the 330 Ohm resistor. This time I’ll show you how both of the lamps interact with each other according to the code written and the input given to them.[3]

Source code: The lamps turned on synergistically(left) and antagonically(right)

The source code is so similar with the first variant, yet there are more GPIO used here so we need to initialise one constant integer representing the extra LED and add more line in the loop void that will give certain commands to the output (LED). In the first source code (left), all the LED would turn on and off together, hence synergistically. However in the second source code (right), one LED would turn off when the other is turning on.[4]

blinking: synergistically(left), antagonically(right)[5]

From this experiment, there are some things i learnt. First, in order to connect your microcontroller to another components through breadboard, you need to make sure that all the pins are well embedded to the breadboard so that all GPIOs can receive inputs and give outputs properly. Another thing i learnt is that we could modify our circuit’s input and output as we like, with modified code according to our needs, for example: I want to add more LED to the circuit, so I plug in more GPIOs with more initializations inside the arduino IDE, another example: I want to make the blink antagonically instead of synergistically, so i got to modify the codes written in Arduino IDE, as simple as that! Also i learnt that the data transfer is really quick, the yellow LED is located slightly further than the blue LED from the ESP32 microcontroller, yet they could blink simultaneously in the synergistic experiment.[6]

Well that’s all for this week fellas, I hope y’all getting a nice week and see u next week with more experiment to do! (I Wayan Ananta Suandira / 18219038)

--

--