Friday, 2 August 2013

Simple Light Meter (Arduino + Servo + Photocell)

Today I almost attended a 24-hour programming contest but at the briefing I decided I didn't fancy sitting there overnight, or being told where I can go and can't. So I simply left. Since the point of me signing up for such an event was mainly to force myself to set aside a little time to figure out how to use Arduino, I sat there for a little while looking up what I was interested in exploring, and went to Sim Lim, where I bought a few bits and bobs and a little servo - and then went home and made my own dumb experiment...

Arduino Uno + Photocell + 1 kΩ Resistor + Small Servo


P8024918

BRIGHT!

P8024919

DARK...

Okay this is basically a superbeginner mashup of these two basic tutorials: Adafruit's Making Sounds (Lesson 10) + Adafruit's Servo Motors (lesson 14). Well I guess I gotta start somewhere so don't laugh at the simpleness of this. I'm just writing it out here because I will probably forget it all if I don't write it down properly, and god knows actual hardware is an undiscovered country for me.

#include  
 
int servoPin = 9;
Servo servo;   
int angle = 0;   // servo position in degrees 
int photocellPin = 0;
 
void setup() 
{ 
  servo.attach(servoPin); 
  //Serial.begin(9600);
} 
 
void loop() 
{ 
  int reading = analogRead(photocellPin); 
  int newAngle = reading/3 - 100;
  //Serial.print(newAngle);
  //Serial.print("\n");
  servo.write(newAngle);           
  delay(60);  
} 


Fritzing


I made a sketch of the above with Fritzing. Fritzing is a useful tool for designers and programmers to design and document their prototypes for pcb boards, arduino-based and other electronics projects. Drag and drop and pull...

Untitled Sketch_bb

Screen Shot 2013-08-03 at 12.00.39 PM.png

1 comment: