Simple Arduino circuit that flashes LED's based on the input from a photocell.
Code Below:
const int analogIN = A0; //Defines the Analog pin for IN
int sensorValue = 0; //Value read from the light sensor
int outputValue = 0; //output to the analog out
const int AnalogOUT1 = 3;
const int AnalogOUT2 = 5;
const int AnalogOUT3 = 6; //defining physical pins 3,5,6,9, and 10 as AnalogOUT1-5
const int AnalogOUT4 = 9;
const int AnalogOUT5 = 10;
void setup() { Serial.begin(9600); pinMode(AnalogOUT1, OUTPUT);
pinMode(AnalogOUT2, OUTPUT);
pinMode(AnalogOUT3, OUTPUT); // Set the Analog pins to be output
pinMode(AnalogOUT4, OUTPUT);
pinMode(AnalogOUT5, OUTPUT);
}
void loop() {
sensorValue = analogRead(analogIN); // read the analog in value: outputValue = map(sensorValue, 0, 3000, 0, 5000); // map range of sensor and output, change for new ratio!!!
analogWrite(AnalogOUT1, outputValue);
analogWrite(AnalogOUT2, outputValue);
analogWrite(AnalogOUT3, outputValue); // change the analog out value
analogWrite(AnalogOUT4, outputValue);
analogWrite(AnalogOUT5, outputValue); Serial.print("sensor = " ); // print the results to the serial monitor Serial.print(sensorValue); Serial.print("\t output = "); Serial.println(outputValue); delay(10); // 10ms delay
}
Link to this comment:
All Comments (0)