Click here to Skip to main content
15,446,510 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to turn on my LED connected to arduino board once it satisfies any condition provded in my python program. 

These are the conditions:

Temperature < 28 , Humidity < 60 , Moisture> 179:

Observation= 'Temperature & Humidity is less.'

Temperature > 28 , Humidity < 60 , Moisture< 179:

Observation= 'Humidity & Moisture is less.'

Temperature < 28 , Humidity > 60 , Moisture < 179:

Observation = 'Temperature & Moisture is less.'


I want the LED to turn on when the output is : '<pre>Humidity & Moisture is less.
'
I have created a code to user input the data and predict the value:

x=int(input("Enter the tmp:"))
y=int(input("Enter the hum:"))
z=int(input("Enter the moist:"))
my_list =[x,y,z]
my_list
xc=[my_list]
print(xc)
y_pred = loaded_model.predict(xc)
print(y_pred)

Once we enter the inputs the ouput will get displayed through 'y pred' respective to the condition provided.

I want the led to turn on when y pred gives an output as 'Temperature & Moisture is less.'

What will be the python code to turn on the led based on this?

What I have tried:

I have tried :
from pyfirmata import util, Arduino
import time


def blink(b_time):
    board = Arduino('COM5')
    it = util.Iterator(board)
    it.start()

    led_13 = board.get_pin('d:13:o')
    while True:
        led_13.write(1)
        print('Led ON')
        time.sleep(b_time)
        led_13.write(0)
        print('Led OFF')
        time.sleep(b_time)


if __name__ == '__main__':
    blink(0.2)


inorder to check whether the led will turn on or not. And the led turned on. Now I want to know how can I turn the LED based on the conditions provided above.
Posted
Updated 22-Nov-21 20:25pm

1 solution

So compare the values, and do it. You have the "on" and "off" code - so all you need it the conditional stuff: Python Conditions[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900