Sums

User avatar
Graeme
Cosmic Lounger
Posts: 1230
Joined: 11 Feb 2010, 12:23
Location: Medway, Kent, UK

Sums

Post by Graeme »

Would anyone like to help me with some sums please?

I will need to know the temperature in my observatory when I'm up and running. I have an Arduino with a DWT11 temperature and humidity sensor. In order to avoid the hardware and programming involved with a wireless setup and for great comic effect I though it would be an idea to output the temperature value to a servo which would then show temperature on an indicator visible from a camera inside the observatory.

So the temperature range is from -10°C to 40°C and the servo moves from 0° to about 170°. I know I can use the Arduino sketch Map function but why use the simple option when you can do something in a much more complicated way?

The servo moves anticlockwise from 170° to 0° so I need a negative slope in the y=Mx+C equation for the servo to indicate -10°C at 0° and 40°C at 170°

I used the coordinates (-10,170) (40,0) for the points on the slope.

I used:
M = y2-y1/x2-x1
= 0-170/40-(-10)
= -3.4

Then:

Y - y1 = M (X - x1) for Y = servo angle (output to servo control pin) and X = temperature (input from sensor)

So:

Y = M (X - x1) + y1

Then my CSE maths let me down! I can see that y1 is not correct because it's not actually the intercept. I tried changing it to an estimated value for C from a graph I drew and I tried working it from 0°C to 40°C with 0 as the intercept, all to no avail!

Would anyone like to have a go at some school level maths for fun, with a prize of a rem credit in my Arduino code, or should I use the Map function?

Regards

Graeme
_______________________________________

http://www.averywayobservatory.co.uk/

User avatar
HansV
Administrator
Posts: 78474
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Sums

Post by HansV »

Your description is somewhat confusing. First, you mention

-10°C at 0° and 40°C at 170°

and then you use coordinates

(-10,170) (40,0)

Which of these two is correct?
Best wishes,
Hans

User avatar
Graeme
Cosmic Lounger
Posts: 1230
Joined: 11 Feb 2010, 12:23
Location: Medway, Kent, UK

Re: Sums

Post by Graeme »

HansV wrote:
29 Jan 2023, 08:23
Your description is somewhat confusing.

That's a natural ability I have!

So when the (strangely backwards) servo is sent to an angle of 0° the pointer will point to show 40°C. When the servo is sent to an angle of 170° the pointer will point to show -10°C.

The slope goes from (x1,y1) to (x2,y2) = (-10,170) to (40,0)

I think that's right this time! :laugh:
_______________________________________

http://www.averywayobservatory.co.uk/

User avatar
HansV
Administrator
Posts: 78474
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Sums

Post by HansV »

OK, so the slope is indeed -170/50 = -3.4

The equation becomes

Angle - 170 = -3.4 * (Temperature - -10)

so

Angle = -3.4 * Temperature + 136

Reverse:

Temperature = (136 - Angle) / 3.4

See the attached Excel workbook.

Servo.xlsx
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

User avatar
Graeme
Cosmic Lounger
Posts: 1230
Joined: 11 Feb 2010, 12:23
Location: Medway, Kent, UK

Re: Sums

Post by Graeme »

Brilliant!

Seems I was using 0 for y1 instead of 170!

To be fair, it was a long time ago when I was at school, when I thought I would never need y=Mx+c!

Thanks loads.

Regards

Graeme
_______________________________________

http://www.averywayobservatory.co.uk/

User avatar
stuck
Panoramic Lounger
Posts: 8176
Joined: 25 Jan 2010, 09:09
Location: retirement

Re: Sums

Post by stuck »

Graeme wrote:
29 Jan 2023, 15:45
...it was a long time ago when I was at school, when I thought I would never need y=Mx+c!...
Similarly, as handheld calculators were just becoming mainstream as I left school, I never thought I'd need to understand or have to use logarithms every again. Then, about 25 years later, something I encountered in my job meant that understanding logarithms was a real advantage and that it meant I could make Excel do stuff others couldn't do, which further cemented the impression my colleagues had of me as a genius with Excel.

If only they knew I was actually standing on the shoulders of the giants that inhabited the version of The Lounge that existed back in the early 2000s. Those of you who remember those days, please take a bow, you have my undying gratitude.

Ken

User avatar
Graeme
Cosmic Lounger
Posts: 1230
Joined: 11 Feb 2010, 12:23
Location: Medway, Kent, UK

Re: Sums

Post by Graeme »

Same as that on the gratitude front. Between projects at work, a few years ago, I put an Access database together. A few people knew how to run a query but nobody was designing user input forms, reports and multiuser databases. I told people about the Lounge and how Hans showed me the way at every step but they still had me down as the Access expert!
_______________________________________

http://www.averywayobservatory.co.uk/

User avatar
HansV
Administrator
Posts: 78474
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Sums

Post by HansV »

Ah - who did we have in those days in the Excel forum? Legare Coleman, Steve Aprahamian (sdckapr), and of course Rory Abernathy (rory) and Jan Karel Pieterse...
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78474
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Sums

Post by HansV »

And in Access Charlotte Foust (charlotte) - I learned a lot from her - Wendell Bell, Mark Liquorman, ...
Best wishes,
Hans

User avatar
stuck
Panoramic Lounger
Posts: 8176
Joined: 25 Jan 2010, 09:09
Location: retirement

Re: Sums

Post by stuck »

HansV wrote:
29 Jan 2023, 19:30
Ah - who did we have in those days in the Excel forum? Legare Coleman, Steve Aprahamian (sdckapr), and of course Rory Abernathy (rory) and Jan Karel Pieterse...
:yep: All names I recognise :hailpraise:

My discovery of Jan Karel's 'Name Manager' Excel Add-in was a game changer for me.

Ken

User avatar
Graeme
Cosmic Lounger
Posts: 1230
Joined: 11 Feb 2010, 12:23
Location: Medway, Kent, UK

Re: Sums

Post by Graeme »

Code written and debugged, sensor, servos and power supply plugged into breadboard, LEDs to represent levels of Temperature and Humidity added. Connection wires plugged into the Arduino.

Then the sensor packed up and reported a read error!!!

It's not the end of the world, DHT11 sensors are only couple of quid on Ebay and the Observatory build is not yet at the stage of needing environmental control. I know the Arduino is used as a kids programming teaching tool but I'm enjoying playing with it! I studied electronics as part of my HNC but my job of work has always been HV so I've not used what I learnt back then!
_______________________________________

http://www.averywayobservatory.co.uk/