Skip to content

Week 6 Electronics Design

  1. Use an EDA tool to design a development board that uses parts from the inventory to interact and communicate with an embedded microcontroller

  2. Group Project: Use the test equipment in your lab to observe the operation of a microcontroller circuit board (as a minimum, you should demonstrate the use of a logic analyzer)

  3. Group Project: Document your work on the group work page and reflect what you learned on your individual page

Click Here

Board Design

This week I wanted to use an entirely new input. During week 4 (Embedded Programming) I used buttons for everything and now I want to try something new. I decided to use a LDR photoresistor. I decided to use an LED as an output. Basically my board idea is a flashlight that automatically turns on.

I decided to use a voltage divider for the LED. A voltage divider would allow the the microcontroller to be able to detect changes in voltage from the LDR. Then, I can send that voltage into the microcontroller via a ADR pin. Since the LDR is a conductor when there is light and a insulator when there isn't light, I would have a simple code stating if the voltage is lower than a certain value, turn the LED on, and when the voltage is higher, turn the LED off.

How do LDR Photoresistors work?

LDRs are a semi conductor material (Cadmium Sulfide). When Photons collide with the Cadmium sulfide, the energy knocks electrons from the valence band to the conductive band. As more electrons are transerred from the valence band to the conductive band, more current is able to flow through the LDR.

breadboard

I designed this breadboard with a Xiao RP2040 microcontroller. I used a voltage divider with the LDR as one of the resistors. I added a wire going from in the middle of both resistors acting as a tap. That wire goes to the ADC pin on the micrcontroller. The microcontroller reads it as an analog input and not digital because the voltage varies and doesnt act like 1s and 0s.

Code

I consulted copilot for my code. I told it:

"I am a Fab Academy Student. I am trying to design circuit where an LDR communicates with a Xiao RP2040 micrcontroller and then turns an LED on depending on the voltage from a LDR. I am using a voltage divider with the LDR as one of the resistors. I have a wire going from in between both resistors to ADC0 on the microcontroller. The microcontroller should read the voltage coming from the LDR as an analog value. When the voltage drops below a certain value, turn the LED on and when the voltage goes above that value, turn the LED off. The LED is connected to micropython pin P29. Can you generate code that fits these requirements?

Copilot responded with this code:


from machine import Pin, ADC
import time

ldr = ADC(26)          # D0 = GP26 = ADC0
led = Pin(29, Pin.OUT) # D3 = GP29

THRESHOLD = 30000      # adjust after testing

while True:
    value = ldr.read_u16()
    print(value)

    if value < THRESHOLD:   # DARK → LED ON
        led.value(1)
    else:                   # BRIGHT → LED OFF
        led.value(0)

    time.sleep(0.1)

I uploaded this code to the Xiao RP2040 via VSCode and then the code worked first try!

I took the circuit into a small room with a light switch so I could test my circuit. As you can see it works!

EDA Tool: KiCad

Kicad does not include a Xiao RP2040, luckily Kicad has a plugin menu. I downloaded and installed the FabLib Library. This included the Xiao RP2040 and many other electronics used in fab labs.

fablib

Here is the plugin I installed. In Kicad I went to Plugin and Content Manager -> Libraries then searched FabLib.

Schematic

I designed this in the schematic editor. I connected all the connections that needed to be together so later in the pcb editor I could know what to connect. I also added 4 LEDs instead of one because I wanted a brighter light.

footprints

Here are all the footprints I assigned. I chose to use surface mount LEDs and Resistors. Out lab uses size 1206 so I made sure to select those ones. I measured the size of the LDR and chose the correct sized footprint. The RP2040 came with its own footprint.

pcb

I designed this PCB in the PCB editor section of Kicad. After I finished everything in the schematic editor, I switched and updated the PCB editor. I arranged all of the components then drew the traces. I made sure to do all of the traces on F.CU which is the front of the copper. After all the traces were drawn, I switched to Edge.Cuts to draw an outline for the board. For this board, a small rectangle was sufficient.

board

After finishing the pcb, I clicked the 3D viewer to see my pcb. This is the complete pcb. Some of the traces aren't visible, they are under the microcontroller, however they don't touch any of the pins or pads so it is completely safe.

Ability to be fabricated

drc

After completing my board in the pcb editor I ran the DRC. This feature checked if my board is able to be created. After running the DRC, I only got a few errors, none of which are important or affect the ability of my board being able to be created.

**Here is my Kicad File

Reflection

I found the individual portion of this week to be very easy. All I had to do was design a simple board and then use an EDA tool. I had already used Kicad and it is my labs main EDA tool so the board design process felt easy. The group work felt harder this week. Me and my group were tasked with using tools in our lab to analyze electronics. Tools like the Osciliscope and especially the Logic Analyzer were new and took a while to learn. The Logic Analyzer was especially difficult because there were around 30 wires sticking out of it that I had to figure out.