Hi.
I know probably there are many project using Tradfri “chips” controls led dimmers, but i did not find any that use them not only for lights.
So here it is: Tradfri (and arduino) as a servo motor controller (or any other devices, depends on your creativity).
Tradfri Zigbee use pwm to control brightness of leds, to use that, we need to progam arduino to counts pwm signals and check on/off status, below arduino code and short movie of proof of concept.
If you wanna use it, have fun.
byte PWM_PIN = 2; //output from transoptor
int status_on_off; // on/off check value
int pwm_value; //counted pwm signal (new)
int pwm_value_old; //counted pwm signal (old)
#include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup() {
pinMode(PWM_PIN, INPUT);
Serial.begin(115200);
myservo.attach(9); // pin 9 as servo controler
}
void loop() {
pwm_value = pulseIn(PWM_PIN, HIGH); //count pwm
pwm_value = map(pwm_value, 0, 1500, 0, 180); //map pwm to servo value
delay(100); //short delay
if (pwm_value != pwm_value_old) //check if there was a change between old and new readings
{
delay(1000); //longer delay
pwm_value = pulseIn(PWM_PIN, HIGH); //another readings to avoid jumps between statuses
pwm_value = map(pwm_value, 0, 1500, 0, 180); //another map pwm to servo value
status_on_off = digitalRead(PWM_PIN); // reading if pwm pin is high or low,
// for "full" on and off pwn will be always 0,
// so value HIGH or LOW value must be check
Serial.println(status_on_off);
if (pwm_value == 0)
{
if (status_on_off == 0)
{
Serial.println("OFF");
myservo.write(0);
}
if (status_on_off == 1)
{
Serial.println("ON");
myservo.write(180);
}
}
if (pwm_value != 0)
{
Serial.println(pwm_value);
myservo.write(pwm_value);
}
}
pwm_value_old = pwm_value;
}
Short movie: https://drive.google.com/file/d/10r6yKrR8kec0avZwcwlQ73HwqAnZaf_K/view