Author Topic: Controlling a servo  (Read 6926 times)

Online Cor

  • Hero Member
  • *****
  • Posts: 1248
  • Karma: +8/-4
Controlling a servo
« on: April 17, 2014, 03:35:54 pm »
Very interesting this Arduino option :-)   Time to build one.

Objective: controll via the servo a thermostate for my floorheating.


The thermostate is in the basement and the vera3 ( UI5 version 622) is about 15 meters away with one concrete wall in line of sight . There are some zwave devices near that thermostate , so the mesh network for Zwave devices is quite good.

Do I understand correctly with this radio "nRF24L01+. "  it is not a zwave radio ?  So to be able to use the servo wirelesly, I need 2 arduino's , one as a gateway , and the second one for the servo?

Or when I get a ethernet cable to my basement , I need 1 arduino ( and the servo) .

Second question for now, how do I controll the servo via the GUI , can I insert a number in degrees and the servo will turn that amount degrees? Will I be able to use it in PLEG?

I will post a full report offcourse in this thread.

Thanks,
Cor





Offline rosskinard

  • Jr. Member
  • **
  • Posts: 75
  • Karma: +3/-0
Re: Controlling a servo
« Reply #1 on: April 17, 2014, 06:51:27 pm »
You might be better off getting a Z-Wave capable thermostat instead. Would be much more precise then trying to calibrate a servo and all...creating a mechanical way of moving it means parts could slip and you might have the system turned on way to high or too low...anything that generates HEAT needs to be very solid in its controls.

And to answer you question, yes you would need an Arduino for the gateway and one for the thermostat. And if you use RF then you would be covering the distance between the Vera and the thermostat unless you made a relay node or sensor, costing another Arduino.

Plus a servo controlled thermostat won't give you FAN and ON/OFF control like a full blown digital thermostat would either.

Just my thoughts...I want to create a servo control for one of my curtain sets in the living room...20 foot ceilings in there and the 2nd window set is about 12 feet up, so I want that controllable. Just got a few test motors in today and will be tinkering with it this weekend.

Online Cor

  • Hero Member
  • *****
  • Posts: 1248
  • Karma: +8/-4
Re: Controlling a servo
« Reply #2 on: April 17, 2014, 10:57:15 pm »
@ Rokskinard: I need to mention it is for a floorheating, the pickup which senses the temperature senses the temperature of the water inside the " floorheating pump device"  I allready demolished a danfoss thermostate trying to get the temperature sensor outside the casing. That didn't work. That would indeed be the best, but unfortunately. I need only about 3 to 4 settings on the thermostate. The idea is ,I can somehow set a setting for 20 degrees ,30 degrees , 40 degrees and 50 degrees of rotation I don't want vera to controll the temperature itself , the thromostate itself does a very good job.

This is the thermostate which can not be modified:
http://www.modelbouwforum.nl/forums/members/corvl-albums-diversen-picture123934-1.jpg

Don't worry about the connection between servo and thermostate , got all the tools like cnc-router, mill in the house to make something appropriate.


It would be nice if you show your progress of the whole project on this forum.

Thanks,
Cor

« Last Edit: April 18, 2014, 01:19:15 am by Cor »

Offline BulldogLowell

  • Hero Member
  • *****
  • Posts: 1576
  • Karma: +191/-85
Re: Controlling a servo
« Reply #3 on: April 17, 2014, 11:10:34 pm »
I'd search through the blinds posts on arduino, lots of good stuff in there, people rotating servos to tilt blinds, a similar application to yours (albeit you seem to need a good servo with plenty of torque).

Don't forget Hek's MySensors for more help.

I wish I had all those nice tools ;)


Offline integlikewhoa

  • Master Member
  • *******
  • Posts: 5630
  • Karma: +157/-382
