Book early for 11/03/2017

Registered #ninjas can book their space now at http://www.coderdojosligoirl.eventbrite.ie/  Space is limited this week!

Advertisements
Arduino

Intro to Arduino – Week 3

Intro to Arduino – Week 3

Notes from this weeks session are reproduced below.  In case there is any problem in viewing you can visit the original notes created by Stuart on http://www.fablabmh.org/arduino/

 

 

This week we will use Light Dependent Resistors (LDRs) to control the switching off or on of an LED.

This is the type of automatic switching that happens with Security Lights that turn on at Dusk and off at Dawn.

Here is the sketch.

// pin assignments
 int LED = 13;
 int LDR = 0;
 
 // variables
 int base;
 int threshold = 200 ;
 
 // declare inputs and outputs
 // and take a baseline reading
 void setup() {
   pinMode(LED, OUTPUT);
   base = analogRead(LDR);
   Serial.begin(9600);
 }
 
 // read from the analog input connected to the LDR
 // and print the value to the serial port.
 // the delay is only to avoid sending so much data
 // as to make it unreadable.
 void loop() {
   int liteLevel = analogRead(LDR);
   int x = (liteLevel-base);
   Serial.println(liteLevel);
   Serial.println(x);
   if (x < threshold) {
     digitalWrite(LED, HIGH);
   } else {
     digitalWrite(LED, LOW);
   }
 }

And here is the circuit diagram (note the Resistor value is 1K ohm)

 

LDR Switch

Lastly here is a link to the Circuit and Code on 123DCircuits.com – LDR SWITCH

This is a fantastic website by Autodesk that allows you to create virtual circuits and upload code to a virtual Arduino and test that it works before making it for real.

The website requires a free login that you can create here