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 ...
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 ...
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)...
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 ...
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 ...
Firstly does the following turn your relay on then off?
import RPi.GPIO as GPIO,time
You also need to add timeouts to your distance sensing code otherwise your code could get stuck in a while ...
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 ...
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 ...
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.
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. "...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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) 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?
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 ...
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 ...
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 ...
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.
The particular model you linked is even worse than most! It would not meet the standards ...
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 ...
Does the following turn on and off your relay accordingly?
import RPi.GPIO as GPIO
RELAIS_1_GPIO = 18
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:
print("moisture: " + str(touch))
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:
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:
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.