Re: Controlling a servo
« Reply #4 on: April 17, 2014, 11:37:29 pm »
@ Rokskinard: I need to mention it is for a floorheating, the pickup which senses the temperature senses the temperature of the water inside the " floorheating pump device"  I allready demolished a danfoss thermostate trying to get the temperature sensor outside the casing. That didn't work.

So why not use a thermostat that has external inputs for temp sensors?

I have 7 TZEMT500BB32MA which have an internal temp, or 2 aux inputs for external sensors. With the external sensors you can adv. the 2 or use one.
89.00 on ebay and I bought External sensors 5 for like 10.00 also on ebay.

http://www.ebay.com/itm/Trane-Z-Wave-thermostat-Schlage-Link-Nexia-TZEMT500BB32MA-New-89-00-/271395379920?pt=LH_DefaultDomain_0&hash=item3f306cdad0

Online Cor

  • Hero Member
  • *****
  • Posts: 1248
  • Karma: +8/-4
Re: Controlling a servo
« Reply #5 on: April 18, 2014, 12:03:46 am »
@Bulldoglowell: The "MySensors" website gave me the idea and now I am very curious , this whole arduino thing gives an enormous amount of extra possibities. As a (bigscale) model airplane builder, enough servomotors and tools  here :-)

@integlikewhoa: That would be ideal indeed, although I haven't seen them for the european market.  Also I see there is a controll panel on that ebay website ?? I would just need a thermostate , like these: http://www.betaalbare-domotica.nl/verwarming-en-airco/danfoss-radiator-thermostaat.html I allready got 3 of them and they work fine together with my vera.  Unfortunately not an external input possible.

Cor
« Last Edit: April 18, 2014, 01:19:48 am by Cor »

Online Cor

  • Hero Member
  • *****
  • Posts: 1248
  • Karma: +8/-4
Re: Controlling a servo
« Reply #6 on: April 18, 2014, 12:50:37 am »
The shoppinglist  , before I order ,anything I missed or I need to add?

-vera3: already got one
-arduino UNO, that one will be the gateway : got one allready
-arduino nano: http://www.ebay.com/itm/130977189883 to be ordered.
- 2x wireless device: http://www.ebay.com/itm/310781092103 I took this one instead of the cheaper on since it has an external antenna and according specs better distance can be covered.
-Servo: got different ones at home to try
-USB cable to connect gateway (arduino uno) to Vera3 : got one allready
-USB cable to programm arduino nano:http://www.ebay.com/itm/Short-OTG-Female-Mini-5-pin-Male-to-USB-Female-Adapter-Extension-Cable-BEST-/171285731771?pt=US_Audio_Cables_Adapters&hash=item27e16cd9bb
-Step down regulators ( from 5V to 3.3V) to connect the wireless device to the arduino: http://www.ebay.com/itm/291116711292
-cables female to female: http://www.ebay.com/itm/291044306717
-cables male to female: http://www.ebay.com/itm/181210714633
-cables male to male: got some allready.
-capacitor for the radio part: http://www.ebay.com/itm/181210714633

I think that's it to build the device.

Anyone who can also tell me how I will be able to controll this servo via the vera 3 , do I have to insert degrees in the UI ? how that does work?

Thanks,
Cor


Offline integlikewhoa

  • Master Member
  • *******
  • Posts: 5630
  • Karma: +157/-382
Re: Controlling a servo
« Reply #7 on: April 18, 2014, 01:27:01 am »
@integlikewhoa: That would be ideal indeed, although I haven't seen them for the european market.  Also I see there is a controll panel on that ebay website ?? I would just need a thermostate , like these: http://www.betaalbare-domotica.nl/verwarming-en-airco/danfoss-radiator-thermostaat.html I allready got 3 of them and they work fine together with my vera.  Unfortunately not an external input possible.

Cor

Your probley right, I don't know much of anything about the European market. Isn't your z-wave a different frequency too?

