Input Devices

This week, I explored the integration of input devices with PCBs, focusing on how sensors and switches interact with microcontrollers to receive and process data. Input devices such as buttons, sensors, and encoders play a crucial role in capturing external signals and converting them into meaningful information for embedded systems.

I worked on understanding the electrical characteristics, communication protocols, and interfacing techniques required to connect these devices to a microcontroller. Additionally, I examined signal conditioning methods, power considerations, and programming approaches to ensure accurate data acquisition. Through hands-on implementation and testing, I gained practical insights into designing efficient input circuits and troubleshooting common issues.

This week, I am working with two Electronic Production as part of assignments:

Group Assignment

Individual Assignment

Group Assignment

As part of the group assignment, Dr. Sujit and I conducted a study that included the following tasks:

1. Integration of Input Devices – Connect and interface various input devices with a PCB.

2. Circuit Design – Design and implement a reliable circuit for input device integration.

3. Sensor Interfacing – Understand and apply techniques for interfacing sensors with a microcontroller.

4. Microcontroller Programming – Develop and test firmware to process input data effectively.

5. Reliable Connections – Ensure stable and efficient connections between components.

6. Data Analysis – Capture, interpret, and utilize data from input devices.

The group assignment is linked here

Individual Assignment

In my individual assignment, I focused on designing and fabricating a PCB to interface with various input devices. The objective was to develop a functional circuit that could effectively capture and process data from sensors and switches using a microcontroller.

I began by designing the PCB using an EDA tool, ensuring proper routing and component placement. After finalizing the design, I proceeded with milling the PCB and assembling the necessary components. Once the hardware was ready, I programmed the ESP32-C3 microcontroller to read data from the connected input devices

Design of PCB with KICAD software

As I explained in Week Six, I learned to use this software for PCB design. It is open-source and easily available online. Using this software, I designed a PCB.

The schematic diagram explains that I used the Xiao RP2040 board for the PCB design.

Image

Then, I opened the PCB editor and used the "Route Track" command to make the necessary connections, ensuring that the PCB functions properly.

Image

Then, I used the Edge Cuts layer, selected the Draw Line tool, and created the PCB outline.

Image

In the next step, the file needs to be saved for PCB fabrication. The files are saved in two ways: one for traces and another for the outline cut.

To save the file for traces:

1. Go to the File menu and select Plot.

2. In the Plot window, choose SVG as the output format.

3. Select F.Cu (the front copper layer).

4. The output message will display the save location of the file.

5. Finally, click Save to store the file.

Image

The same procedure is repeated for the edge cut, except instead of selecting F.Cu, choose Edge Cuts.

1. Go to the File menu and select Plot.

2. In the Plot window, choose SVG as the output format.

3. Select Edge Cuts instead of F.Cu.

4. Click Plot to generate the path for saving.

5. Finally, click Save to store the file.

Image

All the aspects related to the schematic and PCB editors are not explained in detail here.

Generate Toolpath for PCB Milling

To generate the toolpath for CNC milling and create the PCB, I used the Mods Project online platform.

1. Open the Mods Project website.

2. Once the website loads, the main window appears.

3. Then right click and from the available options, select program.

Image

As the program opens, I scroll down and, under the G-code section, select Mill 2D PCB.

Image

Then, go to Read SVG and select the SVG file. Then go to desired location and select .svg file format those are saved in KICAD software.

Image

After selecting the file, press open to preview it.

Image

Then, the preview appears in the Select SVG menu. Then, navigate to the "Convert SVG Image" section and select the "Invert" option.

Image

Then, go to Set PCB Default and select Isolate Traces.

Image

No changes are made in the Isolate Traces settings.

Image

It looks like you're configuring the V-bit parameters for your CNC machining.

Open the V-bit Calculator in your software.

Set the parameters:

1. Tip Diameter: 0.1 mm

2. Angle: 30°

3. Cut Depth: 0.1 mm

4. Click on "Send Calculated Setting"

Image

Then goes into mill raster 2d option. Change the Tool Diameter to 0.1 mm. Then, press the "Calculate" option. Once the calculation is complete, the file will be downloaded to the "Downloads" section.

Image

Then click on the view option.

Image

Click on the Calculate Button to generate the toolpath.The software will then generate the PCB milling file in .nc format.file is save in Downloads.Go to the "Downloads" folder and open the file. This file shows the toolpath.

Image

After that click on the calculate option it will generate the pcb milling file in . nc format.

Navigate to the Downloads folder and locate the generated .nc file. Rename the file by changing its extension from .nc to .gcd.

Image

Once the file is saved in the .gcd format, open it using Notepad or a similar text editor. Locate the code G54 and replace it with G55 to adjust the work coordinate system for the PCB milling process. After making the modification, save the file and exit the editor.

Image

Next, access the Mods CE online software to generate the outline toolpath for the PCB milling process.

Image

Then, go to Read SVG again, and in this menu, select the SVG file.

Image

Then, go to Read SVG and select the SVG file. Then go to desired location and select .svg file format those are saved in KICAD software. Then select the edge_cut file and select open.

Image

Then, go to Set PCB Default and select millout line (1/32).

Image

Without making any changes, go to Mill Raster 2D, change the tool diameter to 0.8mm, and save the changes.

Image

After that click on the calculate option it will generate the pcb milling file in . nc format.

Navigate to the Downloads folder and locate the generated .nc file. Rename the file by changing its extension from .nc to .gcd.

Image

Once the file is saved in the .gcd format, open it using Notepad or a similar text editor. Locate the code G54 and replace it with G55 to adjust the work coordinate system for the PCB milling process. After making the modification, save the file and exit the editor.

Image

CNC Milling Process

Once the trace and outline files are generated, the PCB design is ready for manufacturing.

Then, proceed to the PCB milling machine, where the machine software is launched. Initially, the startup window is displayed.

Image

Next, it is important to set the origin point. To do this, first, click on the "Jog Enable" menu, then select "Incremental." Set the desired increment value, and use the -X, +X, -Y, +Y, Z-up, and Z-down controls to position the spindle accurately.

Image

When go into the Set WCS menu and set X0, Y0, Z0, you are likely defining a new origin point for design.

Image

Then, click the Save button to set the origin for the PCB milling process. The screen will display the coordinates X0, Y0, Z0, confirming that the new reference point has been established.

Image

Next, navigate to the Increments setting, configure it as needed, and click Z-Up to move the tool upward.

Image

Then, navigate to the Load menu and select the program from the desired location.

Load the traces program to initiate the cutting process for the PCB traces.

Then, click Cycle Start to begin the milling process.

Image

As the milling process begins, the tool rotates at a speed of 10,000 RPM, as specified in the program, and starts cutting the PCB traces.

Once the traces are cut, the program is completed. Next, change the tool from a V-bit to a 0.8mm drilling tool. Then, following the same procedure, load the edge cut program while maintaining the previously set origin and click Cycle Start to begin the process.

Once the edge cut program cycle is completed, the PCB is ready for the soldering process.

Image

PCB soldering

With the PCB milling process completed, the board is now ready for soldering. In the next step, the soldering process will be carried out.

In the soldering process, I connected the push button, resistor, LED, connector, and XIAO RP2040 board to the PCB.

Image

Hero Shot

Image

After successfully manufacturing the custom PCB for the Seeed Studio XIAO RP2040, the next step in my project is to design and fabricate a case for the board using 3D printing.Case will also enhance the overall aesthetics and usability of the device. The case will be designed in CAD software, ensuring precise dimensions and proper cutouts for the USB port, pin headers, and any onboard components. Once the design is finalized, it will be 3D printed using a suitable material like PLA to provide a durable and functional housing for the custom PCB

Image

Input Devices PCB Working

As the PCB is ready, the next step is writing a program for PIR (Passive Infrared) sensor.

By detecting infrared (IR) radiation released by objects, especially living things, inside its field of vision, an electronic sensor known as a PIR (Passive Infrared) sensor can identify motion. PIR sensors passively monitor changes in infrared radiation rather than sending out signals like active sensors do. Initially, LEDs will blink simultaneously.

The image shows a PIR (Passive Infrared) Motion Sensor Module, widely used in automation and security applications to detect human movement. The most common model of this type is the HC-SR501, which senses infrared radiation emitted by objects, particularly human bodies, within its field of view. The dome-shaped white component is a Fresnel lens, which focuses infrared signals onto the underlying pyroelectric sensor to detect motion.

