Embedded Programming Cover

9. INPUT DEVICES

[ MISSION: Communicating with the soul of the machine. ]

[ SENSOR_DATALINK: HC-SR04 ]

Ultrasonic Connection

> TRIG: GPIO 26 (D0)
> ECHO: GPIO 27 (D1)
> VCC/GND: 3.3V & GND
Ultrasonic Wiring
ULTRASONIC_FEED // LIVE_DATA
STATUS: [ACTIVE]
SOURCE_CODE // XIAO_RP2350
STATUS: [READ_ONLY]
// Internal LED control with button on D9 for XIAO RP2350 const int buttonPin = D9; // Button pin const int ledPin = LED_BUILTIN; // Built-in orange LED bool ledState = LOW; // Current LED state bool lastButtonState = HIGH; // Previous button state (HIGH due to Pull-up) void setup() { Serial.begin(115200); pinMode(buttonPin, INPUT_PULLUP); pinMode(ledPin, OUTPUT); digitalWrite(ledPin, ledState); Serial.println("--- Button System (D9) Ready ---"); } void loop() { bool currentButtonState = digitalRead(buttonPin); if (currentButtonState == LOW && lastButtonState == HIGH) { delay(50); // Debounce ledState = !ledState; digitalWrite(ledPin, ledState); Serial.print("Button pressed. LED: "); Serial.println(ledState ? "ON" : "OFF"); } lastButtonState = currentButtonState; }

STAGE 02: [ DIY VELOSTAT BUTTON ]

STEP 01

Materials

An insulating material is needed for the exterior.For the exterior, an insulating material is needed. When cutting the material, it is necessary to leave tabs on both sides, as seen in the image.

STEP 02

Conductivity

To conduct electricity in the button, it is necessary to use a copper sheet.

STEP 03

Calibration

The copper sheet needs to be glued to the button tabs.

STEP 04

Calibration

Using conductive thread, it is necessary to sew a pattern starting with the copper strip, so that they touch each other at all times.

STEP 05

Sewing pattern

To sew the pattern correctly, it is necessary to sew diagonal lines like those shown in the image, so that when both sides are pressed together, the conductive thread touches.

STEP 06

Velostat

The most important part of the button is the velostat, which is a material that changes its resistance value when deformed, which means that by reading the resistance values ​​of this material in an analogous way, it is possible to know when it is being pressed.

STEP 07

Velostat placement

The velostat should be placed in the middle of the two button pieces that are made, so that it is between the two sides that are conducting electricity, which will allow us to read its resistance value.

STEP 08

Closing the button

Finally, position the two outer pieces of the button so that the tabs are on opposite sides, as shown in the image, and secure them with either thread or glue. The copper pieces are there so that one side can be connected to GND and the other to an analog read pin.

STEP 1
PRESSURE_SENSOR // ANALOG_IN
VAL: [READING...]
SOURCE_CODE // XIAO_RP2350 // AMBER_EDITION
STATUS: [READY_TO_COPY]
// Internal LED control with button on D9 for XIAO RP2350 const int buttonPin = D9; // Button pin const int ledPin = LED_BUILTIN; // Built-in orange LED bool ledState = LOW; // Current LED state bool lastButtonState = HIGH; // Previous button state (HIGH due to Pull-up) void setup() { Serial.begin(115200); pinMode(buttonPin, INPUT_PULLUP); pinMode(ledPin, OUTPUT); digitalWrite(ledPin, ledState); Serial.println("--- Button System (D9) Ready ---"); } void loop() { bool currentButtonState = digitalRead(buttonPin); if (currentButtonState == LOW && lastButtonState == HIGH) { delay(50); // Debounce ledState = !ledState; digitalWrite(ledPin, ledState); Serial.print("Button pressed. LED: "); Serial.println(ledState ? "ON" : "OFF"); } lastButtonState = currentButtonState; }
🤖

PRINTING FILES

Download the toy that I made.

GET_FILES.ZIP