Code with wiring diagrams

Each code comes with the wiring drawn out, the list of real parts and the wires one by one. Gather, connect, copy and upload to your board.

  1. 1 Gather the parts
  2. 2 Connect it as in the diagram
  3. 3 Copy the code and upload
const int LED = 13;

void setup() {
  pinMode(LED, OUTPUT);
}

void loop() {
  digitalWrite(LED, HIGH);
  delay(500);
  digitalWrite(LED, LOW);
  delay(500);
}
const int TRIG = 9;
const int ECHO = 10;

void setup() {
  Serial.begin(9600);
  pinMode(TRIG, OUTPUT);
  pinMode(ECHO, INPUT);
}

void loop() {
  digitalWrite(TRIG, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG, LOW);

  long us = pulseIn(ECHO, HIGH, 30000);
  float cm = us * 0.0343 / 2;

  Serial.println(cm);
  delay(200);
}
#include <DHT.h>

DHT dht(2, DHT11);

void setup() {
  Serial.begin(9600);
  dht.begin();
}

void loop() {
  float temp = dht.readTemperature();
  float hum  = dht.readHumidity();

  if (isnan(temp) || isnan(hum)) {
    Serial.println("Read error");
  } else {
    Serial.print("Temp: ");
    Serial.print(temp);
    Serial.print(" C  Hum: ");
    Serial.print(hum);
    Serial.println(" %");
  }
  delay(2000);
}
const int LDR = A0;
const int RELE = 7;
const int UMBRAL = 400;  // adjust for your sensor

void setup() {
  pinMode(RELE, OUTPUT);
  digitalWrite(RELE, HIGH);  // off (module is active-LOW)
}

void loop() {
  int luz = analogRead(LDR);

  if (luz < UMBRAL) {
    digitalWrite(RELE, LOW);   // dark: turn on
  } else {
    digitalWrite(RELE, HIGH);  // bright: turn off
  }
  delay(500);
}
#include <WiFi.h>
#include <WebServer.h>

const char* SSID = "YOUR_WIFI";
const char* CLAVE = "YOUR_PASSWORD";
const int LED = 2;

WebServer server(80);

void pagina() {
  server.send(200, "text/html",
    "<a href='/on'>Turn on</a> | <a href='/off'>Turn off</a>");
}

void setup() {
  Serial.begin(115200);
  pinMode(LED, OUTPUT);
  WiFi.begin(SSID, CLAVE);
  while (WiFi.status() != WL_CONNECTED) delay(300);
  Serial.println(WiFi.localIP());  // type this IP in your phone's browser

  server.on("/", pagina);
  server.on("/on",  []() { digitalWrite(LED, HIGH); pagina(); });
  server.on("/off", []() { digitalWrite(LED, LOW);  pagina(); });
  server.begin();
}

void loop() {
  server.handleClient();
}
import serial

with serial.Serial("COM3", 9600, timeout=1) as arduino:
    while True:
        linea = arduino.readline().decode().strip()
        if linea:
            print("Distance:", linea, "cm")

Something not working?

Write to us with a photo of your build and we'll help you find the problem.