I was going to control a servo with RF Link Transmitter - 315MHz and a RF Link 2400bps Receiver - 315MHz. The transmitter circuit has the transmitter a button and an arduino uno and the reciever circuit has the reciever and servo and another arduino uno. What i want it to do is when i press the button the servo turns left from 90° to 0° and when i press it again it turns right from 0° to 90°. I have the codes for the transmitter arduino and the reciever arduino board. What do i add the the reciever and servo arduino to do this?
Search the Playground, there are many Servo examples, such as
http://playground.arduino.cc/ComponentLib/servo
Then look for a message to be received, and turn the servo left or right based on your message.
Some simple toggle code you can test with a servo attached on the tx uno. If that works, then you might add sending the servo position (or a single character) to the rx uno to position the servo there.
//zoomkat servo button toggle test 4-28-2012
#include <Servo.h>
int button = 5; //button pin, connect to ground to move servo
int press = 0;
Servo servo;
boolean toggle = true;
void setup()
{
pinMode(button, INPUT); //arduino monitor pin state
servo.attach(7); //pin for servo control signal
digitalWrite(5, HIGH); //enable pullups to make pin high
}
void loop()
{
press = digitalRead(button);
if (press == LOW)
{
if(toggle)
{
servo.write(160);
toggle = !toggle;
}
else
{
servo.write(20);
toggle = !toggle;
}
}
delay(500); //delay for debounce
}
What would be the schematic for that code?
What is a simple code for a 433MHz transmitter and receiver?
Virtual Wire Found here with a simple Google search... Don't you wish you knew him too?
http://www.airspayce.com/mikem/arduino/VirtualWire.pdf and the code and examples are here http://www.airspayce.com/mikem/arduino/
Can i use any type of transmitter or receiver that is 433mhz also would it go along with the example codes found in the last reply link?
Can i use any type of transmitter or receiver that is 433mhz also would it go along with the example codes found in the last reply link?
What you can, and should, use, is some punctuation, so that question makes sense.
I was going to use a rf transmitter and receiver that is 433mhz. Are there any differences in other models of transmitters and receivers that is 433mhz?
I got this code for the transmitter and i got a few errors. Somebody try to verify this code and see what you get?
//Transmitter Code
#include <VirtualWire.h>
void setup()
{
Serial.begin(9600);
vw_setup(2000);
vw_set_tx_pin(7);
}
void loop()
{
if(Serial.available())
{
char c = Serial.read();
if(c == '1')
{
vw_send((unit8_t *)c, 1);
}
else if(c == '0')
{
vw_send((unit8_t *)c, 1);
}
}
}
Here are my errors.
In file included from sketch_apr09b.ino:2:
C:\Documents and
Settings\Allan\Desktop\arduino-1.0.4\libraries\VirtualWire/VirtualW
ire.h:59: error: variable or field ‘vw_set_tx_pin’ declared void
C:\Documents and
Settings\Allan\Desktop\arduino-1.0.4\libraries\VirtualWire/VirtualW
ire.h:59: error: ‘unit8_t’ was not declared in this scope
C:\Documents and
Settings\Allan\Desktop\arduino-1.0.4\libraries\VirtualWire/VirtualW
ire.h:63: error: variable or field ‘vw_set_rx_pin’ declared void
C:\Documents and
Settings\Allan\Desktop\arduino-1.0.4\libraries\VirtualWire/VirtualW
ire.h:63: error: ‘unit8_t’ was not declared in this scope
C:\Documents and
Settings\Allan\Desktop\arduino-1.0.4\libraries\VirtualWire/VirtualW
ire.h:67: error: variable or field ‘vw_set_ptt_pin’ declared void
C:\Documents and
Settings\Allan\Desktop\arduino-1.0.4\libraries\VirtualWire/VirtualW
ire.h:67: error: ‘unit8_t’ was not declared in this scope
C:\Documents and
Settings\Allan\Desktop\arduino-1.0.4\libraries\VirtualWire/VirtualW
ire.h:71: error: variable or field ‘vw_set_ptt_inverted’ declared
void
C:\Documents and
Settings\Allan\Desktop\arduino-1.0.4\libraries\VirtualWire/VirtualW
ire.h:71: error: ‘unit8_t’ was not declared in this scope
C:\Documents and
Settings\Allan\Desktop\arduino-1.0.4\libraries\VirtualWire/VirtualW
ire.h:76: error: variable or field ‘vw_setup’ declared void
C:\Documents and
Settings\Allan\Desktop\arduino-1.0.4\libraries\VirtualWire/VirtualW
ire.h:76: error: ‘unit16_t’ was not declared in this scope
C:\Documents and
Settings\Allan\Desktop\arduino-1.0.4\libraries\VirtualWire/VirtualW
ire.h:90: error: ‘unit8_t’ does not name a type
C:\Documents and
Settings\Allan\Desktop\arduino-1.0.4\libraries\VirtualWire/VirtualW
ire.h:98: error: ‘unit8_t’ does not name a type
C:\Documents and
Settings\Allan\Desktop\arduino-1.0.4\libraries\VirtualWire/VirtualW
ire.h:104: error: ‘unit8_t’ does not name a type
C:\Documents and
Settings\Allan\Desktop\arduino-1.0.4\libraries\VirtualWire/VirtualW
ire.h:107: error ‘unit8_t’ does not name a type
C:\Documents and
Settings\Allan\Desktop\arduino-1.0.4\libraries\VirtualWire/VirtualW
ire.h:112: error: ‘unit8_t’ does not name a type
sketch_apr09b.ino: In function ‘void setup()’:
sketch_apr09b:8: error: ‘vw_setup’ was not declared in this scope
sketch_apr09b:9: error: ‘vw_set_tx_pin’ was not declared in this
scope
sketch_apr09b.ino: In function ‘void loop()’:
sketch_apr09b:20: error: ‘unit8_t’ was not declared in this scope
sketch_apr09b:20: error: expected primary-expression before ‘)’
token
sketch_apr09b:20: error: ‘vw_send’ was not declared in this scope
sketch_apr09b:24: error: ‘unit8_t’ was not declared in this scope
sketch_apr09b:24: error: expected primary-expression before ‘)’
token
sketch_apr09b:24: error: ‘vw_send’ was not declared in this scope
vw_send((unit8_t *)c, 1);
I'm pretty sure that unsigned, 8 bit, nit is not a valid type. And, you know, the compiler agrees with me.
C:\Documents and
Settings\Allan\Desktop\arduino-1.0.4\libraries\VirtualWire/VirtualW
ire.h
My version of 1.0.4 didn't come with VirtualWire as a core library. I'm positive yours didn't either. That means that you downloaded some (incorrect) version of the VirtualWire library and installed it in the wrong place. I can say that because when I change your nits to ints, I get this when I compile your code:
Binary sketch size: 3,532 bytes (of a 30,720 byte maximum)
What us the proper way to download libraries to the arduino program?
There are two places that the IDE looks for libraries. One is the core libraries folder.
On my system, that is C:\Users<userid>\Documents\arduino-1.0.4\libraries.
The other is the user's libraries folder, where user-downloaded libraries go.
On my system, that is C:\Users<userid>\Documents\Arduino\libraries. Sketches are stored relative to the parent of this directory (C:\Users<userid>\Documents\Arduino).
The advantage of downloading user libraries correctly is that they will still be available with 1.0.5, 1.0.6, 1.5.2, 2.0.0, etc.
If you don't have a libraries folder in the folder where you store your sketches, create one.
When I downloaded the virtualwire library I opened the folder of it that was in the downloads folder and extracted all files to the libraries in the arduino program folder. Is that right?
Is that right?
No. VirtualWire is not a core library, or you would not have needed to download it. Look at my previous reply.
When I create my library folder where in the arduino program folder do I put it?
When I create my library folder where in the arduino program folder do I put it?
You don't. You put it in your SKETCH folder. The Arduino program folder should be read-only. Stay out of it.
How do i get to the sketch folder and put the virtualwire folder in it?
I extracted all the files from virtualWire to my libraries folder where i keep my sketchs. When i went to comply my code it still had problems. What did i do wrong?
I finally got the code to comply. Now what i wanted to do is add this servo code
#include <Servo.h>
int button = 5; //button pin, connect to ground to move servo
int press = 0;
Servo servo;
boolean toggle = true;
void setup()
{
pinMode(button, INPUT); //arduino monitor pin state
servo.attach(7); //pin for servo control signal
digitalWrite(5, HIGH); //enable pullups to make pin high
}
void loop()
{
press = digitalRead(button);
if (press == LOW)
{
if(toggle)
{
servo.write(160);
toggle = !toggle;
}
else
{
servo.write(20);
toggle = !toggle;
}
}
delay(500); //delay for debounce
}
along with a simple receiver code to be meshed together. What would that look like?