🛠 Envoyer un capteur analogique sur le réseau : potentiomètre et Bridge REST

Arduino Yún · debutant · Schéma : IMG-yun-debutant-3-yun-potentiometre-web-bridge.svg — Yún sur breadboard : potentiomètre 10 kΩ sur A0, câble réseau/ant WiFi, et navigateur affichant la valeur renvoyée par http://arduino.local/arduino/analog/0.

Objectives

Take the first step from sensor to network: read a potentiometer on the ATmega32U4's analog input (10-bit ADC, 12 analog inputs on the Yún) and expose the value to the network via the Bridge REST API. You will understand the complete path: pin → 32U4 → internal serial port (pins 0/1) → AR9331 → HTTP → browser.

Hardware

Complete code

// Le Bridge expose les lectures analogiques via /arduino/analog/<pin>.
// Il suffit de faire vivre le pont : le service REST lit les broches en direct.
#include <Bridge.h>

void setup {
  Bridge.begin;     // attend que Linino OS soit prêt
  Console.begin;
  Console.println(F("Potentiometre pral sur A0"));
}

void loop {
  // Optionnel : publier nous-mêmes une valeur dans le « data store » du Bridge,
  // lisible via http://arduino.local/data/get/pot
  static uint32_t derniere = 0;
  if (millis - derniere >= 200) {
    derniere = millis;
    int v = analogRead(A0);              // 0..1023 (ADC du 32U4)
    Bridge.put("pot", String(v));        // route /data/get/pot
    Console.print(F("pot=")); Console.println(v);
  }
}

Expected verification

Three URLs, three views of the same reality: http://arduino.local/arduino/analog/0 returns the raw reading 0–1023; http://arduino.local/data/get/pot returns the value published by Bridge.put; the Serial Monitor displays the rate at 5 Hz. Turn the potentiometer: all three follow in near real-time. Also test from a smartphone: this is your first telemetry server.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials