Thursday, May 6, 2010

Tasks 45 - 50

45)Explore the way your infrared transmitter sends pulses to the receiver. Set up a little demonstration to be marked in class. You may share this project with another person but both members have to know what's going on. Transmission from one Arduino to another is especially excellent.

Had done this - just completely forgot to upload the photo and describe it.

For this task I decided to use the blink program. This would light up the sending IR led so to make a connection, the receiver would have to be in line with it. Because we cannot see infrared light, I added an LED which was set up to light up when there was a connection between the 2 IR's.
The transmitting IR is placed at pin 13 and ground, with the concave side facing the breadboard.
There are also 2 wires connected at ground and 3v pins on the power side of the arduino board. The 3v is set inline with the IR receiver and ground with the LED, the IR and LED are placed so that they link up.
When run with the blink sketch, the LED on the breadboard will light up. If something interrupts the signal, the LED goes off.

//insert photo here..


46) Get a plan to send a signal from one Arduino to another. Set one up to receive and one to transmit. Connect the input pin of the receiver to an output pin of the transmitter. Get the receiver to note on the serial screen what it's reading. Get the transmitter to send a slow square wave that can be received and displayed in real human time.


Plan: One arduino has the blink sketch running which also has TxPin = 2 (transmitter), as an output to the other arduino. When the ledPin is HIGH the TxPin is HIGH also. This is then connected to the other arduinos RxPin = 2 (reciever) and the grounds of both arduinos are connected. The recieving arduino is either expecting something or nothing (0 or 1). If the RxPin is equal to 1, it means the led on the other arduino is HIGH so the recieving arduinos led is set to HIGH and outputs a H to the serial monitor.


Transmitter:

int ledPin = 13;
int TxPin = 2;

void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(TxPin, OUTPUT);
}

void loop()
{
digitalWrite(TxPin, HIGH);
digitalWrite(ledPin, HIGH);
delay(1000);

digitalWrite(TxPin, LOW);
digitalWrite(ledPin, LOW);
delay(1000);
}


Reciever:

int RxPin = 2;
int ledPin = 13;

void setup()
{
pinMode(RxPin, INPUT);
Serial.begin(9600);
}

void loop()
{
if (digitalRead(RxPin)==1)
{
Serial.println("H");
digitalWrite(ledPin,HIGH);
}
else
{
digitalWrite(ledPin,LOW);
Serial.println("L");
}
}


47) Same as 46 but this time reverse roles of sender and receiver.

..cut, paste, done :)

48) Same as 46 but get the receiving Arduino to send the level, 1 or 0, that it's getting back to the other Arduino. So it's just receiving and sending a copy back for checking. Get both Arduinos to display what they are getting. A one second on/off will work ok.

This time I tryed getting both the arduinos to send and receive at the same time. This was my code:

int RxPin = 2;
int TxPin = 3;
int ledPin = 13;

void setup()
{
pinMode(RxPin, INPUT);
pinMode(TxPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
//sending
digitalWrite(TxPin, HIGH);
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(TxPin, LOW);
digitalWrite(ledPin, LOW);
delay(1000);
//receiving
if (digitalRead(RxPin)==1)
{
Serial.println("H");
digitalWrite(ledPin,HIGH);
}
else
{
digitalWrite(ledPin,LOW);
Serial.println("L");
}
}

This was on both arduinos (Rx and Tx pin numbers swapped), but it didnt seem to work properly, one would only output low and the other only high so im not sure if this was working correctly.



49) Get one Arduino to send a given series of pulses, say about a 100, about 1ms long, to the other. Get the receiver to count the number of pulses it gets and display this number on the serial screen.

//in the setup so it doesnt loop once its done.

while (count less than 100)
{
digitalWrite(TxPin, HIGH);
digitalWrite(ledPin, HIGH); // set the LED on
delay(500); // wait for a second
digitalWrite(TxPin, LOW);
digitalWrite(ledPin, LOW); // set the LED off
delay(500);
count++;
}


50) How fast can you send a thousand 1/0 pulses and still count them accurately.
I reduced the delay times on both the sender and receiver but it still printed out, not all at once though.

No comments:

Post a Comment