Photodiode with Arduino Mega 2560: Light Detection Circuit + Proteus Simulation

I had bought this black photodiodes years ago I think but still haven't used it. So while I was surfing my old blog posts, I came across my old Photodiode Light Detector with Arduino blog post. So I wanted to test the photodiode before I can use it in actual implementation. In the previous test when I wrote the blog post on photodiode with arduino, I use another kind of photodiode. And the black photodiode are the ones that are used in IR sensor modules and in the blog post build simple IR sensor based alarm circuit. But these were IR sensor module which has the black light sensor photodiode and the IR emitting photodiode. To test the black light sensing photodiode, I used Arduino mega board this time. Previously I used Arduino Nano and right now my two Arduino Nanos are defective. I don't know why. I could be power surges damaging the voltage regulator something like that. So I am Arduino Mega 2560 with a black photodiode to sense whether the room is dark is not and if it is then turn a LED on. 

Another thing I liked to do is to simulate the circuit in Proteus. What I did was create the Arduino, photodiode, LED functional circuit and wrote a program to test the circuit. Here I have first created a sensor circuit with the black photodiode, resistor, led with the Arduino. So the objective was to turn on the led connected to pin 9 of Arduino Mega, if there is darkness in the room. This circuit is not that hard and so I don't needed to use the Arduino Mega board explorer that I had recently built. 

The circuit diagram of photodiode with Arduino is below.

arduino photodiode light detection circuit diagram


I simulated it and it was working meaning that the code is ok. 

Photodiode with Arduino Code 


// Define pins
int photodiodePin = A1;
int ledPin = 9;

void setup() {
  Serial.begin(9600); // Set Serial output baud rate
  
  pinMode(ledPin, OUTPUT); // Set LED pin as output

  // For output format
  Serial.println("Outputs:");
  Serial.println("Voltage(V):");
  Serial.println("-------------------------------------------------------------\n");
}

void loop() {
  float anaValue = analogRead(photodiodePin); // Read analog value

  float voltage = (anaValue / 1024.0) * 5.0; // Convert to voltage
  
  Serial.println(String(voltage, 2) + "V");

  // Check if voltage is less than 1V
  if (voltage < 1) {
    digitalWrite(ledPin, HIGH); // Turn LED ON
  } else {
    digitalWrite(ledPin, LOW);  // Turn LED OFF
  }

  delay(200); // Small delay
}

Then I uploaded the firmware into Arduino Mega 2560 using the Proteus firmware uploading program. I had program Arduino Uno using this Proteus firmware uploading tool but not the Arduino Mega. So I tried to achieve, test and accomplish not just one but multiple testing. First I was testing the photodiode with Arduino, then I also wanted the photodiode with arduino circuit simulation, another testing task was to test the Arduino Mega 2560 board in Proteus. Then I also tested serial data transfer from arduino into Proteus using the DP9 COM port connector. The incoming data was then connected to the virtual terminal to see the data. The data is light intensity captured by the ADC pin A1 of Arduino Mega and then converted to voltage and then sampled voltages value was sent from Arduino into Proteus virtual terminal for data display. So in short the virtual terminal is the serial monitor in Arduino IDE. So instead of opening and viewing data in serial monitor, I used the virtual terminal in proteus.

I have video recorded this work which I have shared on youtube. Watch the video below.



Post a Comment

Previous Post Next Post