Von English mit KI übersetzt ·
Beides gleichzeitig ist kein Problem. Der Uno hat einen Komparator, der die 5-V-Schiene ab einer VIN-Spannung von etwa 6,6 V auf den Regler umschaltet, und die USB-Datenübertragung funktioniert weiter, weil es den seriellen Leitungen egal ist, woher die Versorgung kommt. Dein Laptop ist dadurch nicht gefährdet.Das Problem ist das Magnetventil. Eine Magnetspule ohne Freilaufdiode erzeugt jedes Mal, wenn das Relais öffnet, eine hohe Spannungsspitze, und diese Spitze läuft über die gemeinsame Masse des Breadboards. Das ist der Sprung im Analogwert und sehr wahrscheinlich auch der Grund, warum USB abbricht. Das würde ich ändern:
- Eine 1N4007 parallel zum Magnetventil, Kathode an +12 V.
- Die Relaisspule nicht über den 5V-Pin des Uno versorgen, sondern von der 12-V-Seite oder einer separaten 5-V-Versorgung. Der Spannungsregler auf dem Board wird heiß, wenn er ein Relais aus 12 V Eingangsspannung speist.
- Die Masse des Ventils zurück zum Netzteil führen und nur an einem Punkt mit der Uno-Masse verbinden, nicht über die Breadboard-Schienen, an denen auch der Sensor hängt.
- 100 nF plus 10 µF parallel zur Sensorversorgung, nah am Sensor.
- Im Sketch nach dem Umschalten des Ventils eine Sekunde lang nicht messen und 8 Messwerte mitteln.
Auf der Laptop-Seite nur saubere Messwerte senden und den Zeitstempel von Hermetry setzen lassen, sofern die Uhr deines Laptops nicht synchronisiert ist:
import serial, requests
s = serial.Serial("/dev/ttyACM0", 9600, timeout=5)
URL = "https://<your-host>/api/v1/telemetry"
HDR = {"Authorization": "Bearer <device token>", "Content-Type": "application/json"}
while True:
line = s.readline().decode(errors="ignore").strip()
if line.isdigit():
requests.post(URL, json={"soil_moisture": int(line)}, headers=HDR, timeout=10)
Die Regeln für die Nutzdaten stehen unter Device HTTP API.
Both at once is fine. The Uno has a comparator that switches the 5 V rail to the regulator when VIN is above roughly 6.6 V, and USB data keeps working because the serial lines don’t care where power comes from. Your laptop is not at risk from that.
The trouble is the solenoid. A solenoid coil with no flyback diode throws a big voltage spike every time the relay opens, and that spike goes through your shared breadboard ground. That’s the jump in the analog reading and very likely the USB dropping out. What I’d change:
- A 1N4007 across the solenoid, cathode to +12 V.
- Take the relay coil power from the 12 V side or a separate 5 V supply, not the Uno’s 5V pin. The onboard regulator gets hot feeding a relay off 12 V in.
- Run the valve’s ground back to the adapter, and join it to the Uno ground at one point only, not through the breadboard rails the sensor uses.
- 100 nF plus 10 µF across the sensor supply, close to the sensor.
- In the sketch, don’t sample for a second after switching the valve, and average 8 readings.
On the laptop side, send only clean readings and let Hermetry stamp the time unless your laptop clock is synced:
import serial, requests
s = serial.Serial("/dev/ttyACM0", 9600, timeout=5)
URL = "https://<your-host>/api/v1/telemetry"
HDR = {"Authorization": "Bearer <device token>", "Content-Type": "application/json"}
while True:
line = s.readline().decode(errors="ignore").strip()
if line.isdigit():
requests.post(URL, json={"soil_moisture": int(line)}, headers=HDR, timeout=10)
Payload rules are on Device HTTP API.

