Skip to content

12. Input devices

Hero Shot

Group Assignment:

Probe an input device’s analog levels and digital signals.

Here is a Group Assignment link

The group assignment link is also attached below.

Individual Assignment:

Measure something: Add a sensor to a microcontroller board that you have designed and read it.

As per assignment requirement I need to add a sensor to the microcontroller board that I made I measure it.

I’m using RP2040 microcontroller for this assigment.

Below photo of RP2040 and its pinout.

Soil Moisture Sensor.

In this assignment I’m using soil moisture sensor to read the moisture.

The Soil Moisture Sensor uses capacitance to measure dielectric permittivity of the surrounding medium. In soil, dielectric permittivity is a function of the water content. The sensor creates a voltage proportional to the dielectric permittivity, and therefore the water content of the soil.

The Resistive sensor below uses two probes to pass current through the soil, and then it reads that resistance to get the moisture level. More water makes the soil conduct electricity more easily (less resistance), while dry soil conduct electricity poorly (more resistance).

Below is the pinout of the Soil Moisture sensor.

Electronics design and production

Since I dont have an Input board, I decided to design and produce one to cater for my assignment.

Shematic.

Below is a schematic diagrams of my electronics design. As usual I used Kicad software to design my circuit.

PCB Layout

SO, as usual after the Schematic is done, we Update the PCB editor from the schematic and continue to run traces after which I will generate Gerber files for G-code processing.

Below is a 3D view of the PCB.

Then after I go to flatcam to generate G-code ready for milling processes.

Milling the PCB

The upcoming step is milling the board and as you can below you just have to set the necessary parameters to achieve the best results.

Below you can seen how the board came out.

Soldering

Here it is essential to make a list of all the components that will be used according to your design and collect them all together before soldering activity commences.

Below you can observe the final appearance of our board after soldering.

Programming

Now we can start programming our board. You can download Arduino IDE if you dont have but for me I already installed it from my prvious assignment.

I decided to use a Soil Moisture Sensor as my input device because it is the one I am going to utilize in my final project.

Below is the program code where we want the serial monitor to print the moisture content detected by the sensor.

Just to make it clear.

#include <Arduino.h>

#define MOISTURE_PIN A0  // Pin for moisture sensor

void setup() {
  Serial.begin(9600);  // Initialize serial monitor
}

void loop() {
  int sensorValue = analogRead(MOISTURE_PIN);
  int moisturePercentage = map(sensorValue, 1023, 0, 0, 100);
  Serial.print("Moisture: ");
  Serial.print(moisturePercentage);
  Serial.println("%");
  delay(1000);
}

void loop() {
  // put your main code here, to run repeatedly:
value- analogRead(sensor_pin);
Serial.print ("Moisture : ");
Serial.print (value);
}

Below video shows the output results in the serial monitor in response to the code.

Files

Source_code

KiCad_files

G-code_files

What went well/what went wrong

Generally, everything went well. Since I am getting used to KiCad as well as programming right now, this made my life a little bit easier. And still, every week, there is a skill that I learn and with this I am very grateful.

However, some hikups were there. For instance, bed alighnment was an issue I ended up doing a second board after the first one was dicarded due to the alignment issue.

But After setting the bed accordingly, everything went well.


Last update: July 2, 2024