This module operates typically at 5V DC and provides a digital output that goes high (3.3V or 5V depending on model) when motion is detected. It has three pins: VCC, GND, and OUT. The VCC is connected to a 5V supply, GND to ground, and OUT provides the motion signal to microcontrollers or other circuits. Two orange-colored potentiometers are available on the board—one to adjust the sensitivity (detection distance) and the other to set the delay time for how long the output remains high after motion is detected.

This PIR sensor typically covers a range of 3 to 7 meters and a detection angle of approximately 120 degrees. It is energy-efficient and only responds to moving infrared sources, making it ideal for applications like automatic lighting systems, burglar alarms, smart home projects, and occupancy detection. Its compact size and ease of interfacing make it popular in both DIY and industrial electronics.

Image

#define PIR_PIN D6 // PIR sensor connected to D6 (GPIO6)

#define LED_PIN D0 // Onboard RGB LED of XIAO RP2040

void setup() {

pinMode(PIR_PIN, INPUT);

pinMode(LED_PIN, OUTPUT);

Serial.begin(115200);

}

void loop() {

if (digitalRead(PIR_PIN) == HIGH) {

Serial.println("Motion Detected!");

digitalWrite(LED_PIN, HIGH); // Turn on RGB LED

delay(500); // LED on for 500ms

digitalWrite(LED_PIN, LOW); // Turn off RGB LED

} else {

Serial.println("No Motion");

digitalWrite(LED_PIN, LOW); // Ensure LED stays off when no motion

}

delay(100); // Small delay for stability

}

Then uploading it to the XIAO RP2040.

Image

A program is developed to work with a touch sensor in the second stage. When the sensor is activated by touch, it sends a signal to make an LED blink, serving as a visual indicator that the sensor has been touched. This setup essentially demonstrates the interaction between the touch sensor and the LED.

The TTP223B Capacitive Touch Sensor Module is a compact and efficient device designed to detect touch inputs. It works by sensing changes in capacitance when a finger or conductive object comes into contact with its touch-sensitive area. This module is often used as a replacement for traditional mechanical buttons, offering a more modern and seamless interface. It operates on low power and can be easily integrated into various projects, making it ideal for applications like touch-activated switches or hidden controls on non-metallic surfaces like glass or plastic.

Image

#define TOUCH_PIN D6 // Touch sensor connected to D6

#define LED_PIN D0 // LED connected to D0

void setup() {

pinMode(TOUCH_PIN, INPUT);

pinMode(LED_PIN, OUTPUT);

Serial.begin(9600);

delay(1000); // Allow time for serial to start

}

void loop() {

int touchState = digitalRead(TOUCH_PIN);

if (touchState == HIGH) {

digitalWrite(LED_PIN, HIGH); // Turn on LED

Serial.println("Touched! LED ON");

} else {

digitalWrite(LED_PIN, LOW); // Turn off LED

Serial.println("Not touched. LED OFF");

}

}

Then uploading it to the XIAO RP2040.

Image

The DHT11 sensor is a popular and reliable device for measuring temperature and humidity. It combines a temperature sensor and a humidity sensor into a single unit, providing digital output data. This makes it convenient for use in projects where monitoring environmental conditions is essential. It's widely appreciated for being cost-effective, easy to use, and accurate enough for many applications, such as weather monitoring, home automation, and greenhouse control. The sensor communicates through a digital pin, making it simple to integrate into microcontroller-based systems.

Humidity is the measure of water vapour present in the air. The level of humidity in air affects various physical, chemical and biological processes. In industrial applications, humidity can affect the business cost of the products, health and safety of the employees. So, in semiconductor industries and control system industries measurement of humidity is very important. Humidity measurement determines the amount of moisture present in the gas that can be a mixture of water vapour, nitrogen, argon or pure gas etc… Humidity sensors are of two types based on their measurement units. They are a relative humidity sensor and Absolute humidity sensor. DHT11 is a digital temperature and humidity sensor

