Import an image to arduino and convert it in a bitstream

I am working on a project , which needs to important and image to an arduino from a file saved on the computer , and be able to convert it into a bitstream. How would I do this ? This data would then be sent through the pin turing on an LED when a 1 is transmitted and be turned off when a 0 is transmitted.How would I do this ?

Transmit image over Serial to the Arduino, one byte at a time. Then simply iterate over the byte (Arduino has the convenient bitRead() function for that) and blink the LED accordingly.

Something like:

if (Serial.available()) {
  c = Serial.read();
  for (byte i = 7; i >= 0 ; i--) {
    digitalWrite(LEDPIN, bitRead(c, i));
    delay(100);
  }
}

LED blink routine takes LSB first, if you want MSB first then reverse the loop:

 for (byte i = 0; i < 8; i++) {

The delay is so you can actually see the LEDs flashes.

@krishv11, what size is the image?

Generally speaking an Arduino has too little SRAM and is too slow to do anything useful with images.

…R

OP wasn't asking to copy the image to the Arduino, just blink an LED based on the bits of an image stored on the PC, and that should be possible.
Now I can't possibly think of any useful application of this, so most likely it's a school assignment.

wvmarle:
OP wasn’t asking to copy the image to the Arduino, just blink an LED based on the bits of an image stored on the PC, and that should be possible.
Now I can’t possibly think of any useful application of this, so most likely it’s a school assignment.

I was aware of that and I believe I phrased my response accordingly :slight_smile:

I am also aware that many Threads start with questions that are mere snippets of the whole project.

…R

On that note, you will need some kind of serial handshaking protocol like Xon/Xoff for flow control. Otherwise the PC will have to guesstimate and throttle the transmitted data flow to match the speed of the device(printer?).

If you're going to sprinkle the same question all over the Internet, please be considerate enough to link them so folks don't waste effort giving you answers you already have. We're here helping you for free. Please show at least a little consideration for that.