Laser projector project, part 2: electronics

At this point I have all the electronics working.

I just had to add the phototransistor by following a tutorial. A quick test showed it works really well. I connected a cardboard disc to the motor, taped a few coins on the bottom side in one place, and put the sensor under the disc. There is a very large difference in the values you get back from the sensor when it’s covered with something and when not.

Here’s a first attempt at visualizing the schematic with Fritzing:

Note that for now this includes a pot (to set the motor speed) and no external power (doesn’t seem necessary for now).

And this is a simple program that will turn on the laser when something is in front of the photo sensor:

const int transistorPin = 9; // connected to the base of the transistor
const int laserPin = 13; // connected to laser TTL control (white wire on

void setup() {

// set the transistor pin as output:
pinMode(transistorPin, OUTPUT);
// set the laser TTL pin as output:
pinMode(laserPin, OUTPUT);



void loop() {

// read the potentiometer:
int potValue = analogRead(A0);
// map the sensor value to a range from 0 - 255:
int outputValue = map(potValue, 0, 1023, 0, 255);
// use that to control the transistor:
analogWrite(transistorPin, outputValue);

int photoSensorVal = analogRead(A1);
// turn on laser if something is close to the photosensor
if(photoSensorVal < 100){
digitalWrite(laserPin, LOW);
} else {
digitalWrite(laserPin, HIGH);


That’s actually it for the electronics. This part went easier than expected, thanks to some great tutorials on SparkFun, Bildr, the physical computing wiki from ITP – and of course Alex’s great courses.

What’s next: I have to find a nice design to keep all the parts together. Now everything is literally kept together with tape, which is not very safe. I already sent some mirrors flying around the room. I think I’ll start with moving the optical sensor related things to a second breadboard and connect it to the other one with some longer wires.

This entry was posted in Bert Balcaen, Physical Computing. Bookmark the permalink. Comments are closed, but you can leave a trackback: Trackback URL.

3 Trackbacks

  1. By on April 28, 2014 at 6:00 am

    Laser projector project, part 2: electronics…

  2. By christian louboutin men on April 28, 2014 at 3:15 am

    christian louboutin men…

    Laser projector project, part 2: electronics…

  3. By on April 24, 2014 at 4:58 pm…

    Laser projector project, part 2: electronics…