<?xml version="1.0" encoding="UTF-8"?>        <rss version="2.0"
             xmlns:atom="http://www.w3.org/2005/Atom"
             xmlns:dc="http://purl.org/dc/elements/1.1/"
             xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
             xmlns:admin="http://webns.net/mvcb/"
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
             xmlns:content="http://purl.org/rss/1.0/modules/content/">
        <channel>
            <title>
									Using ChatGPT code to build a ESP8266 Motion and Temperature Sensor - General Projects				            </title>
            <link>https://www.crackedconsole.com/community/arduino-general/using-chatgpt-code-to-build-a-esp8266-motion-and-temperature-sensor/</link>
            <description>CrackedConsole Discussion Board</description>
            <language>en</language>
            <lastBuildDate>Sat, 07 Nov 2026 23:27:48 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>RE: Using ChatGPT code to build a ESP8266 Motion and Temperature Sensor</title>
                        <link>https://www.crackedconsole.com/community/arduino-general/using-chatgpt-code-to-build-a-esp8266-motion-and-temperature-sensor/#post-638</link>
                        <pubDate>Thu, 25 Apr 2024 09:19:49 +0000</pubDate>
                        <description><![CDATA[It seems to be very useful. Getting chat to write the code is also something I use a lot haha! 🤣]]></description>
                        <content:encoded><![CDATA[<p>It seems to be very useful. Getting chat to write the code is also something I use a lot haha! 🤣 </p>]]></content:encoded>
						                            <category domain="https://www.crackedconsole.com/community/arduino-general/">General Projects</category>                        <dc:creator>HYSTOU</dc:creator>
                        <guid isPermaLink="true">https://www.crackedconsole.com/community/arduino-general/using-chatgpt-code-to-build-a-esp8266-motion-and-temperature-sensor/#post-638</guid>
                    </item>
				                    <item>
                        <title>RE: Using ChatGPT code to build a ESP8266 Motion and Temperature Sensor</title>
                        <link>https://www.crackedconsole.com/community/arduino-general/using-chatgpt-code-to-build-a-esp8266-motion-and-temperature-sensor/#post-637</link>
                        <pubDate>Fri, 05 May 2023 14:51:07 +0000</pubDate>
                        <description><![CDATA[After some back and forth, I was able to get ChatGPT to provide the following
I have tested this code and it seems to work very well.
I am also working on a 3D printed case to hold the sen...]]></description>
                        <content:encoded><![CDATA[<p>After some back and forth, I was able to get ChatGPT to provide the following<br /><br /><br /></p>
<p>I have tested this code and it seems to work very well.</p>
<p>I am also working on a 3D printed case to hold the sensors and battery unit. Next posts will include a wiring diagram and 3D model info</p>
<pre contenteditable="false">#include &lt;ESP8266WiFi.h&gt;
#include &lt;WiFiClient.h&gt;
#include &lt;ESP8266WebServer.h&gt;
#include &lt;DHT.h&gt;

// Replace with your network credentials
const char* ssid = "SSID";
const char* password = "Password";

// Create an ESP8266WebServer object on port 80
ESP8266WebServer server(80);

// Initialize the DHT sensor
#define DHTPIN 2          // DHT data pin is connected to GPIO2
#define DHTTYPE DHT11     // DHT 11
DHT dht(DHTPIN, DHTTYPE);

// Define the PIR motion sensor input pin
#define PIR_PIN 0         // PIR motion sensor input pin is connected to GPIO0

String response = "";

void setup() {
  // Initialize serial communication
  Serial.begin(115200);

  // Connect to Wi-Fi network
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");

  // Start the web server
  server.begin();
  Serial.println("Web server started");

  // Initialize the DHT sensor
  dht.begin();
  server.on("/", handleRoot);
}

void loop() {
  // Check for a new client connection
  server.handleClient();

  // Read the temperature and humidity from the DHT sensor
  float humidity = dht.readHumidity();
  float temperature = dht.readTemperature();

  // Check if any reading failed and exit early
  if (isnan(humidity) || isnan(temperature)) {
    Serial.println("Failed to read from DHT sensor");
    return;
  }

  // Convert temperature to Fahrenheit
  temperature = temperature * 1.8 + 32;

  // Read the motion sensor input
  int motion = digitalRead(PIR_PIN);

  // Construct the response string
  response = "Temperature: " + String(temperature, 2) + " F\n"
                    + "Humidity: " + String(humidity, 2) + " %\n"
                    + "Motion: " + String(motion) + "\n";

  delay(100);
}

void handleRoot() {

  // Send the response to the client
  server.send(200, "text/plain", response);
}</pre>]]></content:encoded>
						                            <category domain="https://www.crackedconsole.com/community/arduino-general/">General Projects</category>                        <dc:creator>CrackedConsole</dc:creator>
                        <guid isPermaLink="true">https://www.crackedconsole.com/community/arduino-general/using-chatgpt-code-to-build-a-esp8266-motion-and-temperature-sensor/#post-637</guid>
                    </item>
				                    <item>
                        <title>Using ChatGPT code to build a ESP8266 Motion and Temperature Sensor</title>
                        <link>https://www.crackedconsole.com/community/arduino-general/using-chatgpt-code-to-build-a-esp8266-motion-and-temperature-sensor/#post-636</link>
                        <pubDate>Sun, 12 Mar 2023 19:04:22 +0000</pubDate>
                        <description><![CDATA[I used to have motion sensors in each room, but the wiring was a hassle as I wired them all down to the basement and used Arduino MEGA controllers to read their data.That will all change tod...]]></description>
                        <content:encoded><![CDATA[<p>I used to have motion sensors in each room, but the wiring was a hassle as I wired them all down to the basement and used Arduino MEGA controllers to read their data.<br />That will all change today.<br /><br />I've been using the ESP8266 for some time now in lighting and RGB projects, now I want to build new motion sensors to put in each room that utilize these.<br />I will also be including a DHT11 Temperature and Humidity sensor in each, very useful in areas such as the bathroom and will allow me to control the exhaust fans based on humidity.</p>
<p>This time, rather than writing the code myself, let's lean a bit on ChatGPT for the code.</p>
<p> </p>
<p><em><span>Can you provide arduino code to use an ESP8266-01 to connect to wifi and then read its 2 available pins for data from the 2 following sensors HC-SR501 PIR motion Sensor DHT11 Humidity Temperature Sensor I want to be able to read these values by via http from the ESP8266-01</span></em></p>
<p> </p>
<blockquote>
<p><span>Sure! Here's some sample Arduino code that should do what you're looking for:</span></p>
</blockquote>
<pre contenteditable="false">#include &lt;ESP8266WiFi.h&gt;
#include &lt;WiFiClient.h&gt;
#include &lt;ESP8266WebServer.h&gt;
#include &lt;DHT.h&gt;

// Replace with your network credentials
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";

// Create an ESP8266WebServer object on port 80
ESP8266WebServer server(80);

// Initialize the DHT sensor
#define DHTPIN 2          // DHT data pin is connected to GPIO2
#define DHTTYPE DHT11     // DHT 11
DHT dht(DHTPIN, DHTTYPE);

// Define the PIR motion sensor input pin
#define PIR_PIN 0         // PIR motion sensor input pin is connected to GPIO0

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Connect to Wi-Fi network
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");

  // Start the web server
  server.begin();
  Serial.println("Web server started");

  // Initialize the DHT sensor
  dht.begin();
}

void loop() {
  // Check for a new client connection
  server.handleClient();

  // Read the temperature and humidity from the DHT sensor
  float humidity = dht.readHumidity();
  float temperature = dht.readTemperature();

  // Check if any reading failed and exit early
  if (isnan(humidity) || isnan(temperature)) {
    Serial.println("Failed to read from DHT sensor");
    return;
  }

  // Read the motion sensor input
  int motion = digitalRead(PIR_PIN);

  // Construct the response string
  String response = "Temperature: " + String(temperature) + " °C\n"
                    + "Humidity: " + String(humidity) + " %\n"
                    + "Motion: " + String(motion) + "\n";

  // Send the response to the client
  server.send(200, "text/plain", response);
}
</pre>
<blockquote>
<p>This code should connect to your Wi-Fi network using the credentials you provide, and then read the temperature and humidity from a DHT11 sensor connected to GPIO2, as well as the motion sensor input connected to GPIO0. It then constructs a string containing the readings, and sends it back to the client when it receives an HTTP request. Note that the PIR motion sensor is initialized as a digital input using <code>digitalRead()</code> and its value is sent back as an integer.</p>
<p>You can access the data by opening a web browser and entering the IP address of the ESP8266-01 into the address bar. The data will be displayed in plain text.</p>
</blockquote>
<p> </p>
<p>Well, time to start working on a circuit, flash the code and see what we come up with!</p>]]></content:encoded>
						                            <category domain="https://www.crackedconsole.com/community/arduino-general/">General Projects</category>                        <dc:creator>CrackedConsole</dc:creator>
                        <guid isPermaLink="true">https://www.crackedconsole.com/community/arduino-general/using-chatgpt-code-to-build-a-esp8266-motion-and-temperature-sensor/#post-636</guid>
                    </item>
							        </channel>
        </rss>
		