That thing you call a control panel is what we call in USA a thermostat. It hangs on the wall in the house. Has built in temp and humity sensor (this one also has external inputs but not all do) has 2 buttons to set what temp you want. Yes it has alot of options if you want them. Set which days it on which days its off and what times and such. Always displays current temp and humidity and time on its screen. Press the button to change the set points.  The price looks to be close to the one you linked when I did a conversion to Euro. 57.00 Euro is 80.00 US $ 

Online Cor

  • Hero Member
  • *****
  • Posts: 1248
  • Karma: +8/-4
Re: Controlling a servo
« Reply #8 on: April 18, 2014, 01:48:59 am »
@ integlikewhoa .... ahhh, I need the thing which is attached to the valvle , and yes , europe has another frequency.

Cor

Online Cor

  • Hero Member
  • *****
  • Posts: 1248
  • Karma: +8/-4
Re: Controlling a servo
« Reply #9 on: November 14, 2014, 03:10:13 pm »
Yes ...... half a year later , and finally I made some time to make this.

This night I finally made some time to build a gateway and a device to use a servo.
The only issues I had was finding drivers to programm the nano and the uno ( I use the uno for the servo).

Now , there is 1 issue. The servo only turns max 90 degrees. I uploaded the sketch without changing anything.
http://www.mysensors.org/build/servo

It should to a full 180 degrees I think ? it is a standard futaba S3001.
The servo is good ( I checked with my RC transmitter and reciever)

Anyone has an idea how to troubleshoot?

Pictures will follow when I hook it up with my thermostat.

*edit* ... oh ... that's wierd... when I use the slider or open-close , it does the 90 degrees. but when I click up-down, it does full 180 degrees ...... why not with the slider??

thanks,
Cor
« Last Edit: November 14, 2014, 03:25:07 pm by Cor »

Online Cor

  • Hero Member
  • *****
  • Posts: 1248
  • Karma: +8/-4
Re: Controlling a servo
« Reply #10 on: November 17, 2014, 09:44:16 am »
Yesterday I started building a bracket for the servo to attach to the thermostat.
I will post some pictures next week when all is finished.

An issue with controlling the servo though , I hope someone can help, attached a screemshot what I have on the UI.

When I use the slider  or close-open , the max servo range of movement is 90 degrees.
When I click up-down , I have a full 180 degrees of movement.

I need to use the servo with a thermostate , so I will create scenes when scene "20 degrees" moves the slider to a setting which correspondents with "temperature 20 degrees C" .... and so on.


Anyone knows how to change this sketch so the slider can use the full 180 degrees like the "up down"- button  instead of the 90-ish degrees it does now?

Thanks,
Cor

Code: [Select]
// Example showing how to create an atuator for a servo.
// Connect red to +5V, Black or brown to GND and the last cable to Digital pin 3.
// The servo consumes much power and should probably have its own powersource.'
// The arduino might spontanally restart if too much power is used (happend
// to me when servo tried to pass the extreme positions = full load).
// Contribution by: Derek Macias


#include <MySensor.h>
#include <SPI.h>
#include <Servo.h>

#define SERVO_DIGITAL_OUT_PIN 3
#define SERVO_MIN 0 // Fine tune your servos min. 0-180
#define SERVO_MAX 180  // Fine tune your servos max. 0-180
#define DETACH_DELAY 900 // Tune this to let your movement finish before detaching the servo
#define CHILD_ID 10   // Id of the sensor child

MySensor gw;
MyMessage msg(CHILD_ID, V_DIMMER);
Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created Sensor gw(9,10);
unsigned long timeOfLastChange = 0;
bool attachedServo = false;
           
void setup()
{
  // Attach method for incoming messages
  gw.begin(incomingMessage);

  // Send the sketch version information to the gateway and Controller
  gw.sendSketchInfo("Servo", "1.0");

  // Register all sensors to gw (they will be created as child devices)
  gw.present(CHILD_ID, S_COVER);

  // Request last servo state at startup
  gw.request(CHILD_ID, V_DIMMER);
}

