I got stuck trying to wirelessly control 1 servo (eventually 2 servos) and 1 DC-motor.
I got 2 servos wireless control working and 1 DC-motor wireless control. But when I try to combine the two it doesn't work. Any tips?
Not working transmitter code 1 servo, 1 DC-motor:
#include <SPI.h> //the communication interface with the modem
#include "RF24.h" //the library which helps us to control the radio modem
int motor_Pin = A2; // connects to analoge pin A2, dc-motor
int msg_Pin = A0; // connects to analoge pin A0
int msg[2]; // creates an array of 2, holding data of both potmeters
RF24 radio(5,10); //5 and 10 are a digital pin numbers to which signals CE and CSN are connected.
const uint64_t pipe = 0xE8E8F0F0E1LL; //the address of the modem, that will receive data from Arduino.
void setup(void){
radio.begin(); //it activates the modem.
radio.openWritingPipe(pipe); //sets the address of the receiver to which the program will send data.
}
void loop(void){
// writes data in the array &maps input over 180 degrees
msg[0] = map (analogRead(motor_Pin), 0, 1023, 0, 255);
msg[1] = map (analogRead(msg_Pin), 0, 1023, 0, 180);
radio.write(&msg, sizeof(msg));
}
Not working receiver code 1 servo, 1 DC-motor:
#include <Servo.h> //the library which helps us to control the servo motor
#include <SPI.h> //the communication interface with the modem
#include "RF24.h" //the library which helps us to control the radio modem
int motorPin = 9; //define motorname
Servo myServo; //define the servo name
RF24 radio(5, 10); /*This object represents a modem connected to the Arduino.
Arguments 5 and 10 are a digital pin numbers to which signals
CE and CSN are connected.*/
const uint64_t pipe = 0xE8E8F0F0E1LL; //the address of the modem,that will receive data from the Arduino.
int msg[2];
void setup() {
myServo.attach(3); //3 is a digital pin to which servo signal connected
pinMode(motorPin, OUTPUT);
radio.begin(); //it activates the modem.
radio.openReadingPipe(1, pipe); //determines the address of our modem which receive data.
radio.startListening(); //enable receiving data via modem
}
void loop(){
if(radio.available()){ //checks whether any data have arrived at the address of the modem
radio.read(&msg, sizeof(msg));
analogWrite(motorPin, msg[0]);
myServo.write(msg[1]);
}
}
//}
(Working) transmitter code 2 servos:
#include <SPI.h> //the communication interface with the modem
#include "RF24.h" //the library which helps us to control the radio modem
int msg_Pin = A0; // connects to analoge pin A1
int msgTwo_Pin = A1;; // connects to analoge pin A1
int msg[2]; // creates an array of 2, holding data of both potmeters
RF24 radio(5,10); //5 and 10 are a digital pin numbers to which signals CE and CSN are connected.
const uint64_t pipe = 0xE8E8F0F0E1LL; //the address of the modem, that will receive data from Arduino.
void setup(void){
radio.begin(); //it activates the modem.
radio.openWritingPipe(pipe); //sets the address of the receiver to which the program will send data.
}
void loop(void){
// writes data in the array &maps input over 180 degrees
msg[0] = map (analogRead(msg_Pin), 0, 1023, 0, 180);
msg[1] = map (analogRead(msgTwo_Pin), 0, 1023, 0, 180);
radio.write(&msg, sizeof(msg));
}
(Working) receiver code 2 servos:
#include <Servo.h> //the library which helps us to control the servo motor
#include <SPI.h> //the communication interface with the modem
#include "RF24.h" //the library which helps us to control the radio modem
Servo myServo; //define the servo name
Servo myServoTwo; //define the servo name
RF24 radio(5, 10); /*This object represents a modem connected to the Arduino.
Arguments 5 and 10 are a digital pin numbers to which signals
CE and CSN are connected.*/
const uint64_t pipe = 0xE8E8F0F0E1LL; //the address of the modem,that will receive data from the Arduino.
int msg[2];
void setup() {
myServo.attach(3); //3 is a digital pin to which servo signal connected
myServoTwo.attach(6); //6 is a digital pin to which servo signal connected
radio.begin(); //it activates the modem.
radio.openReadingPipe(1, pipe); //determines the address of our modem which receive data.
radio.startListening(); //enable receiving data via modem
}
void loop(){
if(radio.available()){ //checks whether any data have arrived at the address of the modem
radio.read(&msg, sizeof(msg));
myServo.write(msg[1]);
myServoTwo.write(msg[0]);
}
}
//}
(Working) transmitter code 1 DC-motor:
#include <SPI.h> //the communication interface with the modem
#include "RF24.h" //the library which helps us to control the radio modem
int msgThree_Pin = A2; // connects to analoge pin A2, dc-motor
int msg[1]; // creates an array of 1, holding data of more potmeters, when larger
RF24 radio(5,10); //5 and 10 are a digital pin numbers to which signals CE and CSN are connected.
const uint64_t pipe = 0xE8E8F0F0E1LL; //the address of the modem, that will receive data from Arduino.
void setup(void){
radio.begin(); //it activates the modem.
radio.openWritingPipe(pipe); //sets the address of the receiver to which the program will send data.
}
void loop(void){
msg[0] = map (analogRead(msgThree_Pin), 0, 1023, 0, 255);
radio.write(&msg, sizeof(msg));
}
(Working) receiver code 1 DC-motor:
#include <Servo.h> //the library which helps us to control the servo motor
#include <SPI.h> //the communication interface with the modem
#include "RF24.h" //the library which helps us to control the radio modem
int motorPin = 9; //define motorname
RF24 radio(5, 10); /*This object represents a modem connected to the Arduino.
Arguments 5 and 10 are a digital pin numbers to which signals
CE and CSN are connected.*/
const uint64_t pipe = 0xE8E8F0F0E1LL; //the address of the modem,that will receive data from the Arduino.
int msg[1];
void setup() {
pinMode(motorPin, OUTPUT);
radio.begin(); //it activates the modem.
radio.openReadingPipe(1, pipe); //determines the address of our modem which receive data.
radio.startListening(); //enable receiving data via modem
}
void loop(){
if(radio.available()){ //checks whether any data have arrived at the address of the modem
radio.read(&msg, sizeof(msg));
analogWrite(motorPin, msg[0]);
}
}
//}