Basic LED OFF Time Extender Circuit – B1P4

Let’s take a look at a new type of transistor along with a new component called a capacitor.

Capacitor symbols

This is one type of a capacitor and it has two terminals as shown in the symbol. To understand how it works we will take a look at the following simulation.

Capacitor - simulation

We have a capacitor along with two switches. One switch connects a power source to the capacitor with a current limiting resistor in series. The other switch connects a resistor to the capacitor terminals. We have plotted the current flowing through the capacitor and the capacitor voltage for analysis.

Capacitor charging - simulation

When the first switch is closed, there is a sharp rise in the capacitor voltage and this reaches a steady value with time. The capacitor is said to be charging. The current flowing through the capacitor follows an inverse trend compared to the voltage and it gradually reduces to 0.

Capacitor steady - simulation

If the switch is now opened or disconnected, then you will notice that the capacitor holds its charge and this will continue for a long time.

Capacitor discharging - simulation

By closing the second switch, we place a resistor across the capacitor and this causes the voltage across the capacitor to gradually drop to 0. The capacitor is said to be discharging.

Capacitor overview

In summary, capacitors are energy storage components that tend to hold on to their charge. They can also be used to filter out electrical noise. This type of capacitor is called an electrolytic capacitor and it has a positive and negative terminal. Just like an LED, the longer terminal is positive. Electrolytic capacitors generally have the negative terminal marked on the case which can also be used as a reference. Capacitance is measured in Farads and electrolytic capacitors generally have values in the uF range. They also have a voltage rating and applying a voltage greater than this will damage them.

Let’s quickly recap what we know about transistors. We know that transistors can be used as a switch or to amplify current and we know that we can do this by applying a positive voltage between the base-emitter terminals. This will result in current flowing between the collector-emitter terminals.

NPN transistor

This type of transistor is called an NPN transistor and you can remember this by assigning the P in the middle of NPN to the positive voltage that needs to be applied to the base. Also, the arrow in the symbol points outwards to help you remember that the base is positive with respect to the emitter.

PNP transistor

There is a transistor that is switched ON when the base is negative with respect to the emitter. The symbol for it is shown above and it is called a PNP transistor. Again, you can remember this by assigning the N in the middle of PNP to the negative base-emitter voltage that needs to be applied. Also, the arrow points inwards indicating that the base is negative with respect to the emitter. For a PNP transistor, the base needs to be lower than the emitter by at least 0.6-0.7V for the transistor to switch ON.

Potential difference

One thing to keep in mind is that potential difference or voltage is relative between two points. For a battery, it is the potential difference between the positive and negative terminals. When we talk about the base-emitter voltage, we are talking about the voltage at the base terminal with respect to that at the emitter.

Basic transistor circuit - schematic

Now that we have this information, we can take a look at the circuit diagram. The rightmost section should be familiar, we simply use an NPN transistor to control an LED. The LED will switch ON when the transistor is switched ON and this will only happen when the base is positive compared to the emitter terminal. Q2 is a PNP transistor and we know that the base has to be negative compared to the emitter for it to switch ON. The collector of Q2 is connected to the base of Q1 using a current limiting resistor and this means that the output of Q2 is the input for Q1.

To summarize, the LED will turn ON only when Q1 is ON. Q1 will turn ON, only when Q2 is ON. And Q2 will turn ON when it’s base terminal has a lower voltage compared to its emitter terminal.

If you look at Q2, the emitter is connected to the positive battery terminal which is at 3V. When the switch S1 is closed, resistors R3 and R4 form a voltage divider network with the common terminal being directly connected to the base of Q2. Since the base voltage is lower than the emitter, it will cause Q2 to switch ON, which will switch Q1 ON, and this will ultimately switch ON the LED.

LED OFF time extension simulation - closed

Let’s take a look at the simulation above to understand what’s the use of the capacitor in this circuit. When the switch is open, the capacitor voltage is 0, the transistors are switched OFF along with the LED. When the switch is closed, the capacitor starts to charge to the source voltage.

