0

I have a pi 3B and a relay board - "5V relay module is active LOW, meaning that LOW level will activate the relay on and HIGH level will deactivate it." .

I have connected 5V to Vcc on the relay, ground to gnd and another pin and Pin 12 to ch1.

This setup works as the relay will turn on with movement but the relay goes straight off.

I am using motioneye to "run a command" and "run an end command" in the movement notification section.

I need the space on the SD card so didn't want to install Python although I can if required. It also seems a bit OTT for a simple GPIO output.

My two bash scripts are below and they have bee given 755 permissions.

lightOn.sh ( run a command )

#!/bin/bash

echo "18" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio18/direction
echo "0" > /sys/class/gpio/gpio18/value
# I have tried adding sleep 60s here
exit

lightOff.sh ( run an end command )

#!/bin/bash

echo "18" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio18/direction
# I have tried adding sleep 60s here
echo "1" > /sys/class/gpio/gpio18/value
exit

I have no experience with bash and have no idea why the above will not work; I have added sleep 60s without success in different places.

Can somebody point out what I am doing wrong?

Note: If I swap the values around the relay never goes off.

UPDATE:

I may be getting a bit further and although the site I brought the relay from says it needs to be pulled low it works the other way around BUT only once! It works every time running the script from Putty; so I assume there is a different problem somewhere.

This is my current code but as I say it will only run once and it does not do exactly what I want. I may be better off with a latching relay as I can send a on and off signal from different pins. I will discuss it with a guy at work next week who will be able to help me out.

#!/bin/bash

echo "18" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio18/direction
for i in {0..500..1}
do
 echo "1" > /sys/class/gpio/gpio18/value
sleep 0.1
done
echo "0" > /sys/class/gpio/gpio18/value
exit

@tlfong01 I didn't think you down voted me as the post was down voted a while before you posted. It annoys me when people down vote and do not leave a reason why; how am I supposed to improve the post if I do not know the problem?

I have seen " Let me google and see if I can help: " used before by people who are insinuating the OP has not put any effort into finding an answer. I am sorry to have assumed that was what you were saying. I have probably spent about 16hrs now trying to sort this out. Sometimes not having the correct search phrase can be a problem to finding the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.