A complete home automation controller for Arduino Nano RP2040 with serial control from your MacBook.
- Digital Control: Control relays, lights, and other on/off devices
- PWM Control: Dimming lights, motor speed control, etc. (0-255 range)
- Sensor Reading: Read digital and analog sensors
- Serial Interface: Control via Serial Monitor or Python script
- Status Monitoring: Real-time status reporting
- MacBook Integration: Python control script included
Digital Output Pins (Relays/Switches):
- Pin 2, 3, 4, 5 - Configured as relay outputs
PWM Output Pins (Dimmable):
- Pin 6, 9, 10 - PWM-capable outputs (0-255)
Analog Input Pins (Sensors):
- A0, A1, A2 - Analog sensor inputs (0-3.3V)
Arduino Pin 2 → Relay Module IN1
Arduino GND → Relay Module GND
Arduino 3.3V → Relay Module VCC
Arduino Pin 6 → 220Ω Resistor → LED Anode (+)
LED Cathode (-) → Arduino GND
Sensor VCC → Arduino 3.3V
Sensor GND → Arduino GND
Sensor OUT → Arduino A0
-
Install Arduino IDE (if not already installed):
- Download from: https://www.arduino.cc/en/software
- Install for macOS
-
Install RP2040 Board Support:
- Open Arduino IDE
- Go to
Arduino IDE → Settings(orPreferences) - In "Additional Board Manager URLs", add:
https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json - Go to
Tools → Board → Board Manager - Search for "RP2040"
- Install "Raspberry Pi Pico/RP2040" by Earle F. Philhower, III
-
Configure Board Settings:
- Go to
Tools → Board → Raspberry Pi RP2040 Boards - Select "Arduino Nano RP2040 Connect"
- Select your port:
Tools → Port → /dev/cu.usbmodem*
- Go to
- Open
home_automation.inoin Arduino IDE - Click the Upload button (→)
- Wait for compilation and upload to complete
- Open Serial Monitor:
Tools → Serial Monitor - Set baud rate to
115200 - You should see the startup message!
Try these commands in the Serial Monitor:
HELP # Show all commands
STATUS # Show current pin states
ON:2 # Turn on pin 2
OFF:2 # Turn off pin 2
PWM:6:128 # Set pin 6 to 50% (128/255)
ANALOG:A0 # Read analog pin A0
Open Terminal and run:
pip3 install pyserialpython3 arduino_control.pyThe script will automatically find your Arduino and provide an interactive menu.
- Auto-detection: Automatically finds Arduino port
- Interactive Menu: Easy-to-use text interface
- Real-time Control: Instant feedback from Arduino
- Status Monitoring: View all pin states
ON:<pin> # Turn pin ON
OFF:<pin> # Turn pin OFF
TOGGLE:<pin> # Toggle pin state
Examples:
ON:2 # Turn on relay on pin 2
OFF:3 # Turn off relay on pin 3
TOGGLE:4 # Toggle relay on pin 4
PWM:<pin>:<value> # Set PWM value (0-255)
Examples:
PWM:6:255 # Pin 6 full brightness
PWM:9:128 # Pin 9 at 50%
PWM:10:0 # Pin 10 off
READ:<pin> # Read digital pin state
ANALOG:<pin> # Read analog value
Examples:
READ:2 # Read state of pin 2
ANALOG:A0 # Read analog sensor on A0
STATUS # Show all pin states and values
AUTOREPORT:ON # Enable automatic status reports (every 5s)
AUTOREPORT:OFF # Disable automatic reports
RESET # Turn off all outputs
HELP # Show command help
- Connect relay to pin 2 for main lights
- Connect LED strip with PWM to pin 6 for dimmable accent lighting
- Control via Python script or schedule commands
- Connect temperature sensor to A0
- Use
ANALOG:A0to read values - Convert readings to temperature in Python script
- Connect relay to pin 3 for on/off control
- Or use PWM on pin 9 for variable speed
- Use digital inputs to read door sensors
- Control alarm outputs with relays
- Monitor status continuously
Edit the pin arrays in the Arduino sketch:
const int RELAY_PINS[] = {2, 3, 4, 5, 7, 8}; // Add more pins
const int NUM_RELAYS = 6; // Update countIn both files:
- Arduino:
Serial.begin(115200); - Python:
baudrate=115200
Add to the loop() function:
void loop() {
// Your automation logic
if (analogRead(A0) > 500) {
digitalWrite(2, HIGH); // Turn on fan if hot
}
// ... existing code ...
}- Make sure USB cable is connected
- Check
Tools → Portin Arduino IDE - Try unplugging and replugging the Arduino
- On Mac, look for
/dev/cu.usbmodem*ports
- Hold down the BOOTSEL button while connecting USB
- Release after it appears as a drive
- Try uploading again
- Check baud rate is set to 115200
- List ports:
python3 -m serial.tools.list_ports - Manually specify port in script
- Check permissions:
sudo chmod 666 /dev/cu.usbmodem*
- Ensure Serial Monitor is closed (only one program can use serial port)
- Wait 2 seconds after connecting for Arduino to reset
- Try pressing the reset button on Arduino
- Voltage Limits: Arduino pins are 3.3V. Do NOT connect 5V devices directly.
- Current Limits: GPIO pins max 12mA. Use relays or transistors for high-current loads.
- Relay Ratings: Ensure relays are rated for your AC/DC voltage and current.
- Isolation: Use optically isolated relays for AC mains control.
- Fusing: Add fuses to circuits controlling high-power devices.
- Testing: Test all circuits with low power before connecting to mains.
The serial protocol can be integrated with Home Assistant using the Serial integration.
Create a Python script to bridge serial commands to MQTT for IoT integration.
Add a Flask web server to the Python script for browser-based control.
This project is open source. Feel free to modify and share!
For Arduino Nano RP2040 documentation:
For issues or questions:
- Check the troubleshooting section above
- Review Arduino IDE error messages
- Test with simple commands in Serial Monitor first
Created for: MacBook Air with Arduino IDE
Board: Arduino Nano RP2040 Connect
Communication: USB Serial (115200 baud)