Sinchan0009
Published © GPL3+

TV Antenna Rotator Using Cayenne

In this project, I will create a rotator for TV antenna, because in my area, TV signal reception is very dependent on antenna direction.

BeginnerShowcase (no instructions)1 hour1,171
TV Antenna Rotator Using Cayenne

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
Servos (Tower Pro MG996R)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Cayenne
myDevices Cayenne

Story

Read more

Schematics

servo circuit.JPG

Code

SERVO_ANTENNA.ino

C/C++
    /*
Cayenne Servo Motor Example

This sketch sample file shows how to connect a Servo Motor with Cayenne Library.
For this example we are going to use a slider widget and the servo will move
depending on the slider value.

The Cayenne Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.

Steps:
1. Install the Servo library from the Arduino Library Manager.
2. In the Cayenne Dashboard add a new Custom Widget, and select Slider.
3. Select a Virtual pin number.
4. Set min value to 0 and max value of 1.
5. Set SERVO_VIRTUAL_PIN to the pin number you selected.
6. Connect the Servo's legs to GND, VCC (5.0), and a Digital pin.
7. Set SERVO_DIGITAL_PIN to the pin number you selected.
8. Set the token variable to match the Arduino token from the Dashboard.
9. Compile and upload this sketch.
10. Once the Arduino connects to the Dashboard you can use the slider to change servo position.
*/
#include "CayenneDefines.h"
#include "CayenneWiFi.h"
#include "CayenneWiFiClient.h"
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#define SERVO_VIRTUAL_PIN 9
#define SERVO_DIGITAL_PIN 4

// servo util lib
#include <Servo.h>
Servo s1;

// a flag to keep track of servos last position
double lastPosition = 0;

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "";
char ssid[] = ""; // fill with your SSID
char pwd[] = ""; // fill with SSID password

void setup()
{
  Serial.begin(115200);
  Cayenne.begin(token, ssid, pwd);

  s1.attach(SERVO_DIGITAL_PIN);
}

CAYENNE_IN(SERVO_VIRTUAL_PIN)
{
  // get value sent from dashboard
  int currentValue = getValue.asInt();
  int position = currentValue;
  // actually move the servo to the specified position
  s1.write(position);

  //update last position
  lastPosition = currentValue;
}

void loop()
{
  Cayenne.run();
}

Credits

Sinchan0009

Sinchan0009

5 projects • 5 followers

Comments