Hot answers tagged

4

You do not understand the way GPIO work. You can control GPIO pins, setting High or Low, and the pins retain their state, even if the Pi is shutdown. When you remove the Pi power the pins become undefined. On re-applying power the GPIO pins are configured as INPUTS, with either a weak pullup or pulldown, which depends on the pin. The pins ONLY become ...


4

I would recommend a transistor - not only does it reduce the current required but it isolates the Pi from the relay which helps to ensure that the Pi is less likely to suffer damage. Is this just a relay that you plan to drive directly? Don't forget about the reverse EMF that occurs when the relay is de-energised - it will generate a high enough voltage to ...


3

Active Low relay boards are preferable in most electronic projects. These work by adding a Optical Isolator and a MOSFET between the relay and the Controller. The MOSFET wont be drawing current until you pull that line low. neither will the OPTO Isolator. This is preferable since most IC's can sink(to ground) more current then they can source(provide current)...


3

Driving the coil of a relay requires power. Power (P) - in direct-current electrical form - may be calculated as the product of voltage (V) and current (I): P = V * I Knowing even a little bit about the GPIO specifications, and then looking at the numbers in your table, it is clear that the RPi Zero is simply incapable of supplying sufficient power to ...


3

Most relays are Active LOW - the relay is ON when the input is LOW and OFF when the input is HIGH. The specification for your relay board should state this.


2

CoderMike's Answer addressed the problems in your code, but if you are actually using the relay module pictured and have wired it in a similar manner there are more concerns. There are a number of similar (poorly-designed) relay modules on the market - they seem to infect ebay! They may work with Arduino (and TTL logic) BUT ARE A LOUSY DESIGN even for that ...


2

Firstly does the following turn your relay on then off? import RPi.GPIO as GPIO,time GPIO.setmode(GPIO.BOARD) GPIO.setwarnings(False) GPIO.setup(7,GPIO.OUT) print('on') GPIO.output(7,GPIO.LOW) time.sleep(4) print('off') GPIO.output(7,GPIO.HIGH) You also need to add timeouts to your distance sensing code otherwise your code could get stuck in a while ...


2

Thank you all for your help in diagnosing this. Relay was faulty, swapped for one of the same make and model and now its working with the test provided by Coder Mike, as well as my original script.


2

Expected scenario: always turn off the bulb when the pi disconnects, turn on the bulb only from the script NOTE: Please know this answer disregards all comments made to the OP's question. The issue you're facing cannot be solved with software alone. You will need to add some hardware if you wish to maintain positive control of your relay at all times. As ...


2

All the relays turned on as soon as the pin they were connected to was set to out mode. This is because the RPi pins toggle between 0 and 3.3V, not between 0 and 5V. So, when you set the pin to 3.3V, there's still (5-3.3 = 1.7V) applied to the LED inside the opto-isolator. If that voltage is enough to turn it on, the relay will stay activated regardless of ...


2

Answer: Yes. There are several ways this can be done. The method used will depend upon the characteristics of the load connected to the relay's contacts. Background: As @OyaMist has stated, "the actual relay state may differ from its nominal state". From a distance, when the relay state must be known, we are reduced to making a simple assumption; i.e. "...


2

You can actually do this without a RasPi. Do a Duck Duck Go for "DTMF Decoder" and you will find many products that take a direct DTMF audio signal from a land line and, depending on the code, activate one of several relays. A typical 4 relay control board sells for less than $20. Most of them are designed to control devices in your home from a ...


2

Answer Remark: Just a quick and dirty answer. Perhaps more details later. Warning: no guarantee no nothing won't meltdown or blow up. I skimmed the datasheets and quickly concluded that there is 80% chance OK, for the following reasons: (1) Touch display is SPI, and relay is I2C, (2) I2C relay has well documented instructions to change ...


2

In the comments, you may have gotten the advice not to start soldering with mains. I would agree with them, though a solution exists. In my home I use a remote controlled switching system, based on 433MHz. What I have is called "Klikaanklikuit" and the website of the vendor boasts that it is also available in Spain. But others exist. If you wire a ...


2

You've made a mistake, I'm afraid. You seem to be attempting to switch the relay coil with a GPIO pin. Unless your relay module is designed to use a 3.3V input you are at risk of breaking another RPi. GPIO pins are for 3.3V - and ONLY 3.3V In addition, the GPIO pins are delicate little flowers; they won't source (or sink) much current, and they don't ...