LED OFF time extension simulation - opened

When the switch is opened, the current which was previously flowing through the voltage divider circuit no longer has a return path to the battery and this current flows through the capacitor instead. The capacitor discharges over time causing its voltage to drop and eventually, the transistors and LED switch OFF.

Pull-up resistor

When the capacitor is fully discharged, it is as good as being non-existent as far as the circuit is concerned. Since the capacitor is no longer relevant and since the switch is disconnected, R3 is no longer relevant as well. R4 is connected between the positive supply voltage and the base and this causes the voltage at the base of Q2 to be the same as that at its emitter – which results in Q2 switching OFF. R4 is said to act as a pull-up resistor since it is pulling up the voltage at the base of Q2.

Basic transistor circuit - breadboard layout

Let’s build the circuit using the breadboard layout.

Basic transistor circuit - demo

Pressing the switch causes the LED to turn ON instantly, whereas releasing the switch causes it to slowly fade away. We can change this time by changing the capacitor value – a higher capacitor value would give us a higher OFF-time extension.

Take a moment to soak up all of this new information as we will be using it to build the future circuits. I’ll see you in the next one!

Basic Transistor Circuit – B1P3

We know that we can turn an LED ON/OFF using a switch and that we can use a potentiometer to control its brightness.

LED control options

Both these involve some manual intervention and in this video, we are going to learn how to do this electronically using a transistor.

NPN transistor symbol

This is the symbol for a transistor and it has three terminals – the base, collector and emitter.

LED control using a transistor

If we connect an LED as shown above, the transistor can then be used to control the LED. The transistor works in different modes depending on the voltage and current flowing between the base and emitter terminals.

Transistor in the OFF state

When no voltage is applied to the base, the transistor is in the OFF state also known as cut-off mode and the LED is switched OFF.

Voltage applied to transistor base

As we apply a voltage between the base-emitter terminals, it causes a small current to flow through the base-emitter, which in turn causes current to flow through the collector-emitter terminals.

Transistor in the linear region

As the base-emitter voltage reaches around 0.6-0.7V, the transistor starts conducting and it causes a sharp rise in the collector-emitter current, which switches ON the LED. In this region, the collector-emitter current is directly proportional to the base-emitter current and the transistor is said to be in the active or linear mode.

Transistor in the saturation region

Increasing the base-emitter current will cause an increase in the collector-emitter current and this will continue until we reach a point where the collector-emitter current becomes independent of the base-emitter current. The transistor is now said to be in the saturation mode.

Transistor datasheet page

As with any electronic component, there is a maximum limit to the voltages and currents that can be applied to the terminals without damaging it. All this information is contained in something called a datasheet which can be obtained by simply typing the part number into a search engine. You can use resistors to limit this current.

Transistor circuit simulation

Let’s take a look at the simulation above to get a better understanding of the above. We have a transistor like before and we’ve connected a 3V battery between the collector-emitter terminals and have added a 330-ohm resistor to limit the current. We have plotted the voltage and current flowing through the resistor for analysis. Similarly, we have added a voltage source between the base-emitter terminals along with a current limiting resistor. The voltage and current have both been plotted for analysis.

Transistor circuit simulation

When the base-emitter voltage is 0, both the currents are 0. As we increase the base-emitter voltage, the base-emitter current increases, which causes an increase in the collector-emitter current as well. When the base-emitter voltage crosses 0.6V, there is a sharp rise in the collector-emitter current which tells us that the transistor has switched ON.

Transistor gain

The base-emitter current is about 30.05uA while the collector-emitter current is 6.01mA which is about 200 times the base-emitter current. This means that the transistor has a gain of 200.

Transistor overview

When used in the linear region, transistors are said to amplify the base-emitter current. If we continue increasing the base-emitter current, we will then enter into the saturation region. The cut-off and saturation region represent the OFF and ON states of a mechanical switch. The ability to use transistors as switches and amplifiers has greatly contributed to the advancement in electronics.

