Sunday, 30 October 2016

How to control something with photoresistor


This is very simple yet very useful Arduino sketch by which you can control many things. You can measure brightness of a light and turn something on and off on certain brightness of that light.

I have made a simple rubber band gun which you fire with a laser from far away (as far as your laser light can reach).

Who does it work?
Well, it's very simple. When you shine the laser on the photoresistor it turns on the motor and when motor starts turning it releases the rubber band.

What do you need?
1× Motor
1× Led (optional)
2× 10k ohm resistors (if you don't use the led then you will just need 1 resistor)
And of course you might already got Arduino and jumper wires.

The sketch

int photocellPin = 0;     // connect the photoresistor to a0
int photocellReading;     //
int led = 4;          // connect LED to pin 4
    void setup(void) {

      pinMode(led, OUTPUT);
    void loop(void) {
      photocellReading = analogRead(photocellPin);     
      Serial.print("Analog reading = ");
      Serial.println(photocellReading);     // the raw analog reading
if (photocellReading >=500){
    digitalWrite(led, HIGH);
  else {
    digitalWrite(led, LOW);


Because the laser light is too bright so I've set the reading to over 500, you can change that to what ever brightness you want.

That's all for this post I hope you liked it and if you did please feel free to share this with others. Thanks

No comments:

Post a Comment