GrovePi Temperature reading to Trigger Relay


I want my Grove PI too start the Relay when the Temperature goes over 20 Degrees.

I have the Tempreture reader Code however i need it too trigger the Relay when the Tempreture is elevated too 20 Degrees.

I think you need to use the digitalWrite function available in the GrovePi library. That function will actuate the relay whenever you want to - for instance when the temperature goes over 20 degrees.

You might want to check this documentation for this given function:

I think this is what you’re asking. Let me know if you’re facing any difficulties with your GrovePi.

Thank you!

Hi Robert,

Thank you for your reply. We are both working on this for a school project.

We have the GrovePi Starter Kit and are trying to work out a way for the Relay to trigger at a set Temperature (as detedcted by the humidity/temp sensor).

We have the Sensor working and sending the Temp & Humidity to the LCD scree. The issue is, as n00bs we are not sure how to take the Temp reading, determine if it is 22degrees or higher and the turn the Relay on (ie. to power a device connected to it).

Any clues on where we may see some sample code?

Thanks again mate.

Kind regards,


Hi @s1477035,

First of all, are you the same user as @s1480052? Thanking me for my reply tells me you are, in which case, I’d suggest you use just one account for replying. It’s really not necessary having multiple accounts.

Well, that really depends on what sensor you are using.

If you’re using the Grove Temperature Sensor, then you’ll have to use the following function:

And if it’s a DHT sensor, like the DHT11, DHT22, DHT21 or AM2301, then you’ll have to use this one:

Otherwise, if it’s an entirely different device that we haven’t covered, then you’ll have to come up with your own implementation or at least find a library on the web to do that.

Thank you!