Raspberry Pi Pico Tutorial - 5V Relay Module

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone and welcome back to the nerd cave in today's tutorial we're gonna look at how to connect this five volt relay to the raspberry pi pico before we start this video i first want to say thank you to all that are subscribed making us reach the first youtube milestone which is 100 subscribers so the next milestone will be that 1000 subscribers one of the most useful things you can do with the pico is to control higher voltages especially ac voltage in a typical range depending on your location of 120 to 240 volt in appliances like fans lights and other household appliances since the pico can only deliver a maximum voltage at 5 volt and limited current it can control these devices directly but you can use a 5 volt relay to switch 120 to 240 volt up to 10 amperes using the pico with a 5 volt relay we will first look at controlling this led light lamp base using a relay and the pico to turn it on and off every 5 seconds then we end the video by using a photo resistor to turn on the led light base when the resistance is a specific value acting like a day 9 switch a day night switch switches outdoor lighting on and off automatically it consists of a light sensitive element that registers the ambient light in this case we are using this photoresistor the relay will close and turn on the light bulb if we reach a preset value of resistance measured by our pico through the analog to digital converter just a warning before we start this tutorial involves high voltages that can cause serious injury or death please take all the necessary precautions and turn off all the power to a circuit breaker before working on it in this tutorial i'll use the srd 5 volt sl-c5 volt relay because it's a very popular among the arduino and diy electronics hobbyist let's start with seeing how the 5v relay works then i'll show you how to set it up with the pico and give you some code to get it working the relay has three high voltages terminal normally closed common and normally open which connected devices you want to control the other side has three low voltage bands ground vcc and signal which connect to the pico inside the relay is 120 to 240 volt switch that is connected to an electromagnet when the relay receives a high signal at the signal pen the electromagnet becomes charged and moves the contacts of the switch open or closed so let's take a look at what is meant by normally open versus normally closed the one you will use depends on whether you want a 3.3 volt signal to turn on the switch or turn the switch off the 122 240 volt supply current enters a relay at the common terminal in both configurations to use the normally open contacts use the no terminal and to use the normally closed contacts you use the nc terminal when the relay receives a high signal in a normally open configuration the 120 to 240 volt switches close and allows current to flow from the common terminal to the normal open terminal so if you want the high signal to turn on the relay use the normally open terminal now when we use the normally closed a high signal opens the switch in a normally closed configuration and interrupts the 120 to 240 volt current a low signal will close the switch and allow the current to flow from the common terminal to the normally closed terminal therefore if you want to use the high signal to turn off the 122 240 volt current use the normally closed terminal for this tutorial we will use the normally open configuration let's look at the schematic diagram the relay module has a plus where you will connect the 5v from the picker's 5v output and the module's ground to any ground pin on the pico for a signal pin labelled s i will use gp18 which is pen 24 but you can use any other gp pen on the pico we will connect one end of the blue wire which is your neutral to common and the other end of the split we did to normally closed for the load now it is time to code and control the relay open funny and create a new file from machine we will import pen and import the utime library for delay we will create a variable relay and set it equal to pen 18 making it a pan out then we create an endless loop by saying while true and we set the relay value to 1 sending a high signal closing the contacts allowing the lamp to turn on we then wait 5 seconds using the sleep function and set the signal being sent to the relay to 0 opening the relay contacts turning off the lamp and wait another 5 seconds before we repeat this whole block of code that is in short how we control the relay module now let's look at something more practical we are going to add a light dependent resistor to our circuit a photoresistor or light dependent resistor and ldr for short is an electronic component that is sensitive to light when the light falls upon it then the resistance changes to make the changes to our schematic we'll connect the one leg of the ldr to the five volt rail and the other leg to pin 34 which is our analog to digital converter channel 2 and from that leg 100 kilo ohm to ground now from our machine library we will also import adc then we create a variable called ldr and we'll put it equal to the adc pen 28 which is our channel number two then in our main loop we will create a variable called reading reading the 16 bit value of our ldr then we print out that reading and we do a short delay of 0.2 now you're gonna have to play around with the values you're reading because there is different types of ldr that has different type of resistance that is why we are printing out a reading we see that if the light is on we're getting a value about five thousand and when i put my hand over the ldr or create a shadow the value drops below three thousand so i'm just gonna create an if statement if reading is smaller than three thousand we're gonna set a relay value to one else if the reading value is greater than 5000 we will set the relay value to zero turning off the light we can see the relay works as we would expect now that you know how the relay works go and use it in your project and share it here in the comments as i would like to see that is all for the tutorial today and if you have any questions just leave a comment down below
Info
Channel: NerdCave
Views: 25,434
Rating: undefined out of 5
Keywords: relay module, raspberry pi pico, micropython
Id: gJZmbqq2-5U
Channel Id: undefined
Length: 6min 32sec (392 seconds)
Published: Mon Mar 21 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.