Hello!
I’m only a begginer in the arduino world. What i’m working on is a type of rc controller car which is controlled by 433MHz module, one way communication. I’ve made some code that sends the value of the position of the joystick to the arduino that is supposed to be on the car. I’ve got the position to print out on the serial monitor but i can’t take that value and assign it to a variable with which i would controll the speed of the car. At the moment i’m using Arduino mega 2560 for both ends of the build. Here is the code of the transmitter:
When i want to use the PWM for the speec control and use the buf[1] value it doesn’t work. I hear a slight buzzing sound in the motor but that’s it. I’ve also tried to assign it to a variable like so:
int powerValue = buf[0];
But that doesn’t work either.
The code may contain extra unneeded stuff because i didn’t really know how to send data via rf modules and i somehow made it work after a whole day of trying different stuff. And there was no good video on the internet explaining what i wanted to know, or they used a different module whereas mine is only one way communication.
if you want to memorize the current pwm you can use a global variable that you assign also when you get the data.
Yes i have tried to set up an integer value at the beggining at the middle and the way you suggested but sadly it doesn’t work. Also if i tried something like this:
J-M-L:
What do you see in the serial monitor with my version?
For some reason now the variable gets the value of the buf[0] but the motor still doesn’t work. I just hear a slight buzzing sound. Also i changed the transmitter arduino to Uno. The code is the same on the transmitter. Here’s my code on the receiver end:
if(vw_get_message(buf, &buflen)) {
int sp = buf[0];
analogWrite(2, sp);
Serial.println("-----------------------");
Serial.print(“SP = “);
Serial.print(sp);
Serial.print(” X = “);
Serial.print(buf[0]);
Serial.print(” Y = “);
Serial.print(buf[1]);
Serial.print(” Z = “);
Serial.println(buf[2]);
Serial.println(”-----------------------”);
} else {
Serial.println(“no data”);
delay(100);
}
}
what do you see? if you only see "no data" and never any X/Y/Z info then there is an issue with the data transmission
Ok. I have figured out what the problem is. The data is fine. When i plug the motor to the 5V and GND pins the motor starts fine. But when i plug it into PWM pin it just doesn’t want to start. So i figured that the current required to start it must be too large. Because the LEDs on the board fade out a bit when i plug it into 5V. So i figured i would get 5 PWM pins and connect them in parallel then i plugged in the motor but it still requires a kickstart to get it goin. Is there any way that i could increase the current output on the PWM pins or do i need a separate power source? Or would maybe a capacitor solve the issue? There is already one soldered on the motor but idk it doesn’t seem to solve the problem.
The pwm pin should drive a mosfet or a motor driver
You should never power a motor from an arduino pin.best way to fry your arduino…
umm… yea… didn’t know that. I don’t have a motor driver at the moment so i thought i could power a motor this way. I thought that you only needed the driver for the motor to spin in another direction.
Before i even saw you reply i watched a video on the transistor as a switch. So i took a 2N3019 NPN power transistor connected the motor to 5V and the collector, emitter to GND and the base to a PWM signal and it works as i wanted it to work now. I probably didn’t quite get the base resistor right should’ve used 58 ohm one but i used 10 ohm because i don’t have anything that is closer in value to it.
Maybe i should’ve posted how i connected the arduino at the beggining but i thought it was the code that was at fault. Lesson learned i guess.
Anyways, thanks for the help!
If you're using 433MHz for RC you are probably exceeding the allowable transmit duty cycle that is permitted in the radio regulations. Based on a typical packet transmit burst duration, you can only legally send a packet every 20-30 seconds or longer.