Tag Archives: Tutorial

Light up different LEDs under different light intensity

I built a little fun device with Arduino that uses a light sensor to detect how light the ambience is and lights up one of the LEDs accordingly. If it is bright in the surroundings the green LED will light, if it is dim the yellow LED will light and the red LED lights if it is completely dark.

Here is the circuit diagram for setting up the device

Image

Each LED has a wire connected to the UNO board to slot 9, 10, 11 individually, and the resistor and light sensor(photocell) all ultimately connect to the negative ground. Make sure they are all interconnected.

Below is the code with detailed comments:

// LDR reads the ambient light, and lights up one of the three LEDs,
//depending on how light the ambience is

#define LEDg 11
#define LEDy 10
#define LEDr 9
#define SENSOR 0

int val = 0;
int val_sensor = 0;

void setup() {

pinMode(LEDg, OUTPUT);
pinMode(LEDy, OUTPUT);
pinMode(LEDr, OUTPUT);
Serial.begin(9600);

//when plugged in, all the LED will light at first
digitalWrite(LEDg, HIGH);
digitalWrite(LEDy, HIGH);
digitalWrite(LEDr, HIGH);
delay(1000);
}

void loop() {
val = analogRead(0);

//print out the readings for light intensity from the sensor
Serial.println(val);

//default all the LED values to LOW so at first they won’t light

digitalWrite(LEDg, LOW);
digitalWrite(LEDy, LOW);
digitalWrite(LEDr, LOW);

 //bright surroundings light the green LED

if (val >= 500)
{
digitalWrite(LEDg, HIGH);
}

//medium light intensity, light the yellow LED
else if (val > 200)
{

digitalWrite(LEDy, HIGH);

}

//when the light intensity is VERY LOW, light the red LED
else
{

digitalWrite(LEDr, HIGH);
}

//set up the delay to 100 milliseconds so the LED respond to change in the light intensity faster
delay(100);
}

Measuring temperature with Arduino

Hi guys!

Here’s a fun little thing you can do with your Arduino. If you don’t have a thermometer but would still like to know the temperature in your room, you can build one using the temperature sensor found in the basic kits for Arduino. 

Image

 

I had to turn the sensor around in this diagram so you could actually see where the wires go. For pin 1 (which when the sensor faces you with the flat side is the left most one, but in this it’s the right most one), you will attach your power line (in this case 5V). Pin 2 goes to an analog source (A1 in my case) and number 3 is your ground pin.

Arduino code:

int tempPin =1; //this is the analog pin you’re connected to

void setup()
{Serial.begin(9600); //serial port connection to the computer

}

void loop()
{

int tempRead = analogRead(tempPin); //voltage reading from sensor
Serial.println(tempRead); //puts out the reading in the serial monitor
int tempC = map(tempRead, 0, 1023, -50, 450); //your values will be from 0 to 1024 which you then convert to your degrees using the map function

//10mv correspond to 1 degreeC
Serial.print(“new temp: “);
Serial.println(tempC);

delay(200);
}

Color certain part of the photo

Want to make your photo fancier? Here is a little useful trick

This is the original image:

Image

If we want to color only the flower and make the rest black and white, it will look like this:

Image

 

 

Open the image and select ‘Pen Tool’ from the tool barImage, the select ‘Path’ from the function window at the topImage, and draw along the figure of flower like this

Image

 

press ‘CTRL+ENTER’ to select the area you just drew, and then press ‘CTRL+SHIFT+I’ to select the counterpart

Image

 

Duplicate the background layer to get background layer copy, then select ‘<Image –> Adjustments –> Hue/Saturation>, a window will pop up and enter the data like following

Image

 

Now your image will look like this:

Image

You are done for now, but if you want to further change the color of the flower, do the following:

press ‘CTRL+SHIFT+I’ to counter-select the flower part, and get the window for ‘Hue/Saturation’ again( A fast way to do this is to press ‘CTRL+U’)

If I want the flower in bright color, I will enter the data as following

Image

 

Notice the color of flower changed? Press ‘CTRL+D’ to cancel selection, and you are done!

Image

Making mirrored image

We also see fancy cosmetics commercials like this:

Image

 

 

 

Using photoshop makes the product looks more presentable, and you may find the trick is very useful in photo-processing. Wonder it is done? Here is the simple tutorial:

First, we need to set up the background, click ‘File –> New’, in the window popped up, entry the data

Image

Note the entry could be different depends on what size and background color you want, for the example above, we get a image like this:

Image

 

Open the target image, select ‘Magic Wand Tool’Image, click at the background , press ‘CTRL+SHIFT+I’ to select the counterpart

Image

 

Drag the selected image to the background image

Image

 

Use the same method to get the bottle image

 

Image

Now we want to make the mirrored images, selected ‘Layer 1’ and ‘Layer 2’ and duplicate them, and we get ‘Layer 1 copy’ and ‘Layer 2 copy’

Image 

Select these 2 copies of layers and press ‘CTRL + T’ to transform them,  right click on the image and select ‘Flip Vertical’, we get the image like this

Image

 

Adjust the opacity of this two copies of layer to 40%

Image

 

and we get the result image, YEAH~

Image

Fixing black and white drawings in Photoshop