Basic transistor circuit - schematic

Let’s take a look at the circuit diagram for this project. We have an LED connected like before along with a current limiting resistor but we only have a wire connected to the base terminal.

Basic transistor circuit - layout

Let’s use the breadboard layout to build the circuit.

Basic transistor circuit - breadboard

If we hold the jumper wire connected to the base with one hand and use the other hand to hold the jumper wire connected to the positive rail, then you will see that the LED starts to glow. A tiny current flow through our body which switches ON the transistor. The amount of current depends on the body resistance and we can decrease the body resistance by increasing the pressure applied which in turn will increase the brightness.

CAUTION
Please do not repeat this circuit with any other power source. The circuit above is safe because of the high body resistance and because we are using a small, 3V battery source. Using a higher voltage or higher capacity power source can be extremely dangerous.
Also, do not directly connect the two terminals together without using a current limiting resistor as this will cause a high current to flow through the base-emitter terminals which will damage the transistor.

We can now use transistors to build interesting circuits so let’s move on to the next post.

Variable Resistors (Potentiometers) – B1P2

Let’s learn how to use variable resistors. As implied by the name, a variable resistor is a type of resistor whose value can be adjusted. They are commonly referred to as potentiometers, and the type contained in the kit is called a trimmer-potentiometer or trim-pot.

Potentiometer symbols

The commonly used symbols for potentiometers are shown above and it has three terminals.

Potentiometer terminals and value

The potentiometer value is generally printed on the component and it is 103 for this one. The last digit tells you how many zeros need to be added to give you the resistance value in Ohms. 103 is equal to 10,000 Ohms or 10K Ohms. The resistance between the two outermost terminals is fixed and it is 10K ohms. The resistance between the central terminal and the end terminals is variable. The central terminal is also called a slider arm or wiper.

Equivalent potentiometer representation

The potentiometer can be represented by two resistors as shown with both the resistors adding up to a total value of 10K ohms.

Equivalent potentiometer representation

If the slider is moved closer to terminal A, it will reduce the resistance in the top half and increase that in the bottom half. The total will still be 10K ohms.

Equivalent potentiometer representation

Conversely, if we move the slider closer to terminal B, it will increase the resistance in the top half and decrease that in the bottom half. We can use a potentiometer to vary the LED brightness or control the audio volume for instance.

Basic potentiometer circuit - schematic

This is the circuit diagram for the potentiometer circuit. It is very similar to the previous circuit with the main change being that the LED is now connected to the slider arm of the potentiometer.

Basic potentiometer circuit - breadboard layout

Let’s use the breadboard layout to build the circuit. Keep in mind that the middle terminal is the slider terminal which is connected to the LED anode.

Let’s switch ON the battery box and vary the LED brightness by rotating the potentiometer. The LED will be the brightest when the slider is in the topmost position, and the brightness will reduce as we move the slider to the lowermost position. We know from the previous circuit that the current flowing through the LED should be 3mA, by adding a potentiometer, we can either allow all of the 3mA to flow through the LED, or we can reduce it and turn OFF the LED.

This is the basic concept behind potentiometers, and before we move on to the next circuit, let’s discuss something called a voltage divider.

Voltage divider representation

Here we have the equivalent circuit for a potentiometer. If both the resistors have a value of 5K Ohms and if we apply 3V to the end terminals then the voltage at the common terminal will be 1.5V. By changing the slider position, we can change the output voltage from 0V to the entire supply voltage of 3V. What this means is that we can use two resistors to divide an input voltage to some other output voltage – this is called a voltage divider circuit and it is commonly used in electronics.

Voltage divider equation

If this resistor is R1 and this one is R2, then the output voltage is given by the following equation. We can use this to either determine the output voltage or the value of any one resistor.

Basic potentiometer circuit wiring

We will look at transistors in the next post and I will see you there.

A Basic LED & Resistor Circuit – B1P1

