Uno mit 12-V-Netzteil und USB gleichzeitig: Brennt mein Laptop durch?
Von English mit KI übersetzt ·
hallo, ich bin Studienanfänger im ersten Jahr, bitte entschuldigt, falls das offensichtlich ist.Ich habe einen Uno, der über A0 einen kapazitiven Bodenfeuchtesensor ausliest und über ein Relaismodul ein 12-V-Magnetventil schaltet. Der Uno kommuniziert über die serielle USB-Verbindung mit meinem Laptop, und ein kleines Python-Skript auf dem Laptop liest die Zeilen aus und sendet sie mit der HTTP-API des Geräts an Hermetry. Das funktioniert, ich sehe soil_moisture auf meinem Board.Das Ventil braucht 12 V, deshalb möchte ich ein 12-V-Netzteil an die Hohlstecker-Buchse anschließen. Ist es in Ordnung, Hohlstecker-Buchse und USB-Kabel gleichzeitig angeschlossen zu lassen? Ich habe Angst, dass Strom in den USB-Anschluss meines Laptops zurückfließt.Außerdem gibt es zwei seltsame Dinge: Wenn das Ventil klickt, springt der Feuchtewert für einige Messungen von etwa 410 auf 600 und etwas darüber, und manchmal verschwindet der COM-Port vom Laptop, und mein Skript stürzt mit „could not open port“ ab.
hi, first year student, so sorry if this is obvious.
I have an Uno reading a capacitive soil moisture sensor on A0 and switching a 12 V solenoid valve through a relay module. The Uno talks to my laptop over USB serial, and a small Python script on the laptop reads the lines and posts them to Hermetry with the device HTTP API. That part works, I can see soil_moisture on my board.
The valve needs 12 V so I want to plug a 12 V adapter into the barrel jack. Is it OK to have the barrel jack AND the USB cable plugged in at the same time? I’m scared of back-feeding into my laptop’s USB port.
Also two weird things: when the valve clicks, the moisture reading jumps from around 410 to 600-something for a few samples, and sometimes the COM port disappears from the laptop and my script crashes with „could not open port“.
Von English mit KI übersetzt ·
Ich denke, man muss sich für eines von beiden entscheiden? Ich ziehe das USB-Kabel immer ab, wenn ich ein Netzteil benutze.
I think you have to choose one or the other? I always unplug the USB when I use an adapter.
Von English mit KI übersetzt ·
Nein, der Uno verkraftet beides. Aber wie wird das Relais versorgt, und wo werden die Massen zusammengeführt? Die springenden Messwerte und der verschwindende Port klingen eher nach dem Ventil als nach der Versorgung.
No, the Uno handles both. But how is the relay powered, and where do the grounds meet? The jumping readings and the disappearing port sound like the valve, not the supply.
Von English mit KI übersetzt ·
Der VCC des Relaismoduls liegt am 5V-Pin des Uno. Das Ventil wird über den Relaiskontakt mit 12 V aus demselben Netzteil versorgt. Alles teilt sich eine gemeinsame Masse auf dem Breadboard. Nirgends eine Diode, ich wusste nicht, dass ich eine brauche.
Relay module VCC is on the Uno’s 5V pin. Valve is 12 V through the relay contact, from the same adapter. Everything shares one ground on the breadboard. No diode anywhere, I didn’t know I needed one.
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.
Von English mit KI übersetzt ·
Es war die Diode. Ich habe eine 1N4007 am Ventil angebracht und das Relais auf eine eigene 5-V-Versorgung umgesetzt. Der COM-Port ist in zwei Tagen kein einziges Mal abgebrochen, und der Messwert bleibt beim Umschalten des Ventils um 405-415. Außerdem habe ich die einsekündige Pause eingefügt. Danke!
It was the diode. Put a 1N4007 on the valve and moved the relay to its own 5 V supply. The COM port hasn’t dropped once in two days and the reading stays around 405-415 when the valve switches. Also added the one second pause. Thanks!
Von English mit KI übersetzt ·
Haha, ich nehme es zurück. Habe auch etwas dazugelernt.
Ha, I stand corrected. Learned something too.
- Du musst angemeldet sein, um auf dieses Thema antworten zu können.
Mitdiskutieren
Melde dich an, um Fragen zu stellen und zu beantworten, hilfreiche Beiträge mit „Gefällt mir“ zu markieren und die Antwort zu kennzeichnen, die dein Problem gelöst hat. Jeder Beitrag bringt Punkte und Stufen.

