Page 1 of 1

Sense a voltage and turn on a pin

Posted: Thu Jul 21, 2016 7:01 pm
by Ridley Walker
i want to control temperature in a small greenhouse. I have a proper sensor ordered, but in the meantime, i have been hacking around with a simple resistor/thermistor string between 3.3v and ground. I can sense the voltage on ADC1, print it, and blink an led once a second.
I have been trying use an " if ADC is > do something" "else if ADC is < do something" where "do something" is turn a pin on or off, etc
I have used every iteration "while" " if > ,if < " that i can think of. I have run out of ideas.

If anybody could point me to a code snippet that will help me get this done, i will be most appreciative.

Re: Sense a voltage and turn on a pin

Posted: Thu Jul 21, 2016 7:11 pm
by dhylands
I'd highly recommend that you take a free python course. I think the gist of what you're looking for is along these lines:

Code: Select all

while True:
    adc_value = read_adc_value()
    if adc_value > upper_threshold:
        set_gpio_high()
    elsif adc_value < lower_threshold:
        set_gpio_low()
This web page has lots of examples: https://docs.python.org/3/tutorial/index.html
If you want something a bit more structured like a course, then this udacity course is reasonable:
https://www.udacity.com/course/intro-to ... nce--cs101

Re: Sense a voltage and turn on a pin

Posted: Thu Jul 21, 2016 11:53 pm
by Ridley Walker
thanks Dave,
I have been looking for a course that is "beginner " enough for me. I was going thru a course from Code Academy, I think it was, but it disappeared! I'll have to get more serious looking for it...

In your code you referenced "elsif". Did you mean "elif"?

Re: Sense a voltage and turn on a pin

Posted: Fri Jul 22, 2016 1:17 am
by dhylands
Ridley Walker wrote:In your code you referenced "elsif". Did you mean "elif"?
Yeah - I work in a bunch of different programming languages on a more or less daily basis, so sometimes I get things confused.

Re: Sense a voltage and turn on a pin

Posted: Fri Jul 22, 2016 2:41 pm
by Ridley Walker
Confused? Confused!!! You have no idea.
Imagine me at 76 yrs old, can't remember what i had for breakfast, zero experience with this stuff.

Thanks again, your code fixed me right up. I used your code to show me the errors in the stuff i had cobbled up.
Now a happy camper - my greenhouse will be warm this winter...

Re: Sense a voltage and turn on a pin

Posted: Tue Aug 16, 2016 2:21 pm
by 41536172@qq.com
and you also need to know about "PID"control.