Week 4: Output/Input devices

In week 4 we took a look at the different components that can be used within an Arduino circuit. There are output and input devices where :

  • Input devices read the environment (digital inputs/analogue inputs) sensors, buttons, etc.
  • Output devices are actuators that transform the data received by Input devices to voltage and show result/ interact with the viewer (LEDs, speakers, etc.)

Here are two exercises – the first one with a photoresistor and an LED – when the light is low, the LED turns on and accordingly turns off when the light is sufficient, and the second one measuring the temperature in the room.

For this experiment we used a photoresistor, an LED, a resistor, 4 wires, Arduino Uno and a breadboard. The code that is used is:

//photoresistor A Style Tech.
int Pr = 0; // will be used for analog 0.
int PrValue = 0; // value of output
int Pr_Input = 31; // value of when light is on
void setup() {
Serial.begin(9600); //start serial Monitor
pinMode(8, OUTPUT); // pin 8 as output
}
void loop() {
PrValue = analogRead(Pr);
Serial.println(PrValue); //prints photoresistor value
delay( ); // value updated every 0.1 second.
if (PrValue < Pr_Input) // if sensor value is less than 19, light will turn on.
{
digitalWrite(8, HIGH);//LED on } else { digitalWrite(8, LOW);// LED off }
}
if (PrValue >= Pr_Input) // if sensor value is less than 19, light will turn on.
{
digitalWrite(8, LOW);//LED on } else { digitalWrite(8, LOW);// LED off }
}
}

The light sensor in the circuit constantly collects data about the level of light in the room – after the first measurement we found out that the current light level is 36. After a few experiments with turning on/off the lights, shading the sensor and so on, we found out that something is wrong and the circuit does not function adequately -the LED turned on and off with no connection to the external light conditions. We tried changing the code, playing around with light, but nothing worked, until we realized that the sensor and the LED are too close together so the sensor measures the light of the LED as well, and it is not consistent, so it tricks the sensor into thinking that the light is constantly changing. So that’s what the role of the UNO card is – it is a wall that stops the light from the LED to reach the photoresistor and alter its measurements. After that we found out that the light in the room is actually 32 and after a slight change in code the circuit worked properly.

 

This simple circuit just measures the temperature in the room, but unfortunately the sensor was broken I guess so it showed impossible temperatures.

Here is the used code for this circuit:

void setup()
{
Serial.begin(9600); //Start the serial connection with the computer
//to view the result open the serial monitor
}

void loop() // run over and over again
{
//getting the voltage reading from the temperature sensor
int reading = analogRead(sensorPin);

// converting that reading to voltage, for 3.3v arduino use 3.3
float voltage = reading * 5.0;
voltage /= 1024.0;

// print out the voltage
Serial.print(voltage); Serial.println(” volts”);

// now print out the temperature
float temperatureC = (voltage – 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((voltage – 500mV) times 100)
Serial.print(temperatureC); Serial.println(” degrees C”);

// now convert to Fahrenheit
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
Serial.print(temperatureF); Serial.println(” degrees F”);

delay(1000); //waiting a second
}

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s