Control servo connected to arduino over serial communication

Ok so i have setup a home automation system with relay, pir motion sensor and touch panel. Now i want to add a dimmer which actually is a servo screwed to a fan regulator. So i was trying a way to send servo angle feom openhab to the arduino ober serial. But i am not able to figure out how. I tried using the serial bbinding. But i could not send numeric data i dnt knw why. I wld appreciate any hlp here. Basically i want opehab to send a numeric digit which will be the angle of servo to the arduino…

The binding’s wiki shows this example:

Number Temperature        "My Temp. Sensor"    (Weather)       { serial="/dev/ttyS1@115200,REGEX(ID:2.*,T:([0-9.]*))" } 

This is an incoming data. You should be able to drop the REGEX and any Number you sendCommand to should go out over the serial bus as a number.

If not you may need to use Base64 encoding and a String Item. See the wiki page for details.

Yeah but i want some answer thats more detailed. I mean what i have to do… Do i need to set a rule or sometime…

If all you are doing is sending a number all you need to do is set up the Item as a Number and and value that gets sent to it either in a Rule or from the Sitemap will be published over the serial bus.

Ok i’m explaining the basic design. So i have a touch switch panel with a arduino controlling it. The same will be controlling the servo. So i need openhab to send a digit to arduino as a angle whever i give command from app. And i want the arduino to send back the servo angle to openhab when i click the speed button on the panel so that it can be updated in the app. So now help me with this coding part here

I’m no expert with serial and I’m really no expert with Arduino. Given that, this is how I would approach it.

Assuming that the Arduino publishes the status over the same serial port all you need to do is define the Number Item.

Number MyItemName "My Item Label [%d]" <icon> { serial="/dev/port@baud" }

Where you replace:

  • MyItemName with your desired Item name
  • My Item Label with your desired sitemap label
  • icon with your desired icon name
  • /dev/port with the path to your serial device
  • baud with the baud rate of your serial connection