Let’s learn how to build a very simple circuit that powers an LED. LED stands for Light Emitting Diode, and what this means is that it is simply a light source. When current flows through an LED, it will cause the LED to glow.

Generally speaking, the higher the current flowing through an LED, the brighter the LED will glow. Current is measured in Amps and the LEDs contained in the kit can handle a maximum current of 20mA. This means that we need a way to limit the current in the circuit and this can be done using a resistor. We will be using a 330 Ohm resistor for now.

Overview of circuit diagrams

In order to understand how the circuit works, we will start drawing the circuit diagram or schematic. A circuit diagram is a visual representation of the circuit using meaningful symbols and it gives you an idea of what the connections look like, which in turn gives you an idea of how the current flows through the circuit.

Circuit symbols

The symbols for a battery, resistor and LED are shown above. One terminal of the LED is longer than the other, and this is intentional. The longer terminal is the positive terminal, also called the anode, while the other one is the negative terminal or cathode.

LED circuit circuit

Connecting the circuit is extremely simple, you simply connect a wire from the battery to the resistor, from the resistor to the LED and then from the LED back to the battery. This provides a path for the current to flow. If the LED is connected in the opposite orientation, it will not glow and can even damage it. The booklet contains the circuit diagrams for all the projects that we will be working on.

Twisting components in place

We can build the circuit by twisting the components together but things quickly get messy if you want to add more components which is why we will be using a breadboard.

A typical breadboard and metal interconnects

The image above shows you what a typical breadboard looks like along with its internal structure. The metal strips provide some of the connections for us which greatly simplifies the circuit building process. We can also use jumper wires to bridge the necessary connections.

Wire termination PCB on breadboard

To connect the battery box, we can use the wire termination PCB that’s been provided in the kit. Simply insert it into the breadboard and use a screwdriver to fasten the wires as needed. Keep the red wire close to the red power strip while the black wire close to the blue power strip.

LED circuit breadboard layout

The booklet contains the breadboard layout which can be used as a reference to build the circuit. We already have the battery box connected, so let’s place the resistor and LED as shown. The longer LED terminal is represented by a slight bend in the breadboard layout. The blue lines indicate jumper wires that need to be placed, whereas the green highlights serve to indicate that something is connected along those metal strips. Let’s start by inserting a wire from the positive rail to the resistor, which is internally connected to the LED anode, and another one from the LED cathode to the negative rail. You can switch ON the battery box, to watch the LED glow.

LED circuit schematic

Let’s take a closer look at the circuit. We know that the battery box gives us 3V and that the resistor has a value of 330 Ohms. To determine the current flowing through the circuit, we need to look at something called Ohms Law.

Ohms law calculation for LED circuit

This is what the equation for Ohms Law looks like and it gives us the relationship between the voltage, resistance and current. By using the numbers we have, we can determine that the current will be 3/330 or approximately 9mA which is well below the LED limit of 20mA. Let’s measure the current to see if this is actually the case.

LED circuit current measurement

Since there is only one loop in this circuit, the same amount of current is going to flow between the three components. We can simply break the circuit, and insert a current measuring device called an Amp meter or ammeter. You can also use a device called a multimeter to take the measurements.

LED circuit current measurement

Let’s start measuring the current by breaking the circuit and inserting the probes in series. The current is about 3mA which is much less than the 9mA we thought was flowing. This is because when current flows through an LED is causes a voltage drop to appear across it and this voltage drop depends on different factors including the colour of the LED.

LED circuit voltage measurement

If we measure the voltage across the LED, you will see that it is about 2V.

Ohm's law calculation with LED voltage drop

This means that the voltage across the resistor is just 1V and Ohms law tells us that the current should be 3mA which is what we measured. The value of the resistor determines the current and we can change this to change the current, which will, in turn, change the LED brightness.

All the resistors in the kit are sorted as per their values, but the simplest way to determine the value is by using a multi-meter. Resistors like the ones in the kit also contain colour bands which are used to indicate their value. The booklet contains a colour code chart which can be used as a reference.

