Uno con un adaptador de 12 V y USB a la vez: ¿me va a freír el portátil?
Traducido del English por IA ·
hola, soy estudiante de primer año, perdón si esto es obvio.Tengo un Uno que lee un sensor capacitivo de humedad del suelo en A0 y activa una electroválvula de 12 V mediante un módulo de relés. El Uno se comunica con mi portátil por serie USB, y un pequeño script de Python en el portátil lee las líneas y las envía a Hermetry con la API HTTP del dispositivo. Esa parte funciona, puedo ver soil_moisture en mi placa.La válvula necesita 12 V, así que quiero conectar un adaptador de 12 V al conector barril. ¿Es correcto tener el conector barril y el cable USB conectados al mismo tiempo? Me da miedo que se retroalimente el puerto USB de mi portátil.Además hay dos cosas raras: cuando la válvula hace clic, la lectura de humedad salta de unos 410 a 600 y pico durante unas cuantas muestras, y a veces el puerto COM desaparece del portátil y mi script se cae con «could not open port».
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».
Traducido del English por IA ·
¿Creo que hay que elegir una de las dos opciones? Yo siempre desconecto el USB cuando uso un adaptador.
I think you have to choose one or the other? I always unplug the USB when I use an adapter.
Traducido del English por IA ·
No, la Uno aguanta ambos. Pero ¿cómo se alimenta el relé y dónde se unen las masas? Las lecturas que saltan y el puerto que desaparece parecen cosa de la válvula, no de la alimentación.
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.
Traducido del English por IA ·
El VCC del módulo de relé está en el pin de 5V del Uno. La válvula recibe 12 V a través del contacto del relé, desde el mismo adaptador. Todo comparte una misma tierra en la protoboard. No hay ningún diodo, no sabía que lo necesitaba.
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.
Traducido del English por IA ·
Usar ambos a la vez no pasa nada. El Uno tiene un comparador que conmuta el riel de 5 V al regulador cuando VIN supera aproximadamente 6,6 V, y los datos por USB siguen funcionando porque las líneas serie no les importa de dónde viene la alimentación. Tu portátil no corre ningún riesgo por eso.El problema es el solenoide. Una bobina de solenoide sin diodo de libre circulación genera un pico de tensión muy grande cada vez que el relé se abre, y ese pico pasa por la masa compartida de tu protoboard. Ese es el salto en la lectura analógica y, muy probablemente, la caída del USB. Esto es lo que cambiaría:
- Una 1N4007 en paralelo con el solenoide, cátodo a +12 V.
- Alimentar la bobina del relé desde el lado de 12 V o desde una fuente de 5 V separada, no desde el pin 5V del Uno. El regulador integrado se calienta mucho si alimenta un relé desde la entrada de 12 V.
- Llevar la masa de la válvula de vuelta al adaptador y unirla a la masa del Uno en un único punto, no a través de los raíles de la protoboard que usa el sensor.
- 100 nF más 10 µF en la alimentación del sensor, cerca del sensor.
- En el sketch, no tomar muestras durante un segundo después de conmutar la válvula, y promediar 8 lecturas.
En el lado del portátil, envía solo lecturas limpias y deja que Hermetry asigne la hora a menos que el reloj del portátil esté sincronizado:
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)
Las reglas del payload están en 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.
Traducido del English por IA ·
Era el diodo. Puse un 1N4007 en la válvula y pasé el relé a su propia alimentación de 5 V. El puerto COM no se ha caído ni una vez en dos días y la lectura se mantiene alrededor de 405-415 cuando la válvula conmuta. También añadí la pausa de un segundo. ¡Gracias!
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!
Traducido del English por IA ·
Ja, me equivoqué. Yo también he aprendido algo.
Ha, I stand corrected. Learned something too.
- Debes estar registrado para responder a este debate.
Únete a la conversación
Inicia sesión para preguntar y responder, dar me gusta a las publicaciones útiles y marcar la respuesta que resolvió tu problema. Cada aportación suma puntos y niveles.