DHT11 sensor consists of a capacitive humidity sensing element and a thermistor for sensing temperature. The humidity sensing capacitor has two electrodes with a moisture holding substrate as a dielectric between them. Change in the capacitance value occurs with the change in humidity levels. The IC measure, process this changed resistance values and change them into digital form.

For measuring temperature this sensor uses a Negative Temperature coefficient thermistor, which causes a decrease in its resistance value with increase in temperature. To get larger resistance value even for the smallest change in temperature, this sensor is usually made up of semiconductor ceramics or polymers.

The temperature range of DHT11 is from 0 to 50 degree Celsius with a 2-degree accuracy. Humidity range of this sensor is from 20 to 80% with 5% accuracy. The sampling rate of this sensor is 1Hz .i.e. it gives one reading for every second. DHT11 is small in size with operating voltage from 3 to 5 volts. The maximum current used while measuring is 2.5mA.

Image

#include "DHT.h"

// Define DHT sensor type and data pin

#define DHTPIN D6 // D6 pin on XIAO RP2040

#define DHTTYPE DHT11 // DHT 11

// Initialize DHT sensor

DHT dht(DHTPIN, DHTTYPE);

void setup() {

Serial.begin(9600);

delay(1000); // Allow time for serial to initialize

dht.begin();

Serial.println("DHT11 sensor initializing...");

}

void loop() {

// Read humidity and temperature

float humidity = dht.readHumidity();

float temperature = dht.readTemperature();

// Check if any reads failed

if (isnan(humidity) || isnan(temperature)) {

Serial.println("Failed to read from DHT sensor!");

return;

}

// Print readings

Serial.print("Temperature: ");

Serial.print(temperature);

Serial.print(" °C\tHumidity: ");

Serial.print(humidity);

Serial.println(" %");

delay(2000); // Wait 2 seconds between readings

}

Image

Then uploading it to the XIAO RP2040.

The circuit diagram shows how to connect the DHT11 sensor to the Xiao RP2040 microcontroller. It highlights the specific pins used to link the components, such as the power supply, ground, and the data pin for communication between the sensor and the microcontroller. This setup allows the Xiao RP2040 to read temperature and humidity data from the DHT11, making it easy to build environmental monitoring projects or similar applications.

As part of my assignment, I decided to work with an accelerometer sensor, and for that, I chose the ADXL345. It’s a compact and low-power 3-axis accelerometer that can measure acceleration in all three directions—X, Y, and Z. It helps detect motion, tilt, and orientation, which makes it suitable for many applications like robotics, gesture control, and mobile devices. I found it useful because it communicates easily with microcontrollers using I2C or SPI, and it gives precise data with a resolution of up to 13 bits. This makes it a good option for projects involving movement sensing or tracking.

Image

#include

#include < Adafruit_Sensor.h>

#include < Adafruit_ADXL345_U.h>

// Create ADXL345 sensor instance

Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);

void setup() {

Serial.begin(9600);

while (!Serial); // Wait for serial monitor to open

// Initialize sensor

if (!accel.begin()) {

Serial.println("ADXL345 not detected. Check wiring.");

while (1);

}

Serial.println("ADXL345 Found!");

// Set range: ±2G, ±4G, ±8G, ±16G

accel.setRange(ADXL345_RANGE_2_G);

Serial.print("Range set to: ");

switch (accel.getRange()) {

case ADXL345_RANGE_2_G: Serial.println("±2G"); break;

case ADXL345_RANGE_4_G: Serial.println("±4G"); break;

case ADXL345_RANGE_8_G: Serial.println("±8G"); break;

case ADXL345_RANGE_16_G: Serial.println("±16G"); break;

}

>

void loop() {

sensors_event_t event;

accel.getEvent(&event);

Serial.print("X: "); Serial.print(event.acceleration.x); Serial.print(" m/s^2\t");

Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print(" m/s^2\t");

Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.println(" m/s^2");

delay(500);

void loop() {

sensors_event_t event;

accel.getEvent(&event);

Serial.print("X: "); Serial.print(event.acceleration.x); Serial.print(" m/s^2\t");

Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print(" m/s^2\t");

Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.println(" m/s^2");

delay(500);

}

Then uploading it to the XIAO RP2040.

Image

Downloads

Input Devices




FAB ACADEMY - Dr. Shantanu Kadam Image