15 Must-Have Prompts for IoT and Embedded Systems: Arduino, ESP32, Raspberry Pi

15 Must-Have Prompts for IoT and Embedded Systems: Arduino, ESP32, Raspberry Pi

Introduction

The Internet of Things (IoT) and embedded systems have moved far beyond hobbyist tinkering. Today, they power industrial automation, smart agriculture, wearable health monitors, and connected home ecosystems. But even experienced developers often find themselves stuck when writing firmware for microcontrollers like Arduino and ESP32, or setting up complex edge computing nodes on Raspberry Pi. The key to unlocking efficiency lies in precise, context-aware prompts for code generation, debugging, and configuration.

This article is a practical cheat sheet of 15 ready-to-use prompts designed for engineers, students, and makers working with Arduino, ESP32, and Raspberry Pi. Each prompt is copy-paste ready, includes a clear explanation of its task, and provides a real example of the output you can expect. We'll cover everything from sensor interfacing and MQTT communication to energy-saving sleep modes and cloud integration. No fluff — just actionable commands that save you hours of research.

Why Use AI Prompts for Embedded Development?

Generative AI tools have evolved significantly since 2023. In 2026, they can generate full firmware skeletons, explain register-level operations, and even suggest optimal pin configurations based on your hardware list. However, the quality of the output depends entirely on how well you frame the request. A vague prompt like "write Arduino code for a temperature sensor" yields generic results. A specific prompt that includes the sensor model, communication protocol, and desired output format produces production-ready code.

Embedded development requires attention to memory constraints (RAM, flash), real-time behavior, and power consumption — aspects that generic code often ignores. The prompts below address these specifics, drawing on official datasheets and community best practices from sources like the Arduino Reference, ESP-IDF Programming Guide, and Raspberry Pi Documentation.

Section 1: Arduino — Sensor Reading and Actuation

Prompt 1: Read a DHT22 Temperature and Humidity Sensor

Task: Generate a stable Arduino sketch that reads temperature and humidity from a DHT22 sensor using the Adafruit DHT sensor library, with error handling and serial output.

Prompt:

Generate an Arduino sketch for reading a DHT22 sensor connected to digital pin 7. Use the Adafruit DHT sensor library (version 1.4.4 or later). Include error handling: if the sensor read fails, print "Sensor error" and retry after 2 seconds. Output temperature in Celsius and humidity as a percentage to the Serial Monitor every 5 seconds. Use a `while` loop to wait for serial connection. Explain the code with comments.

Example Output (excerpt):

#include <DHT.h>
#include <DHT_U.h>

#define DHTPIN 7
#define DHTTYPE DHT22

DHT_Unified dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(115200);
  while (!Serial);
  dht.begin();
}

void loop() {
  sensors_event_t event;
  dht.temperature().getEvent(&event);
  if (isnan(event.temperature)) {
    Serial.println("Sensor error");
    delay(2000);
    return;
  }
  Serial.print("Temperature: ");
  Serial.print(event.temperature);
  Serial.println(" °C");
  delay(5000);
}

Prompt 2: Control a Servo Motor with Potentiometer Input

Task: Create a sketch that maps an analog potentiometer reading to a servo angle (0–180 degrees) and moves the servo accordingly.

Prompt:

Write an Arduino sketch that reads an analog input from pin A0 (potentiometer) and maps the value (0–1023) to an angle (0–180). Attach a servo to pin 9. Update the servo position only when the angle changes by more than 2 degrees to reduce jitter. Use the built-in Servo library. Output the current angle to Serial Monitor.

Prompt 3: Debounce a Push Button with Interrupt

Task: Generate code that uses an external interrupt to detect a button press, with software debouncing (20 ms delay).

Prompt:

Create an Arduino sketch that reads a push button on pin 2 (interrupt pin 0). Use a volatile boolean flag to indicate a press. Implement debouncing using a 20 ms delay inside the ISR. When pressed, toggle an LED on pin 13 and print "Button pressed" to Serial. Ensure the ISR is short and re-entrant.

Section 2: ESP32 — Wi-Fi, MQTT, and BLE

Prompt 4: Connect to Wi-Fi with Automatic Reconnection

Task: Write ESP32 Arduino code to connect to a Wi-Fi network, with automatic reconnection if the connection drops.

Prompt:

Generate ESP32 Arduino code that connects to a Wi-Fi network with SSID "MyNetwork" and password "MyPassword". Use WiFiMulti library to handle multiple networks. Implement a reconnection mechanism: if disconnected, attempt reconnection every 10 seconds up to 5 times, then deep sleep for 30 seconds. Print IP address once connected.

Prompt 5: Publish Sensor Data to MQTT Broker

Task: Combine DHT22 sensor reading with MQTT publishing on an ESP32.

Prompt:

Write ESP32 Arduino code using PubSubClient library. Connect to Wi-Fi (SSID "MyNetwork", password "MyPassword") and MQTT broker at broker.hivemq.com port 1883. Read a DHT22 on pin 4 every 10 seconds. Publish JSON payload {"temp":23.5,"hum":60.1} to topic "home/sensor1". Include last will testament with topic "home/sensor1/status" and message "offline".

Real-world note: ASI Biont supports connection to MQTT brokers through its IoT integration layer — more details on asibiont.com/courses.

Prompt 6: Bluetooth Low Energy (BLE) Beacon

Task: Configure ESP32 as a BLE beacon (iBeacon format) that advertises a custom UUID.

Prompt:

Generate ESP32 Arduino code using the ESP32 BLE Arduino library. Set up a BLE server that advertises an iBeacon with UUID 2f234454-cf6d-4a0f-adf2-f4911ba9ffa6, major 1, minor 1, Tx power -59 dBm. Use deep sleep between advertising intervals of 1 second to save power. Print the beacon data to Serial.

