Authorized Online Retailers:
in this lesson, we’ll show how to control the servo motor remotely through Cayenn IOT platform.
2 Hardware Preparation
|Ethernet Shield W5100||1|
|Servo motor SG90||1|
3 Hareware connection
Connect the servo motor SG90 with UNO as following diagram:
There is a known bug with the slider when a device is added using Arduino, in this case from the dashboard it looks like the device is not online.
In this project, we need to add a new device using Bring Your Own Thing and then add a slider widget to control the servo.
Click the Bring Your Own Thing button and you will find your Cayenne authentication info as below:
Copy & paste this sketch code into Arduino IDE, edit the code line:
char username = "MQTT_USERNAME"; char password = "MQTT_PASSWORD"; char clientID = "CLIENT_ID";
Replace the Cayenne authentication info with your own, then select Sketch > Upload to compile and upload the sketch into Arduino UNO board.As soon as your Arduino device comes online and connects to Cayenne, you will see your Arduino Board in the online dashboard.
4 Add new Device
Choose: Custom Widget->”Slider”
You will see the setting box as below:
Please note: If V7 pin was used by other widgets, you can select other pins. and change the VIRTUAL PIN in sketch to the pin number you have selected.
In you dashboard, click”Step 1:Sketch File”, the sample sketch will be displayed,copy and paste the sketch into Arduino IDE.
Open Arduino IDE, find the code "getValue.asDouble() * 180" . change to"getValue.asDouble() * 1 "
// Determine angle to set the servo. int position = getValue.asDouble() * 180;
// Determine angle to set the servo. int position = getValue.asDouble() * 1;
Choose the Board type Arduino Uno and correct Port, remember to use your authentication token. upload the sketch to Uno board, in your Cayenne dashboard click”Step 2 :Add Actuators” then you should see the Servo Motor was added on your dashboard:
Now, no matter where you are, you can control the servo motor by clicking the slider icon from your smartphone or web browser. However, you can only make the servo motor moved around between 0 and 180 degrees(move to 0 degree position or 180 degree postion), now let's make it more interesting.
Go to Cayenne dashboard, click the SG90 servo motor setting button, Set the slider max value as 180.
Now you can make the servo motor move to specific position, the servo will move depending on the slider value.
DownLoad Url osoyoo.com