Hello. I am making a water fountain for my cat. I have an Arduino Nano, powered via miniUSB from a 5v phone charger. I have a 5v relay and a motion PIR sensor, powered from arduino's 5v. The relay clicks when moving, seems fine. When I connect the pump, the pump works but the relay keeps clicking. The voltage slightly drops to 4.7 - 4.8v. Pump is supposed to be 3-6v 100-200mah. The pump is connected to another charger. The pump works, but the relay clicks like once every 0.1 seconds. This is the code.
const int MOTION_SENSOR_PIN = 8; // Arduino pin connected to the OUTPUT pin of motion sensor
const int RELAY_PIN = 6; // Arduino pin connected to the IN pin of relay
int motionStateCurrent = LOW; // current state of motion sensor's pin
int motionStatePrevious = LOW; // previous state of motion sensor's pin
void setup() {
Serial.begin(9600); // initialize serial
pinMode(MOTION_SENSOR_PIN, INPUT); // set arduino pin to input mode
pinMode(RELAY_PIN, OUTPUT); // set arduino pin to output mode
}
void loop() {
motionStatePrevious = motionStateCurrent; // store old state
motionStateCurrent = digitalRead(MOTION_SENSOR_PIN); // read new state
if (motionStatePrevious == LOW && motionStateCurrent == HIGH) { // pin state change: LOW -> HIGH
Serial.println("Motion detected!");
digitalWrite(RELAY_PIN, HIGH); // turn on
}
else
if (motionStatePrevious == HIGH && motionStateCurrent == LOW) { // pin state change: HIGH -> LOW
Serial.println("Motion stopped!");
digitalWrite(RELAY_PIN, LOW); // turn off
}
}
I know, I know... everything is connected right and it all works, but it doesn't work... and I am wrong... so that means, if you hook it up like this, and it works, you will be saying I am right... but since you have everything right and it works but it doesn't work... this must be wrong. Dilemma.
Corrected image shows the missing 5vdc phone charger power going to the coil side of the relay and sharing ground... or not.
@lupuom
The diagram you show in post #7 is fine and it should work.
Does it work OK if you have the USB connected to a computer?
Is there a sensitivity adjustment on the PIR device?
With a computer USB, it is the same. The thing is, the relay clicks and works perfectly when NOT connected to the pump. It respects the set time on the PIR sensor, everything. When I connect the pump... Clickclickclickclick. Pump works. The clicking is extremely annoying though.
Your assumption that connecting the pump should not have an effect on the relay is correct but it is happening.
One bad thing is that you are running a 3-6V pump on 12V, that is not good.
Another bad thing is that you don't have a flyback diode on the pump.
is it intended that your drawing and the sketch do not comply?
Sketch:
const int MOTION_SENSOR_PIN = 8; // Arduino pin connected to the OUTPUT pin of motion sensor
const int RELAY_PIN = 6; // Arduino pin connected to the IN pin of relay
const int MOTION_SENSOR_PIN = 7; // Arduino pin connected to the OUTPUT pin of motion sensor
const int RELAY_PIN = A5; // Arduino pin connected to the IN pin of relay
Please don't post diagrams that don't show exactly how you have things connected and what powers sources you are using. It just makes us go on wild goose chases and we get nowhere in trying to help you.
Please show us exactly how you have things connected and how things are powered.