Task 1: Simple Light Reading With LDR: Schematic
Task 1: Simple Light Reading With LDR: Schematic
Schematic
CODE
int sensorReading;//analog pin reading
void setup()
{
Serial.begin(9600);
pinMode(6,OUTPUT);
}
void loop()
{
sensorReading=analogRead(0); //get analog reading
if (sensorReading<700)
{
digitalWrite(6,HIGH);
}
else digitalWrite(6,LOW);
Serial.println(sensorReading);
delay(1000);
}
CODE
const int analogInPin = A0; // Analog input pin that the
potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is
attached to
int sensorValue = 0;
int outputValue = 0;
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin, outputValue);
// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);
// wait 2 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(2);
}
Code
int sensorValue = 0; //make a variable where you can store
incoming
//analog values
void setup(){
pinMode(12, OUTPUT); //tell arduino what you'll be using these
pins
pinMode(11, OUTPUT); // for (output).
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
Serial.begin(9600); //initialize serial
}
void loop(){
digitalWrite(8, LOW);
delay(15);
digitalWrite(9,HIGH);
sensorValue = analogRead(0);
delay(sensorValue + 25);
digitalWrite(9,LOW);
delay(15);
digitalWrite(10,HIGH);
sensorValue = analogRead(0);
delay(sensorValue + 25);
digitalWrite(10,LOW);
delay(15);
digitalWrite(11,HIGH);
sensorValue = analogRead(0);
delay(sensorValue + 25);
digitalWrite(11,LOW);
delay(15);
}
Wiring Input/Output
A= Pin 2
B= Pin 3
C= Pin 4
D= Pin 6
E= Pin 7
F= Pin 8
G= Pin 9
Code
// bits representing segments A through G (and decimal point) for numerals 0-9
const byte numeral[10] = {
//ABCDEFG /dp
~B11111100,
~B01100000,
~B11011010,
~B11110010,
~B01100110,
~B10110110,
~B10111110,
~B11100000,
~B11111110,
~B11100110,
}
;
//
//
//
//
//
//
//
//
//
//
0
1
2
3
4
5
6
7
8
9
else{
// isBitSet will be true if given bit is 1
isBitSet = bitRead(numeral[number], segment);
}
isBitSet = ! isBitSet; // remove this line if common cathode display
digitalWrite( segmentPins[segment], isBitSet);
}
}