Hey guys, here’s a quick tutorial on how I personally fix my drawings using photoshop. I hate that my portraits look real nice and crisp in real life, but once they get scanned, it’s like all the black got sucked out of them and I’m left with a greyed out mess that doesn’t look nearly as nice as the original. Luckily, you can use photoshop to tweak some things and make your drawings look more like you want them.

For this tutorial, I’m going to use this portrait I did of my friend Jon. 

Image

 

As you can see, the scanner did a weird job of the proportions, and the colors look off and patchy. What I first did was use the Rectangular Marquee Tool and made a selection of the part of the drawing I wanted to keep and pasted it into a new window (that way I got rid of the white margin that came out from the scanner going over the page). Next, I used the Free Transform option to rescale the image so it wasn’t so stretched out.

Image

 

Much better in terms of proportions! Next, let’s try to fix the color. In the original, the background was pitch black, but some of the color lifted in the scan. Next thing is to duplicate the layer (right click the current layer tab and select Duplicate layer). This way we can make adjustments and go back to the original if we don’t like it.

For black and white drawings, I like to go to Image> Adjustments> Black and White. This way when we mess around with the levels and curves we don’t get a weird green cast. But this still doesn’t bring the black back into the drawing.To bring it back, we can use the nifty Levels options. 

Image

 

 

Dragging the arrows around allows you to lighten and darker the tones of your pictures. I like to drag the left most one quite a bit in, which effectively darkens the background and shadows that otherwise wouldn’t be showing. 

Image

After tweaking the arrows for a while, this was my end result. More techniques could be used, like using the Burn tool to further darken some areas to make them blend better, like the shadows in the hair. But for now, this will do. 

Image

 

The finished product.

I hope you learned something new and hopefully this will be useful for you when you’re trying to fix your scans!

Image/face swaps

Honestly my most favorite thing to do in Photoshop is mess around with my friends and put their faces onto different bodies. Today, we’re going to put my friend Steven’s face onto Marilyn Monroe’s body. Why? Truly the real question would be Why not. 

Here’s the images we’ll be working with:

Image

Steven looking marvelous. Dashing.

Image

 

This image of Marilyn in the iconic pose.

First thing you’ll want to do is open both images in Photoshop. Keep in mind that this is just how I do it, but you can mess around with the tools and adjustments to your liking until you find something that works for you. 

I like to use the Lasso tool to make a rough selection around Steven’s face

Image

 

Then you’ll want to copy and paste your selection into the window containing your stock photo of Marilyn. I like to hold down CTRL+C (command+C on Mac) and then CTRL+V to paste it. You’ll want to right click the selection in the new window and select Free Transform. That way, you can easily move and adjust the selection.

 Image

 

Position the head roughly proportional to the body for now. We’ll get into detailed work soon. Now, you can put the previous tutorial on Layer Masks to work. Having your head layer selected, click on the Layer Mask button Image

 

Making sure you have the Layer mask thumbnail selected, go ahead and paint in black what you want to hide of the selection, so it’s not as rough, but without deleting the pixels in case you mess up and need to go back easily. When you’re happy with the way it looks, it’s time to get to better arranging the head on the body. I like to decrease the opacity of the head layer until I can see what the real head looks like underneath, but I can still see details of the new one. 

Image

 

This is the most terrifying thing I’ve ever seen. Better get to fixing it quickly. Using the Free Transform option I was talking about earlier, it’s time to resize the head so it’s not five times the size it should be. make sure you have your proportions locked.Image

 

If you right click your selection after hitting Free Transform, you will get multiple options of adjusting your layer. Use Rotate and Scale in order to better fit the photo. If you’re feeling brave, use the other options such as Distort or Warp to better suit your needs. 

Image

 

When you’re happy with how the head is positioned and you’re done laughing, time to clean around the edges. In my example, you can see that Steven’s hair is much darker than Marilyn’s, and I prefer his better. So what I’m going to do is color over Marilyn’s hair in the color of the background to hide it. After that what I like to do is see what Photoshop can do for me in terms of color matching. 

Image

 

After messing around with those settings, and also going into Levels a little bit, I ended up with my final result, which by no means is perfect, but it makes for a good gag photo to laugh at. 

Image

 

I hope you had fun learning how to mess around in Photoshop some more! There’s many other things you can do to make this better, but for the sake of keeping this tutorial short, I’ve kept it pretty basic. Enjoy!

Change background of a photo

 

Changing background of a photo is an easy, fun trick of photoshop. Using Lasso Tool to extract necessary part of image is one basic skill of photoshop and it is extremely helpful in photo processing.

Suppose we have two separate pictures:

ImageImage

and this is how it looks in the end:

Image 

Wondering how it is done? Below is the detailed tutorial, the tools involved may come in handy in basic photoshop manipulating

First, open the two individual pictures in PS

Then select ‘Polygonal Lasso Tool‘ on the left side tool bar.(Note Polygonal Lasso Tool is in the sub menu of ‘Lasso Tool’)

Image 

Extract the image by clicking consecutively along the human figure, you may want to be as precise as possible, as following

Image

Move the selected image to the background picture, and scale it proportionately

Image  

Enlarge the pictures, notice the little area, obviously we need to get rid of that.

Image

Again, use Polygonal Lasso Tool to get the area and press ‘DELETE’ , the selected area will disappear and reveal the background

Image  

Press ‘CTRL+D’ to cancel selection, and then ‘CTRL+0’ to restore the original image size

Now, TAH-DAH~ You are done! Simple, right?

,Image