Story
This project is all about using the RP2350 to communicate changes either with a switch to act as a switch in Home Assistant, or changes with temperature/humidity using a DHT22 sensor.
First things first, download Arduino IDE, add the RP2040/RP2350 board definitions and take out your components.
First, solder wires to a 3.3V pin, a GND pin, and two other GPIO pins of your choice (I'll be using #18 for the button, and #19 for the DHT22 sensor).
We're going to connect the mechanical keyboard switch to GND and #18. Next, connect the DHT22 to 3.3V (on the +), GND (on the -), and #19 for the "Out".
(Note: The DHT22 sensor I'm using has a breakout board with a builtin resistor)
After that, hold the boot key and plug in the board to our computer.
Open the Arduino IDE and use the following code:
#include <DHT22.h>
#define Serial2_RX 5
#define Serial2_TX 4
#define pinDATA 19
DHT22 dht22(pinDATA);
const int buttonPin = 18; // the number of the pushbutton pin
const int ledPin = 25; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
Serial.println(dht22.debug());
float temp = dht22.getTemperature();
float h = dht22.getHumidity();
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == LOW) {
// turn LED on:
digitalWrite(ledPin, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
After that, click the upload button. Once it's fully compiled and uploaded the code to the board, pressing the switch should turn on the LED on the board.
Future updates to this guide will include sending the button presses and temperature/humidity data to Home Assistant via MQTT, as well as CAD files for a 3D printed case.