void loop()
{
  gw.process();
  if (attachedServo && millis() - timeOfLastChange > DETACH_DELAY) {
     myservo.detach();
     attachedServo = false;
  }
}

void incomingMessage(const MyMessage &message) {
  myservo.attach(SERVO_DIGITAL_OUT_PIN);   
  attachedServo = true;
  if (message.type==V_DIMMER) { // This could be M_ACK_VARIABLE or M_SET_VARIABLE
     int val = message.getInt();
     myservo.write(SERVO_MAX + (SERVO_MIN-SERVO_MAX)/100 * val); // sets the servo position 0-180
     // Write some debug info
     Serial.print("Servo changed. new state: ");
     Serial.println(val);
   } else if (message.type==V_UP) {
     Serial.println("Servo UP command");
     myservo.write(SERVO_MIN);
     gw.send(msg.set(100));
   } else if (message.type==V_DOWN) {
     Serial.println("Servo DOWN command");
     myservo.write(SERVO_MAX);
     gw.send(msg.set(0));
   } else if (message.type==V_STOP) {
     Serial.println("Servo STOP command");
     myservo.detach();
     attachedServo = false;

   }
   timeOfLastChange = millis();
}




Offline cotejean

  • Newbie
  • *
  • Posts: 5
  • Karma: +1/-0
Re: Controlling a servo
« Reply #11 on: November 17, 2014, 01:32:19 pm »
Hello Cor,

I ran in the same problem. I fixed it by replacing the line:

   myservo.write(SERVO_MAX + (SERVO_MIN-SERVO_MAX)/100 * val); // sets the servo position 0-180

by the following 2 lines of code:

        val = map(val, 0, 100, 0, 180); // scale 0%-100% between 0 and 180)
        myservo.write(val);       // sets the servo position 0-180

Online Cor

  • Hero Member
  • *****
  • Posts: 1248
  • Karma: +8/-4
Re: Controlling a servo
« Reply #12 on: November 18, 2014, 04:12:27 am »
@ Cotejean:

That's awesome!    next week I will be home and change the sketch and try!

Do you have any idea why there would be a difference in using the slider or the up-down buttons?

One more question;
These 2 lines :
Code: [Select]
#define SERVO_MIN 0 // Fine tune your servos min. 0-180
#define SERVO_MAX 180  // Fine tune your servos max. 0-180

Does this do anything than when I change the code into your code? the finetuning I mean.
Code: [Select]
val = map(val, 0, 100, 0, 180); // scale 0%-100% between 0 and 180)
I guess when I change the 0, 180  to what I want, I can finetune in that line of code.
for example:
Code: [Select]
val = map(val, 0, 100, 20, 160); // scale 0%-100% between 20 and 160)

Thanks a lot,
Cor
« Last Edit: November 18, 2014, 04:25:30 am by Cor »

Offline cotejean

  • Newbie
  • *
  • Posts: 5
  • Karma: +1/-0
Re: Controlling a servo
« Reply #13 on: November 18, 2014, 09:59:58 am »
I think that your suggestion would work
Code: [Select]
val = map(val, 0, 100, 20, 160); // scale 0%-100% between 20 and 160)

I have the servo motor mounted to one set of blinds in the living room. (Still experimenting with the Arduino plugin).
For now I was making it open and close using 2 different  scenes and LUUP code:
To open the blinds
Code: [Select]
luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "72"}, 37)

To close the blinds
Code: [Select]
luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "17"}, 37)

Offline cotejean

  • Newbie
  • *
  • Posts: 5
  • Karma: +1/-0
Re: Controlling a servo
« Reply #14 on: November 18, 2014, 10:05:06 am »
I forgot to say that for now, in my setup,  72% is "open" and 17% is "closed". I will try to use these values in the mapping code this weekend to see how it works and I will report the results here. It would be nice to "click" open and have the servo motor go to 72% and click "close" to make it go to 17%.

(That verification process is really a pain...)