Skip to content

7. Input & Output device

This week I worked on different elements that is either output or input devices including how to program them & connections

Types of wires

  • Positive: Voltage common collector (vcc) or vin

  • Negative: Ground or GND

Different Aspects

  • Microcontroller: can be used as power source

  • Digital: alternating voltage between high & low

  • Analog: Can have many voltage due to the sinusoidal pattern. In other words you can control voltage amount using it

  • Currents: We have two types of currents AC & DC

Input Sensors

  • Light Sensor It works on the photoresistor light sensitivity and resistance to the amount of light falling on it

  • Temperature Sensor Device used to measure temperature depending on its resistance & the received voltage

  • Ultrasonic Sensor It is distance sensor it measures the distance by emitting high frequency sound waves and receiving the reflection back. The time it takes to go & rebound is calculated and converted to distance

Output Device Experiment

Jumper Wires

There are three types of jumpers

  • Male to Male

  • Male to Female

  • Female to Female

The difference between male & female is the end point of the wire male have pins that used to be plugged into things, whereas female ends is open and needs things to be plugged into. Another thing to mention is color do not mean anything.

how does LDR sensor works

It is relatively easy to understand the basics of how an LDR works without delving into complicated explanations. It is first necessary to understand that an electrical current consists of the movement of electrons within a material.

Good conductors have a large number of free electrons that can drift in a given direction under the action of a potential difference. Insulators with a high resistance have very few free electrons, and therefore it is hard to make the them move and hence a current to flow.

An LDR or photoresistor is made any semiconductor material with a high resistance. It has a high resistance because there are very few electrons that are free and able to move - the vast majority of the electrons are locked into the crystal lattice and unable to move. Therefore in this state there is a high LDR resistance.

As light falls on the semiconductor, the light photons are absorbed by the semiconductor lattice and some of their energy is transferred to the electrons.

The amount of energy transferred to the electrons gives some of them sufficient energy to break free from the crystal lattice so that they can then conduct electricity. This results in a lowering of the resistance of the semiconductor and hence the overall LDR resistance.

the process is progressive, and as more light shines on the LDR semiconductor, so more electrons are released to conduct electricity and the resistance falls further.

code for LDR sensor

int ldr=A0;//Set A0(Analog Input) for LDR.
int value=0;
void setup() {
Serial.begin(9600);
pinMode(3,OUTPUT);
}

void loop() {
value=analogRead(ldr);//Reads the Value of LDR(light).
Serial.println("LDR value is :");//Prints the value of LDR to Serial Monitor.
Serial.println(value);
if(value<300)
  {
    digitalWrite(3,HIGH);//Makes the LED glow in Dark.
  }
  else
  {
    digitalWrite(3,LOW);//Turns the LED OFF in Light.
  }
}

connection of the sensor

#define sensor 2
#define buzzer 3
#define red 4
#define green 5

void setup() {
Serial.begin(9600);
pinMode(sensor,INPUT);
pinMode(buzzer,OUTPUT);
pinMode(green,OUTPUT);
pinMode(red,OUTPUT);


}

void loop() {
bool value = digitalRead(sensor);
if(value == 0)
{
  digitalWrite(buzzer, HIGH);
    digitalWrite(green, HIGH);
      digitalWrite(red, HIGH);

}
else
{
    digitalWrite(buzzer, LOW);
    digitalWrite(green, LOW);
      digitalWrite(red, LOW);
  }
}

connection of LDR sensor & SERVO motor with mkr1010

code of SERVO

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

final code file

click here

group assignment

Check out sami’s documentation for our group assignment

group assignment


Last update: September 7, 2022