Hi. You may remember I was asking about the hardware. I think I have it all. Now it's the programming part. There's two units...a Teensy on a board (chosen for size, rather than power), with a motion sensor and a transmitter.
I was thinking something like this....(I copied it from someone else, made some changes)
// Include VirtualWire library
#include <VirtualWire.h>
// Define pins
const int led_pin = 13;
const int transmit_pin = 12;
const int sensor_pin = 7;
int sensor_value;
void setup()
{
// Init
vw_set_tx_pin(transmit_pin);
vw_setup(2000); // Transmission rate
pinMode(led_pin, OUTPUT);
pinMode(sensor_pin,INPUT);
}
void loop()
{
// Get sensor value
sensor_value = digitalRead(sensor_pin);
// Init message
char msg[1] = {'0'};
// Change message if motion is detected
if (sensor_value == 1){
msg[0] = '1';
}
// Transmit data every second
digitalWrite(led_pin, HIGH); // Flash a light to show transmitting
vw_send((uint8_t *)msg, 3);
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(led_pin, LOW);
delay(1000);
}
And now, for the receiver...
// Include VirtualWire library
#include <VirtualWire.h>
//And don't forget the Servo
#include <SoftwareServo.h>
SoftwearServo thisservo; //Servo object
// Pins definition
const int led_pin = 13;
const int transmit_pin = 12;
const int receive_pin = 11;
const int servo_pin = ??; //will have to get the pin number
void setup()
{
// Init
delay(1000);
Serial.begin(9600); // Debugging only
Serial.println("setup");
// Initialise the IO and ISR
vw_set_rx_pin(receive_pin);
vw_setup(2000); // Transmission rate
// Start the receiver PLL
vw_rx_start();
// Set LED pin
pinMode(led_pin, OUTPUT);
// set Servo pin
thisservo.attach(servo_pin);
// Init
delay(1000);
Serial.begin(9600); // Debugging only
Serial.println("setup");
// Initialise the IO and ISR
vw_set_rx_pin(receive_pin);
vw_setup(2000); // Transmission rate
// Start the receiver PLL
vw_rx_start();
}
void loop()
{
//sorry, how do you make a servo work? Still trying to figure what's the basic way to dictate its "forms"?
//if "1" is received, the servo turns a bit then turns back (dog food dispenser)
for(pos = 0; pos < 90; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 90; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
//if "0" is received, nothing happens
}
What do you think?
Yes, this is my first Arduino thing. Doing it for a brother.
// Include VirtualWire library
#include <VirtualWire.h>
// Define pins
const int led_pin = 13;
const int transmit_pin = 12;
const int sensor_pin = 7;
int sensor_value;
void setup()
{
// Init
vw_set_tx_pin(transmit_pin);
vw_setup(2000); // Transmission rate
pinMode(led_pin, OUTPUT);
pinMode(sensor_pin,INPUT);
}
void loop()
{
// Get sensor value
sensor_value = digitalRead(sensor_pin);
// Init message
char msg[1] = {'0'};
// Change message if motion is detected
if (sensor_value == 1){
msg[0] = '1';
}
// Transmit data every second
digitalWrite(led_pin, HIGH); // Flash a light to show transmitting
vw_send((uint8_t *)msg, 3);
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(led_pin, LOW);
delay(1000);
}
And now, for the receiver...
// Include VirtualWire library
#include <VirtualWire.h>
//And don't forget the Servo
#include <SoftwareServo.h>
SoftwearServo thisservo; //Servo object
// Pins definition
const int led_pin = 13;
const int transmit_pin = 12;
const int receive_pin = 11;
const int servo_pin = ??; //will have to get the pin number
void setup()
{
// Init
delay(1000);
Serial.begin(9600); // Debugging only
Serial.println("setup");
// Initialise the IO and ISR
vw_set_rx_pin(receive_pin);
vw_setup(2000); // Transmission rate
// Start the receiver PLL
vw_rx_start();
// Set LED pin
pinMode(led_pin, OUTPUT);
// set Servo pin
thisservo.attach(servo_pin);
// Init
delay(1000);
Serial.begin(9600); // Debugging only
Serial.println("setup");
// Initialise the IO and ISR
vw_set_rx_pin(receive_pin);
vw_setup(2000); // Transmission rate
// Start the receiver PLL
vw_rx_start();
}
void loop()
{
//sorry, how do you make a servo work? Still trying to figure what's the basic way to dictate its "forms"?
//if "1" is received, the servo turns a bit then turns back (dog food dispenser)
//if "0" is received, nothing happens
}
So how has that helped?
Answered none of my questions. You have not edited your first post to put the code into code tags you just posted it again.
Are you serious about getting help?
I modified the intial post, and.....for the first question....
?? That won't work will it?
I read that it is doable, that an Arduino may be powered either by AC adaptor, OR by USB (if I'm wrong, let me know). The "Receiver" is using a conventional Uno. The "Transmitter" is using a Teensy. The Teensy will be modified, for a special "battery pack" that's chargable via USB, since it has to be attached to the outside of a door.
When I say USB adaptor, I just mean one of those simple things you plug in with USB ports on it.
The "receiving" of data is what I need to figure out. Hence my "pseudocode" commands about 0 and 1 (that it's only a "1" that triggers the mechanism)
Are you serious about getting help?
Forgive my second post, wasn't thinking clearly when writing it. Also, doing a quick mod because I found out some way to move the servo...just need to "get it together"
Also, the initial post has been updated. Sorry, I'm a little too new to this.
When I say USB adaptor, I just mean one of those simple things you plug in with USB ports on it.
As long as you are only using it to power the thing and not expect any connections that is fine.
It is a good idea only to send the messages when you want something to happen. So send a message to open the servos and another one to close it. Don't continually send a message saying nothing has happened.