Newbie help for Grove Relay on RPi3 and Base Hat needed

Hi all,

I am a total newbie and therefore apologies upfront for missing knowledge.

I need help with the Grove Relay, as it is not turning on a lamp.

I have the following setup:

I want to simply turn on and off a lamp for testing and knowledge building purposes in the first step.

  • The OLED Display is working fine.
  • The Relay LED blinks correctly, when tested with and without extension cable attached.
  • The relay is connected to D5. I also tried D16 and PWM.
  • The lamp is connected to an extension cable.
  • The extension cable is wired to the relay.
  • The extension cable is put into the socket.
  • I live in Europe, 230 Volt and 50 Hertz.
  • I tried two different relays, same behaviour for both.
  • I checked the wiring without the relay. The lamp works.

Did I buy the wrong relay?
Did I wire it incorrectly?

Sorry but I have no idea of electrics and stuff. I think I need the most dumbest low bob help ever!
There is electricity on the relay, I got two minor electric shocks yesterday in the late evening. :slight_smile:

Your help is highly appreciated! :+1:

Here is my Python code:

import time
import requests
from grove.grove_oled_display_128x64  import GroveOledDisplay128x64
from grove.grove_relay import GroveRelay

# OLED Display
display = GroveOledDisplay128x64()

# Relay Number 1
relay1 = GroveRelay(5)

# Temperature variable
temp = 22

# Humidity variable
humi = 90

# CO2 variable
CO2 = 1000

# IFTTT values
IFTTT_URL = xxxxxxxxxxxxxxxxxxxxxx - ifft works just deleted the sensible information
IFTTT_KEY = xxxxxxxxxxxxxxxxxxxxxx - ifft works just deleted the sensible information

count = 0

while True:
	try:
		# Getting current time
		t = time.strftime("%H:%M", time.localtime(time.time()))
		
		# Putting time to display
		display.set_cursor(0, 0)
		display.puts('Time:')
		display.set_cursor(0, 6)
		display.puts(t)
		print("Time set")
		
		# Putting temp to display
		display.set_cursor(1, 0)
		display.puts('Temp:')
		display.set_cursor(1, 6)
		display.puts(str(temp)+" C")
		print("Temp set")
		
		# Putting humi to display
		display.set_cursor(2, 0)
		display.puts('Humi:')
		display.set_cursor(2, 6)
		display.puts(str(humi)+" P")
		print("Humi set")
		
		# Putting CO2 to display
		display.set_cursor(3, 0)
		display.puts('CO2:')
		display.set_cursor(3, 6)
		display.puts(str(CO2)+" PPM")
		print("CO2 set")
		
		count += 1
		
		if count == 10:
		
			# Testing Relay Number 1
			relay1.on()
			time.sleep(10)
			relay1.off()
			time.sleep(1)
			print("Relay 1 Test")
		
			requests.post(IFTTT_URL + IFTTT_KEY, json = {'value1':temp, 'value2':humi, 'value3':CO2})
			print("Uploaded to IFTTT sheet")
			count = 0
	
	except KeyboardInterrupt:
		# Exit procedure for keyboard interrupt
		relay1.off()
		display.off()
		print("KeyboardInterrupt")
		exit(1)   
		
	except:
		# Exit procedure for everything else
		relay1.off()
		display.off()
		print("Except Exit")
		exit(1) 

Here are the pictures of the wiring and the information of the lamp:

adc.py output without any attachements to the base hat results in:

pi@raspberrypi:~/grove.py/grove $ python adc.py
1650
1650
1652
1650
1649
1654
1651
1658
1654
1655
1657
1654
1655
1653
1654

Hi @Matthias_K , Can you try using relay only on the raspberry pi with the example code provided in the wiki page!

from grove.gpio import GPIO
 
 
class GroveRelay(GPIO):
    def __init__(self, pin):
        super(GroveRelay, self).__init__(pin, GPIO.OUT)
 
    def on(self):
        self.write(1)
 
    def off(self):
        self.write(0)
 
 
Grove = GroveRelay
 
 
def main():
    import sys
    import time
 
    if len(sys.argv) < 2:
        print('Usage: {} pin'.format(sys.argv[0]))
        sys.exit(1)
 
    relay = GroveRelay(int(sys.argv[1]))
 
    while True:
        try:
            relay.on()
            time.sleep(1)
            relay.off()
            time.sleep(1)
        except KeyboardInterrupt:
            relay.off()
            print("exit")
            exit(1)            
 
if __name__ == '__main__':
    main()

also share a wiring diagram if possible! Thanks.

Thanks @salman for the help.

Output is:

pi@raspberrypi:~/grove.py/grove $ python wikiTest.py
Usage: wikiTest.py pin

Wiring diagram is in progress. Will post it asap.

and here is the …“diagram” …

Does that help?

@Matthias_K Dose the example code works, any output from the relay? , and the digram looks good.

The code output is:

pi@raspberrypi:~/grove.py/grove $ python wikiTest.py
Usage: wikiTest.py pin

@Matthias_K You also need to mention the pin you are using! example

python grove_relay.py 12

Here I, am using 12th Pin.

Ah sorry. Sure.
Did test it on 12 and 5. Both times the LED (D3) blinks red.

Which LED? The program should turn on and turn off the relay in delay of 1 sec, and are you able to do that?

No. Still all in all the same behaviour. The lamp doesn´t turn on.

LED meant the small red light on the relay itself. This blink red in an intervall of 1 second like given via the code.

Should the relay give some sort of audio feedback? clicking or something similar?

Yes, you should hear a tik sound from the relay when it’s enable, can you remove the lamp wire from the relay and try again. can you check you getting the tik sound!

@salman Thanks for your support. It works now.

It didn´t work because both the two relays I tried before are apparently dead.
I had two others in spare, they both work and do the clicking.

But seriously @Seeed ? Buying four and two of them are broken? Quality is something different. I will never again buy products from you directly. I am angry!

It’s working fine right?

Yes. Thanks again @salman for your support.

Great, Happy making :grinning::+1:. The Mechanical relay has some tear and wear, there is another type of relay which is more stable and reliable, Solid State Relay take a look

1 Like