Resistor colour code chart

Resistors commonly have 4 or 5 bands. If it has 4 bands then the first two indicate the digits, the third indicates the multiplier while the last one indicates the tolerance. If it has 5 bands, then the first 3 indicate the digits followed by the multiplier and tolerance. If we look at the first resistor, it starts with an orange band, and by using the 1st digit table, we can see that orange corresponds to the number 3. The second band is also orange which gives us the number 3 again. The 3rd band is brown which gives us the value 10 while the 4th band is gold, which gives us a value of 5%.

Resistance value

The end result is a 330 Ohm resistor with a tolerance of 5%. The 5% tolerance states that the actual value of the resistor could be anywhere between 95% to 105% of the indicated value. For a 330 Ohm resistor, this would be anywhere between 313.5 to 346.5 Ohms.

LED circuit on a breadboard

That’s it for this post. We will look at variable resistors in the next one.

Batteries & Battery Boxes – B1P0

We will be using batteries for all the projects, so let’s start by trying to understand the principle behind batteries and circuits in general.

Battery Water Tank Analogy

Consider two water tanks as shown – tank B is at ground level, while tank A is at some height. Due to this height difference, the water in tank A is said to have higher potential energy compared to that in tank B. If we were to connect the two tanks together, it would result in water from tank A flowing into tank B.

Battery Water Tank Analogy

This is similar to what happens in a circuit. The two tanks form the battery, with the positive terminal being tank A, while the negative being tank B. The pipe is similar to a circuit which results in electric current flowing through it.

The diameter of the pipe determines the rate at which water can flow through it, while the resistance of the circuit, determines the current that can flow through the circuit. We will look at resistors in the next post.

The rate at which water can flow also depends on the amount of water. If we have a lot of water in tank A, it will cause water to flow at a maximum rate because of the high potential difference. Batteries also have something called potential difference and this also controls the amount of electric current flowing through the circuit. The potential difference is called voltage and is generally indicated on the batteries. The AA batteries have a potential difference of 1.5V, whereas the bigger battery has a potential difference of 9V between the terminals.

Batteries in series

One more thing to mention is that batteries can be connected together to increase the potential difference. So if we take 2 AA batteries and connect them as shown above, the potential difference at the ends will be 3V – that’s 1.5v + 1.5V. We can also turn the batteries around and connect the terminals together which is the same as what we did before.

Batteries in series

3V battery box

That is what exactly happens in the battery box. The two batteries are connected internally giving us the two wires. The battery box also contains a switch so instead of the red wire being directly connected to the positive terminal, it is connected through a switch. When we slide the switch to the ON position it connects the red wire to the positive terminal like so.

3V battery box switch

I hope this gives you a rough idea about batteries and battery boxes. We will start building circuits in the next post.

BBox 1 - Introduction

Introduction To BBox 1 – Discrete Components

The BBox series takes a practical approach to learning electronics and BBox 1 uses discrete components like resistors, capacitors, and transistors to build 24 circuits. Each circuit teaches you something new and builds upon the previous ones so you get a thorough understanding of how everything comes together.

BBox 1 contains everything you need to get started, with the exception of batteries. You will need two AA batteries and one 9V battery. The 9V battery is only used for the soil moisture circuit and all the other circuits can work on 3V. The booklet contains information that will help you build the projects.

The Kickstarter edition also contains two additional kits – a solar power project complete with a solar panel and the PCB version of the transistor siren. We will go over some basic concepts in the next post before we start with the projects.

Using The Second SPI Port – SPI1

SPI1 Demo
In this post, we’re going to quickly tell you how to use the second hardware SPI port that’s present on the Pico/Nano boards. The board support package (BSP) already contains the required libraries so all that’s needed to do is call the appropriate functions in your sketch.

Wiring:

The default hardware SPI port uses the D10 (SS), D11 (MOSI), D12 (MISO) & D13 (SCK) pins for communication. This is very common across almost all the Arduino boards. The second hardware I2C port uses the A6 (SS), A7 (MOSI), A0 (MISO) & A1 (SCK) pins for communication.

