ni3o
April 18, 2024, 4:49pm
1
Good evening from Germany,
I bought an Arduino a couple of days ago, it was pretty fun so far, but I hit a roadblock I can't wrap my head around.
So I have a 5V AM2315C humidity/temperature sensor and a 5V relay, my electrician colleague build for me, directly connected to Arduino UNO 4 Wi-Fi.
Arduino Board Connections
Power
5 V -> Sensor +
GND -> relay -
Digital
SCL -> SCL Sensor
SDA -> SDA Sensor
GND -> GND Sensor
PIN 4 -> relay +
The issue I have is I can switch the relay or read the sensor. If I initialize the sensor and then switch the relays, the Arduino freezes.
This loop usually runs once. Calling aht.getEvent() after digitalWrite() causes the freeze. But I have no clue why it would do that.
//simplified for testing, this exact code runs one loop
#include <Adafruit_AHTX0.h>
Adafruit_AHTX0 aht;
void setup() {
aht.begin();
pinMode(4, OUTPUT);
}
void loop() {
sensors_event_t humidity, temp;
aht.getEvent(&humidity, &temp);
delay(2000);
digitalWrite(4, HIGH);
delay(2000);
digitalWrite(4, LOW);
}
Greetings,
Nico
What is powering the relay coil? Please provide a schematic or wiring diagram.
An Arduino is not a power supply. You will likely need an external supply for the relay.
ni3o
April 18, 2024, 8:02pm
3
I provide a continuous 5V from the digital pin of the Arduino to switch the relay on, it's connected to a 230v power supply.
That makes sense, so providing 2x5V from the Arduino is too much then? I would need a relay that's turned on and off by just a pulse, then?
You need a relay module that has an interface for a digital output. Most use a transistor and/or optocoupler. Power the relay separately, and keep the relay power and AC wiring as far as you can from the Arduino, to reduce electrical interference.
The Arduino should be connected to the relay only by the digital control output, and GND.
1 Like
ni3o
April 18, 2024, 8:40pm
5
Thanks a lot for the tips, I will look into that. There are a lot more nuances to the fine electronics stuff than I thought, but I will figure it out.
Typical relay with external power and transistor driver.
1 Like
ni3o
April 19, 2024, 7:38am
7
Yeah, I don't have the separate power supply. My college is going to set it up this way.
Thanks for the help, I appreciate it a lot
system
Closed
October 16, 2024, 7:39am
8
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.