# Automation pHAT information

**URL:** <https://forums.pimoroni.com/t/automation-phat-information/4570>\
**Category:** Support\
**Created:** [April 13, 2017, 12:24pm UTC](https://forums.pimoroni.com/t/automation-phat-information/4570 "2017-04-13T12:24:35Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![ColinS](https://avatars.discourse-cdn.com/v4/letter/c/e56c9b/32.png) [@ColinS](https://forums.pimoroni.com/u/ColinS)\
**Post date:** [April 13, 2017, 12:24pm UTC](https://forums.pimoroni.com/t/automation-phat-information/4570/1 "2017-04-13T12:24:36Z")

</div>

Hi I’m new to the PI .I want to use ADC input to turn on the relay. Where do I find the coding for the Automation pHAT?

---

<div class="post-metadata">

**Author:** ![RogueM](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/roguem/32/311_2.png) [@RogueM](https://forums.pimoroni.com/u/RogueM)\
**Post date:** [April 13, 2017, 2:20pm UTC](https://forums.pimoroni.com/t/automation-phat-information/4570/2 "2017-04-13T14:20:03Z")

</div>

the repository can be found here: [https://github.com/pimoroni/automation-hat](https://github.com/pimoroni/automation-hat)

to achieve what you want you’d need to read an analog input like so:

```
value = automationhat.analog.one.read()

```

then use it in a conditional to turn the relay on:

```
automationhat.relay.one.on()

```

… that is broadly speaking the approach, the exact code you need to run will depend on your needs. Check the library doc for more options.

---

<div class="post-metadata">

**Author:** ![ColinS](https://avatars.discourse-cdn.com/v4/letter/c/e56c9b/32.png) [@ColinS](https://forums.pimoroni.com/u/ColinS)\
**Post date:** [April 14, 2017, 11:05am UTC](https://forums.pimoroni.com/t/automation-phat-information/4570/3 "2017-04-14T11:05:10Z")

</div>

Hi thanks for the info. As I said I am very new to Pi. I have looked at the three examples in the GitHub is this the library doc you were referring to? I will be ok writing my code I just require the commands.

---

<div class="post-metadata">

**Author:** ![RogueM](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/roguem/32/311_2.png) [@RogueM](https://forums.pimoroni.com/u/RogueM)\
**Post date:** [April 14, 2017, 1:04pm UTC](https://forums.pimoroni.com/t/automation-phat-information/4570/4 "2017-04-14T13:04:28Z")

</div>

There is an API reference available in the ‘documentation’ directory. Most methods should be documented there.

… used alongside the examples they should give you a fair understanding of the library, but feel free to ask here if you get stuck.

---

<div class="post-metadata">

**Author:** ![ColinS](https://avatars.discourse-cdn.com/v4/letter/c/e56c9b/32.png) [@ColinS](https://forums.pimoroni.com/u/ColinS)\
**Post date:** [April 14, 2017, 4:31pm UTC](https://forums.pimoroni.com/t/automation-phat-information/4570/5 "2017-04-14T16:31:02Z")

</div>

Super thanks got the info now and prepared to start coding.

---

<div class="post-metadata">

**Author:** ![ColinS](https://avatars.discourse-cdn.com/v4/letter/c/e56c9b/32.png) [@ColinS](https://forums.pimoroni.com/u/ColinS)\
**Post date:** [April 15, 2017, 9:48am UTC](https://forums.pimoroni.com/t/automation-phat-information/4570/6 "2017-04-15T09:48:49Z")

</div>

Hi I have started testing the automation phat but have hit a problem reading the ADC .i have connected ADC One input to 5v when I run the code using  
Value=automationhat.analog.one.read()  
Print Value  
I get  
Automation pHAT detected…  
0.0  
I assume this value should (if 10 bit ADC)be between 0 and 1023. Or am I missing something. I get the same result on the other two ADC inputs. I have checked with a DMM that there is 5v on the terminal.  
The input, output and relay circuits are working ok. Also what current can the output circuits sink?  
Thanks

---

<div class="post-metadata">

**Author:** ![pi2003](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/pi2003/32/1613_2.png) [@pi2003](https://forums.pimoroni.com/u/pi2003)\
**Post date:** [April 15, 2017, 11:26am UTC](https://forums.pimoroni.com/t/automation-phat-information/4570/7 "2017-04-15T11:26:55Z")

</div>

I believe it is a 12 bit Adc and the value back is a voltage. If you look at my topics I have created there is one about changing the value from an enviro phat from a voltage to a number between 0-1023 an a lot of it is cross compatible over to automation phat.

The topic is called getting a number from ads1015

---

<div class="post-metadata">

**Author:** ![ColinS](https://avatars.discourse-cdn.com/v4/letter/c/e56c9b/32.png) [@ColinS](https://forums.pimoroni.com/u/ColinS)\
**Post date:** [April 15, 2017, 12:54pm UTC](https://forums.pimoroni.com/t/automation-phat-information/4570/8 "2017-04-15T12:54:38Z")

</div>

Hi thanks for the info. Returning a voltage is what I need . But my problem is that the ADC is giving 0.0 when a voltage (5v) applied to any ADC input.

---

<div class="post-metadata">

**Author:** ![pi2003](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/pi2003/32/1613_2.png) [@pi2003](https://forums.pimoroni.com/u/pi2003)\
**Post date:** [April 15, 2017, 1:11pm UTC](https://forums.pimoroni.com/t/automation-phat-information/4570/9 "2017-04-15T13:11:47Z")

</div>

I believe tha ADC is 24 v but that wouldn’t be a problem. Can you attach a potentiometer and see what happens then?

---

<div class="post-metadata">

**Author:** ![ColinS](https://avatars.discourse-cdn.com/v4/letter/c/e56c9b/32.png) [@ColinS](https://forums.pimoroni.com/u/ColinS)\
**Post date:** [April 15, 2017, 2:22pm UTC](https://forums.pimoroni.com/t/automation-phat-information/4570/10 "2017-04-15T14:22:52Z")

</div>

Thanks I have found the issue. I only asked for one ADC read this gave 0.0v. I then used a while true loop which gave 5.3v on all but the first reading(0v).  
So can you tell me why the first reading is always 0.0v as this may cause a problem with my project as I want to operate the relay when the ADC reading falls below 3.8v.

---

<div class="post-metadata">

**Author:** ![pi2003](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/pi2003/32/1613_2.png) [@pi2003](https://forums.pimoroni.com/u/pi2003)\
**Post date:** [April 15, 2017, 2:39pm UTC](https://forums.pimoroni.com/t/automation-phat-information/4570/11 "2017-04-15T14:39:54Z")

</div>

I have no idea why the ADc would do that. I am away from my kit at the moment so I can not test it on other ads1015 devidces but from memory this is not an issue that I have run into before and a quick google does not produce any promising results. Could you post the code you are using?

---

<div class="post-metadata">

**Author:** ![ColinS](https://avatars.discourse-cdn.com/v4/letter/c/e56c9b/32.png) [@ColinS](https://forums.pimoroni.com/u/ColinS)\
**Post date:** [April 15, 2017, 3:37pm UTC](https://forums.pimoroni.com/t/automation-phat-information/4570/13 "2017-04-15T15:37:52Z")

</div>

Hi ADC one is connected directly to the 3.3v pin on the phat.  
Code 1  
#!/use/bin/env python  
Import automationhat  
Print(automationhat.analog.one.read())

When run gives  
Automation pHat detected…  
0.0

Code 2  
Import time  
Import automationhat  
While true:  
print(automationhat.analog.one.read())  
sleep(1.0)

When run gives  
Automation pHAT detected…  
0.0  
3.31  
3.31  
3.31  
Thanks for the help this issue is not urgent I need to sort it before I start coding my project. So if its easier to leave it until after Easter that’s fine.

---

<div class="post-metadata">

**Author:** ![RogueM](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/roguem/32/311_2.png) [@RogueM](https://forums.pimoroni.com/u/RogueM)\
**Post date:** [April 15, 2017, 3:38pm UTC](https://forums.pimoroni.com/t/automation-phat-information/4570/14 "2017-04-15T15:38:57Z")

</div>

I think this is because creating the ads1015 class instance initialises the i2c bus, but perhaps the cause lies elsewhere. You should add a short pause after import of the library and that should take care of that.

Still, if there are readings that you would normally deem aberrations, i.e impossible under normal circumstances, it is probably a good idea for your code to exclude/ignore values returned outside of that expected range. Failing that you expose yourself to quite a lot of pain, potentially.

---

<div class="post-metadata">

**Author:** ![ColinS](https://avatars.discourse-cdn.com/v4/letter/c/e56c9b/32.png) [@ColinS](https://forums.pimoroni.com/u/ColinS)\
**Post date:** [April 15, 2017, 4:04pm UTC](https://forums.pimoroni.com/t/automation-phat-information/4570/15 "2017-04-15T16:04:16Z")

</div>

Thanks I put a sleep 1.0 delay after the import now getting consistent reading. I can now start writing code. Thanks for the advice re testing the input range.  
Thank you guys you are very helpful at Pimoroni.

---

<div class="post-metadata">

**Author:** ![gadgetoid](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/gadgetoid/32/13_2.png) [@gadgetoid](https://forums.pimoroni.com/u/gadgetoid)\
**Post date:** [April 19, 2017, 4:05pm UTC](https://forums.pimoroni.com/t/automation-phat-information/4570/16 "2017-04-19T16:05:56Z")

</div>

I’d definitely echo @RogueM’s advice and suggest you use something like a moving average or other smoothed value from the ADC. They’re definitely not immune to jitter and abnormal readings which could flutter your relay output.

There’s always a trade off between accuracy and response time. Although in this case you should get below 100ms response even when taking an average of 100 samples. Assuming Python can keep up, of course.