For this example, we are going to interface a 3rd party 8×8 LED matrix board (MAX7219) that uses SPI for communication. The Pico and Nano are both 5V boards so please make sure the module you use is 5V compatible or else you will need to use a level shifter to convert the 5V signals to 3.3V and vice-versa.

Here’s what the connections look like:

  • Connect the CLK pin to A1
  • Connect the SS pin to A6
  • Connect the MOSI pin to A7
  • Connect the 5V and GND pins to the microcontroller or appropriate power source

SPI1 Wiring SPI1 Wiring

The Sketch:

Using the new SPI port is very simple. You simply need to use SPI1 instead of SPI. Here’s what the sketch looks like:

void setup()
{
  pinMode(slaveSelectPin, OUTPUT);

  SPI1.begin();
  initMAX7219();
}

void loop()
{
  for(int i=1; i<9; i++)          //Display B
      writeTwoBytes(i,bytesB[i-1]);
  delay(500);                    
  
  for(int i=1; i<9; i++)          //Display N
      writeTwoBytes(i,bytesN[i-1]);
  delay(500);                    

  for(int i=1; i<9; i++)          //Display B
      writeTwoBytes(i,bytesB[i-1]);
  delay(500);                    
  
  for(int i=1; i<9; i++)          //Display E
      writeTwoBytes(i,bytesE[i-1]);
  delay(500);     

  for(int i=1; i<9; i++)          //Clear display
      writeTwoBytes(i,0x00);
  delay(500);
}

We start by setting up the SPI port we then call the initialization function for the module which initializes the MAX7219 chip. We then repeatedly display the characters BNBE on the module.

Here’s what the function that sends two bytes to the MAX7219 looks like:

void writeTwoBytes(unsigned char byte1, unsigned char byte2)
{
  digitalWrite(slaveSelectPin, LOW);
  SPI1.transfer(byte1);
  SPI1.transfer(byte2);
  digitalWrite(slaveSelectPin, HIGH);
}

We have omitted the initialization function from this post as that’s dependent on the module that’s being interfaced. You can download the entire sketch using the link below if you need to use it.

Here’s what the output looks like:

SPI1 - Demo SPI1 Demo

Download the SPI1 demo sketch here.

Using The Second I2C Port – Wire1

Wire1 Demo
In this post, we’re going to quickly tell you how to use the second hardware I2C port that’s present on the Pico/Nano boards. The board support package (BSP) already contains the required libraries so all that’s needed to do is call the appropriate functions in your sketch.

Wiring:

The default hardware I2C port uses the A4 (SDA) & A5 (SCL) pins for communication. This is very common across almost all the Arduino boards. The second hardware I2C port uses the PE0 (SDA) & PE1 (SCL) pins for communication. These are also marked as SD1 and SC1 on the pinout cards. These are present as test pads on the reverse of the Pico.

For this example, we are going to interface the Accelerometer Blob using the I2C bus for communication. The Pico and Nano are both 5V boards so please make sure the module you use is 5V compatible or else you will need to use a level shifter to convert the 5V signals to 3.3V and vice-versa. The accelerometer blob already contains the necessary level shifting so we can interface it directly to the Pico/Nano.

For this demo, we will be using the following connections:

  • Connect the SDA pin to PE0
  • Connect the SCL pin to PE1
  • Connect the 5V and GND pins to the microcontroller or appropriate power source

I2C1/Wire1 Wiring I2C1/Wire1 Wiring

The Sketch:

Using the new I2C/wire port is very simple. You simply need to use Wire1 instead of Wire. Here’s what the sketch looks like:

#include "Wire1.h"

#define LIS3DH_WHO_AM_I   0x0F
#define LIS3DH_ADDRESS    0x19

