Documentation Week 9

Assignment for week 9


Use an Input device

Arduino

For this assignment i had to use an input device to read some analog variables.

My pick fell on a light sensor. The program i wrote is the following:


#define PhC_PIN PB3 //Define the Photoconductive Cell Pin

int phcellReading; //Variable for PhCell Reading

#include //Including the SoftwareSerial library

#define RX PB0 //Defining the MOSI Pin as RX

#define TX PB1 //Defining the MISO Pin as TX

SoftwareSerial mySerial(RX, TX); //Defining the SoftwareSerial Pins (RX, TX)

void setup() {

mySerial.begin(2400); //Opening the serial, 2400 as data rate

pinMode(PhC_PIN, INPUT_PULLUP); //Setup the internal Pullup

}

void loop(){

phcellReading = analogRead(PhC_PIN); //Read the PhCell

mySerial.print("Analog reading = ");

mySerial.println(phcellReading); //Print PhCell

delay(100); //wait a bit

}


Every 100 miliseconds the sensor picks up the light and puts it out in the seriell monitor.

code

Here you can see how the light sensor is connected to the analog pins of the bord and writes the values to the seriel output.

code


Download:

Code