Section 3: Raspberry Pi — Edge Computing and Automation

Prompt 7: Read a DS18B20 Temperature Sensor via 1-Wire

Task: Generate Python code for Raspberry Pi to read temperature from a DS18B20 sensor connected to GPIO4 (1-Wire).

Prompt:

Write Python 3 script for Raspberry Pi (kernel 6.x) that reads temperature from a DS18B20 sensor connected to GPIO4. Use the w1-gpio kernel module. Parse the w1_slave file to extract the temperature in Celsius. Print the value every 5 seconds. Handle errors if the sensor is not connected (file not found). Use try-except blocks.

Prompt 8: Set Up an MQTT Subscriber to Control GPIO

Task: Create an MQTT client that listens for commands to turn on/off an LED on GPIO17.

Prompt:

Write a Python script for Raspberry Pi using paho-mqtt library. Connect to broker at test.mosquitto.org port 1883. Subscribe to topic "home/led". When a message "ON" is received, set GPIO17 high; when "OFF", set it low. Use RPi.GPIO library with BCM numbering. Print all received messages to console. Run loop forever with clean exit on Ctrl+C.

Prompt 9: Log Sensor Data to a CSV File with Timestamp

Task: Combine DHT22 reading on Raspberry Pi with CSV logging.

Prompt:

Write a Python script for Raspberry Pi that reads temperature and humidity from a DHT22 connected to GPIO4 using the Adafruit_DHT library. Every 60 seconds, append a new row to "sensor_log.csv" with columns: timestamp (ISO 8601), temperature (float), humidity (float). If the file doesn't exist, create it and write the header. Use the csv module.

Section 4: Power Management and Optimization

Prompt 10: ESP32 Deep Sleep with Timer Wake-Up

Task: Generate code that puts ESP32 into deep sleep for 10 minutes, wakes up, reads a sensor, publishes data via MQTT, then returns to sleep.

Prompt:

Write ESP32 Arduino code that uses esp_sleep_enable_timer_wakeup(600000000) for 10-minute deep sleep. On wake, set RTC memory to count wake cycles. Read a DHT22 on pin 4, publish to MQTT (broker: broker.hivemq.com, topic: "home/sensor2"), then go back to deep sleep. Include RTC data memory to retain the wake count across sleep cycles.

Prompt 11: Arduino Low-Power Mode with External Interrupt Wake

Task: Implement sleep mode on Arduino Uno using the Low-Power library, waking on a button press.

Prompt:

Write Arduino code using the Low-Power library (version 1.8.0). Put the Arduino to sleep in POWER_DOWN mode. Use an external interrupt on pin 2 (rising edge) to wake. After wake, blink an LED on pin 13 three times, then return to sleep. Disable ADC and BOD to save power. Measure approximate current consumption.

Section 5: Communication Protocols (I2C, SPI, UART)

Prompt 12: Scan I2C Bus and Display Device Addresses

Task: Scan the I2C bus on both Arduino and Raspberry Pi.

Prompt:

Generate Arduino code that scans all addresses from 1 to 127 on the Wire library. For each address that acknowledges, print "Device found at address 0x" + hex value. Run the scan once in setup, then print the total number of devices. Also provide equivalent Python code for Raspberry Pi using smbus2 library.

Prompt 13: Read an MPU6050 Accelerometer/Gyroscope via I2C

Task: Read raw accelerometer and gyroscope data from MPU6050 on ESP32.

Prompt:

Write ESP32 Arduino code using the Wire library to read from MPU6050 at address 0x68. Configure the sensor with 2g accelerometer range and 250°/s gyroscope range. Read registers 0x3B to 0x48 to get accelerometer and gyroscope raw values. Convert to g and °/s. Print values to Serial every 100 ms. Include explanation of register addresses.

Section 6: Cloud Integration and Dashboards

Prompt 14: Send Data to ThingSpeak (or Similar IoT Cloud)

Task: Send temperature data to ThingSpeak channel via HTTP GET request.

Prompt:

Write ESP32 Arduino code that reads a DHT22 sensor and sends data to ThingSpeak channel ID 123456 with write API key "ABCDEFGH". Use WiFiClientSecure to make HTTPS GET request to api.thingspeak.com/update?api_key=ABCDEFGH&field1=25.3. Include error checking: if HTTP response code is not 200, retry once after 5 seconds. Use a delay of 15 seconds between updates.

Prompt 15: Set Up a Local Dashboard with Node-RED on Raspberry Pi

Task: Create a Node-RED flow that receives MQTT data and displays it on a dashboard.

Prompt:

Generate a Node-RED flow JSON that subscribes to MQTT topic "home/sensor1" (broker: localhost:1883). Use a JSON parser node to extract temperature and humidity. Display them on a dashboard with a gauge chart for temperature (range 0–50°C) and a text widget for humidity. Add a switch node to turn on/off a GPIO17 LED via MQTT publish to "home/led". Export the flow as a JSON array.

Conclusion

Embedded and IoT development doesn't have to be a slow, trial-and-error process. By using the right prompts, you can generate robust, production-ready code snippets that handle real-world constraints like power efficiency, error recovery, and communication reliability. The 15 prompts in this guide cover the most common tasks across Arduino, ESP32, and Raspberry Pi — from basic sensor reading to cloud integration.

As you build more complex systems, remember to refine your prompts with specific hardware details, library versions, and failure modes. The era of copy-pasting forum code is over; AI-generated code, when properly prompted, can be more consistent and better documented. Keep this cheat sheet handy during your next project, and you'll cut development time significantly.

For deeper dives into IoT connectivity and API integrations, explore the resources at ASI Biont, which provides structured learning paths for embedded systems and automation.

← All posts

Comments