void setup() {

  byte deviceID;
  
  Serial.begin(57600);
  delay(100);             //short delay to allow for proper boot-up. 
  
  Serial.println("Boot Success: Hello World! \n");
 
  Wire1.begin();
  Wire1.beginTransmission(LIS3DH_ADDRESS);
  Wire1.write(LIS3DH_WHO_AM_I);
  Wire1.requestFrom(LIS3DH_ADDRESS, 1);
  deviceID = Wire1.read();
  Wire1.endTransmission();

  Serial.print("Device ID is: ");
  Serial.println(deviceID, HEX);
}

We start by setting up the serial port as we want to send serial messages to it. We then setup the Wire1 bus and begin communicating with the module. This follows the standard I2C communication protocol and doesn’t make use of any 3rd party libraries.

We request the accelerometer blob to send us it’s ID which is a unique byte for the LIS3DH chip. We then print this to the serial port to make sure everything is OK.

After uploading the code, you need to open up the serial monitor from the Arduino IDE (Tools -> Serial Monitor). Make sure the correct baud rate is selected. Press the rest button on the board and you should be able to see an output similar to the one shown below:

Serial Output Serial Output

Download the I2C1 demo sketch here.

That’s all you need to do to use the new I2C port. If you are using existing 3rd party libraries, then you will have to manually update the libraries to use Wire1 instead of Wire. Unfortunately, not all the libraries currently support using an alternate serial port.

Using The Second UART Port – Serial1

Serial1 Demo
In this post, we’re going to quickly tell you how to use the second hardware serial port that’s present on the Pico/Nano boards. The board support package (BSP) already contains the required libraries so all you need to do is call the appropriate functions in your sketch.

Wiring:

The default hardware serial port uses the D0 (Tx) & D1 (Rx) pins for communication. This is very common across almost all the Arduino boards. These two pins are connected to the USB-serial converter on the Pico/Nano and are used to upload sketches from the Arduino IDE.

The second hardware serial port uses the D11 (Tx) & D12 (Rx) pins for communication. These are also marked as TX1 and RX1 on the pinout cards. If you are using the Pico then you can locate these on the finer 1.27mm pitch header pins.

Since the Pico and Nano are both 5V boards, you will need a 5V USB-serial converter to test this demo. Please connect the following pins to the board:

  • Connect D11 to the Rx pin of a USB-serial converter
  • Connect D12 to the Tx pin of a USB-serial converter
  • Power up the Pico or Nano using USB or an external 5V power supply

Serial1/UART1 Wiring Serial1/UART1 Wiring

The Sketch:

Using the new serial port is very simple. You simply need to use Serial1 instead of Serial. Here’s what the setup function looks like:

  Serial1.begin(57600);     //opens serial port, sets data rate to 57600 bps
  Serial1.println("Boot Success: Hello World!");
  Serial1.println("Communicating through serial1.");
}

As can be seen, we simply setup the serial port for 57600 baud and then send two messages to make sure everything is OK.

We now need to make sure that we can successfully receive data using the serial port. To do this, we can use a simple sketch like the one below:

  if (Serial1.available() > 0) 
  {
    incomingByte = Serial1.read();        //read the incoming byte
    Serial1.print("Received: ");          
    Serial1.println(incomingByte, DEC);   //send the byte to the terminal in decimal format
  }

We wait for serial data to be available at the port and then read this into a variable called “incomingByte”. We then print this byte back to the terminal using the decimal format as that will print out the ASCII values of the bytes.

After uploading the code, you need to select the COM port corresponding to your USB to serial converter and then open up the Serial Monitor (Tools -> Serial Monitor). Make sure the correct baud rate is selected. Simply type in some test characters like ABC123 and press enter. You will then be able to view the ASCII values for the bytes like so:

Serial Output Serial Output

The last byte with value 10 is the ASCII value for the line feed (Enter)

Download the UART1 demo sketch here.

That’s all you need to do to use the new serial port. If you are using existing 3rd party libraries, then you will have to manually update the libraries to use Serial1 instead of Serial. Unfortunately, not all the libraries currently support using an alternate serial port.