How to connect a 60rpm motor to cayenne

As I am using a 60 rpm motor for driving a conveyor system which has to be connected to cayenne in serial connection to ardiuno…So what is the electronic circuit I must use and how to establish a link between ardiuno,electronic circuit and cayenne dashboard?

I think a good place to start is to check out the Cayenne Arduino getting started docs.
http://mydevices.com/cayenne/docs/#getting-started-arduino

-B

sir thanks for replaying. sir can u help me in providing me an process to connect a dc motor to cayenne… i need the electronic circuit

You can use Arduino to control a DC Motor and use PWM to control the speed of the motor as you send number from 0-255.
Cayenne provides connection with motor driver of Adafruit company.

Here you can find more information about this driver:
https://learn.adafruit.com/micropython-hardware-pca9685-dc-motor-and-stepper-driver/overview

If you want to try the first approach, you will need some additional elements as transistors, resistors and etc.
Good start is to see this article:

sir thanks for providing me with above links… but my main problem is that i am using an 60 rpm motor for which the 5v dc output of ardiuno is not enough for which i am providing external voltage of 12v using and dc battery. but as in the example of sketch file we r using virtual pin to toggle the motor. so i want an exact layout diagram of mentioned above process with ardiuno and cayenne. could u help in this??

Yes,
I have made something like this before, but I did not connect it to Cayenne (it was 3 years ago). Please check it. You can use then Motor Widget to turn on/off.


Please, look at the Datasheet of the Transistor: https://cdn-shop.adafruit.com/datasheets/TIP120.pdf

sir,
thanks for this layout i was expecting this… and there is one small doubt that what is the role of declaring virtual pin V1 in the sketch file of cayenne for motor switch and how to use and connect the virtual pin to the dc motor??

You are not connecting virtual pin to the DC motor. You can connect motor to some PWM port. You use Virtual Pin with Cayenne.

This code is everything that you need to run your motor with Cayenne. Go through it:

/*
Cayenne Motor Switch Actuator Example
This sketch shows how to set up a Motor Switch with Cayenne. The Arduino cannot
drive a motor because it does not output the needed current. As a result, in order
to make this example work, various electronic components are necessary to drive
the DC motor. To keep it simple, you will need an external power source, transistor (eg. PN2222),
diode (eg. 1N4001), and a 270 ohm resistor.
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. In the Cayenne Dashboard add a Button using Custom Widget.
2. Select a virtual pin number.
3. Set VIRTUAL_PIN to the pin number you selected.
4. Set up your motor schematic and attach it to a PWM pin (3, 5, 6, 9, 10, and 11 on most Arduino boards).
5. Set the motorPin variable to the PWM pin number you selected.
6. Set the token variable to match the Arduino token from the Dashboard.
7. Compile and upload this sketch.
8. Once the Arduino connects to the Dashboard you can toggle the Motor switch.
We use the virtual pin to receive data from the dashboard to enable and disable the motor.
*/

#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space

// If you're not using the Ethernet W5100 shield, change this to match your connection type. See Communications examples.
#include <CayenneEthernet.h>

// Virtual Pin of the widget.
#define VIRTUAL_PIN V1

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "AuthenticationToken";

// motor pin
int motorPin = 3;

void setup()
{
	Serial.begin(9600);
	Cayenne.begin(token);
}

//Enable or disable the motor based on value received on virtual pin.
CAYENNE_IN(VIRTUAL_PIN)
{
  int speed = 155;
  // read the integer value which should be 0 or 1
  int enabled = getValue.asInt();
  if (enabled == 1) {
    // turns on the motor at the specified speed
    analogWrite(motorPin, speed);
  } else {
    // turn motor off
    analogWrite(motorPin, 0);
  }
}

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

oh k…so than after selecting the custom widget in the i/o which one should i must select
virtual pin or digital pin i mean the motorPin = 3; or VIRTUAL_PIN V1 ??

Motor PIN 3 or where you connect your motor is for connection with the motor. You have to select VIRTUAL PIN, it is used to receive data from the dashboard to enable and disable the motor. And please use MOTOR SWITCH which is in Actuators drop down menu. Then you will be able to enable or disable the motor based on value received on virtual pin.

Everything is quite well described in the Documentation.
@bestes already post you a link, but in case of missing it: Press Here

so there is no direct connection with virtual pin V1 and electronic dc motor circuit layout which u shared me to try?

Motor is connected to some PWM port. The virtual pin is VIRTUAL and through it, you can control the motor from the dashboard:)

The magic is here:

CAYENNE_IN(VIRTUAL_PIN)
{
  int speed = 155;
  // read the integer value which should be 0 or 1
  int enabled = getValue.asInt();
  if (enabled == 1) {
    // turns on the motor at the specified speed
    analogWrite(motorPin, speed);
  } else {
    // turn motor off
    analogWrite(motorPin, 0);
  }
}

You read the state of virtual pin (widget is connected to virtual pin) and based on this state you send to motorPin either 1 or 0. You can modify the code to fits your need. You can delete the speed line.

sir i tried with the electronic layout given by u… and uploaded the above code to ardiuno…as i am connecting the 12v the motor is getting started without any input from dash board…what to do now??

Can you send me picture.of wiring?

It is strange. Did you use DIODE, as in the picture between the two wires of the motor? What about the dashboard? Do you have widget? What happen if you toggle it ON/OFF ?

Sir i placed exactly as in layout…And without adding any control in dashboard the motor is running

and sir this is the code which i uploaded to ardiuno
#include <CayenneSerial.h>
#define VIRTUAL_PIN V2
// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token = “59lfda5thl”;
int motorPin = 9;
void setup()
{
//Baud rate can be specified by calling Cayenne.begin(token, 9600);
Cayenne.begin(token);
}
//Enable or disable the motor based on value received on virtual pin.
CAYENNE_IN (V2)
{

// read the integer value which should be 0 or 1
int enabled = getValue.asInt();
if (enabled == 1) {
// turns on the motor at the specified speed
analogWrite(motorPin,0);
} else {
// turn motor off
analogWrite(motorPin,0);
}
}

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

and sir i am using serial communication not the Ethernet or wifi shield

I have read somewhere that arduino pins are HIGH by default. Can you add control in the dashboard to investigate what will happen?