2

There are a number of poorly-designed relay modules on the market. They may work with Arduino (and TTL logic) BUT ARE A LOUSY DESIGN even for that purpose and totally unsuitable for the Pi as they are only controllable from 5V. The schematic of a typical module is but there are a number of variants. The best option is to return them and purchase a module ...


2

Unfortunately there are many different relay boards out there using this particular relay but that might feature different driving electronics. So it's difficult to give a definitive answer. There are however some indications that this excellent arcticle /1/ covers this board and the problems the OP describes. (Image source: /1/) I leave it to the OP to ...


1

From the rather unclear photos you have posted the device does not have an opto-isolator but a transistor. It is unclear why it doesn't work, however there is another type of poor module, triggered by a low level, with a PNP transistor which is not controllable from 3.3V. (This saved the manufacturer some fraction of a cent.) Without a circuit it is not ...


1

Question (1) How to use Rpi to control a relay to switch on/off a LED? (2) How to wire the NC and COM terminals of the relay? Answer Introduction Let us use the following example and look closely at the very right side of the schematic, the relay switch with the COM, NO, and NC terminals: Part A - How to wire the COM and NO terminals (1) COM (Common) - The ...


1

I can't imagine why you'd have to 'Google for days', but I don't think Google is the best way to find a relay with a particular set of specifications. I'd suggest you use the screens and filters available on the websites of some of the big electronic distributors. I'd probably try Mouser first. For example, I took some of the specifications in your ...


1

Try removing the jumper and powering VCC with 3.3V and JDVCC with 5V. I have used similar relays with 3.3V systems without any problems.


1

I'm sorry not being here a month ago, because that relay board is the perfect one for Raspberry Pi and it works smoothlessly. Main things to consider are three: these relays are 5V (Amazon main picture wrongly shows 12V version) the inputs are "active low" meaning that connecting them to ground results in corresponding relay coil to receive ...


1

You are another victim of the shoddy products for sale on the web. This is not a coding problem - the relay is UNSUITABLE for the Pi. They can be only be used with additional circuitry, or modifying the module. See https://raspberrypi.stackexchange.com/a/100014/8697 The particular model you linked is even worse than most! It would not meet the standards ...


1

You can power a small servo from the Pi provided there is spare power. You don't have to power it from the Pi. If you power it separately then you need to connect the servo's power supply ground and a Pi ground. Just connect the control line directly to a Pi GPIO. In summary for the servo + pin connected to power supply + - pin connected to power supply ...


1

In my case the current from my power supply to the relay module was not sufficient at 1.0 amps. I swapped it out with one rated at 2.0 amps and that got my relays switching. Thank you all.


1

Does the following turn on and off your relay accordingly? import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) RELAIS_1_GPIO = 18 GPIO.setup(RELAIS_1_GPIO, GPIO.OUT) while True: print('on') GPIO.output(RELAIS_1_GPIO, GPIO.LOW) time.sleep(2) print('off') GPIO.output(RELAIS_1_GPIO, GPIO.HIGH) time.sleep(2)


1

Setting a GPIO pin has a latching behavior. That is when you set it, it stays that same value until you tell it otherwise. So in your if statement, just add an else clause to reset it low if the value read is <=600: if touch > 600: GPIO.output(RELAIS_1_GPIO, GPIO.HIGH) print("moisture: " + str(touch)) else: GPIO.output(RELAIS_1_GPIO, GPIO....


1

OBSERVATION: I do not see a line of code / instruction to pull the GPIO back to low. If the observation is correct and this instruction is executed: GPIO.output(RELAIS_1_GPIO, GPIO.HIGH) How would the line GPIO return to a low state? Under what condition do you expect the GPIO to return to the low state? What happens if the instructions is changed to: ...


1

In the second section of code: gpioConfig=[19] so i=19 j=1 and never increments newState=statuses['gpio1'] which gives 1 As newState == 1, GPIO 19 is only every set to HIGH


1

I want to create a system that has an internet connection via a mobile sim and allows owners of enabled telephone numbers to switch a relay by ringing the device sim. In this instance, you need a SIM card module. The system just tries to upload some log files which is not too large hence you can buy a GSM module and make a 2G connection to your RPi. ...


Only top voted, non community-wiki answers of a minimum length are eligible