LED as light sensor !!?

Sometime ago there was a post on reddit which claimed that you can use your LED as a light sensor to detect the intensity of light. We decided to try it out and oh boy! it completely changed our perspective on the LED.

We just took a LED and performed an AnalogRead on the Arduino. Check this out:

LiFi using IR sensor and headphone jack

In our previous post, we explored using the Solar panel + Led as a LiFi module. In this post, we shall be using IR sensors in order to transmit data (tones and square wave signals) wireless. The schematics of the setup are given below:

drawing

One can use this to send square wave of any frequency independently as well. This has been demonstrated in the video below

Video Demo:
Watch the video demo for a live demonstration of the working of this concept.

This is not limited to tones, one can use it to transmit raw music as well.

 

Switch on and off LED in Arduino using PySerial

When one starts off learning about Arduino, the Blind LED is one of the most popular programs to begin with. As you go up the learning ladder you find asking the question of ‘Hang on! What if I want to change the blink rate dynamically ?’ How would one go about doing that ?

Or breaking it further, how to turn on and off led with my discretion

Well, off the bat the first thing I could think of is using the Serial port to send the signal to switch on and off the LED. Ardruino has a default command that can be used for this purpose:

Serial.available()

” Get the number of bytes (characters) available for reading from the serial port. This is data that’s already arrived and stored in the serial receive buffer (which holds 64 bytes). available() inherits from the Stream utility class ”

Arduino code:

char c;
int led = 13;
boolean ledLightUp = false;

void setup(){
  Serial.begin(9600);
  pinMode(led,OUTPUT);
}

void loop()
{
// When a user sends serial data then read and execute the following
   if (Serial.available() > 0)
    {
      c = Serial.read(); 
      Serial.println(c);
      if(c == 'y')
      {
        ledLightUp = true;
        Serial.println("LED ON");
      }
      else if(c == 'n')
      {
        ledLightUp = false;
        Serial.println("LED OFF");
      }
    }
  if(ledLightUp){
    digitalWrite(led,HIGH);
  }  
  else{
    digitalWrite(led,LOW);
  }
}

 

Python code:

>> import serial,struct
>> ser = serial.Serial('your port name', 9600)
>> ser.write(struct.pack('b',enter here 'y' or 'n' with paranthesis))

 

You can watch the following video I made that demonstrates the essence of this post.