Greetings,
I am working on a project where I have an LED as a transmitter and Photodetector as a receiver. I am sending a text that is encoded using serial.println() function and enables LED flicking according to the transmitted text ASCII code. At the receiver side, I am connecting a photodetector to an analog pin A0, and I want to receive the text that was transmitted
Using this code, we sent a text from PC (A) to PC(B) without any components to test it, and it worked well, but I don't know how to adjust it to be able to receive using a photodetector
TX: (Arduino MEGA)
void setup() {
// put your setup code here, to run once:
Serial.begin (115200);
Serial1.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Hello");
Serial1.println("Hello world");
delay(1000);
}
Rx: (Arduino UNO)
#include <SoftwareSerial.h>
SoftwareSerial mySerial(a0, 11); // RX, TX
void setup() {
// put your setup code here, to run once:
Serial.begin (115200);
mySerial.begin(9600);
}
void loop() { // run over and over
if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
}
I used this code to read from the receiving pin, and it will take the ascii code and convert it back to the original text. I, however, noticed that when I run this code I am not receiving anything.
In my attempt to address the issues of the above code, I tried the below code of analog read example form Arduino references:
int analogValue = 0; // variable to hold the analog value
void setup() {
// open the serial port at 9600 bps:
Serial.begin(115200);
}
void loop() {
// read the analog input on pin 0:
analogValue = analogRead(A0);
// print it out in many formats:
Serial.println(analogValue); // print as an ASCII-encoded decimal
Serial.println(analogValue, BIN); // print as an ASCII-encoded binary
//delay(10);
}
Using this code I was able to read something in my serial monitor (the sensed value and its binary representation). However, I noticed that only transmitted (bit 1) is received.
Thanks for your help in advance