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.

