0% found this document useful (0 votes)
14 views

Control 2

The document discusses several projects involving controlling LEDs and other outputs using analog inputs from potentiometers and light sensors. Project 1 involves controlling LED brightness using a potentiometer. Project 2 involves implementing a state table using LED outputs controlled by a potentiometer input. Projects 3 and 4 involve controlling LEDs using the output from a light sensor.

Uploaded by

jasmhmyd205
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Control 2

The document discusses several projects involving controlling LEDs and other outputs using analog inputs from potentiometers and light sensors. Project 1 involves controlling LED brightness using a potentiometer. Project 2 involves implementing a state table using LED outputs controlled by a potentiometer input. Projects 3 and 4 involve controlling LEDs using the output from a light sensor.

Uploaded by

jasmhmyd205
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

University of Basra

College of Engineering

Electrical Engineering

‫محمد حيدر سلمان‬


22- ‫الثالث – تحكم‬
2021/7/7
Introduction

analog input
It is the feature of MCU which enables it to deal with analog signals.
For MCU to have this feature, it should have internal A/D converter
circuit. Arduino boards use MCUs which have this feature. For example,
Arduino uno has 6 channels (analog inputs), all of these channels are
connected to one A/D converter circuit using multiplexer circuit. The
used A/D circuit is of 10 bits digital output with flexible reference
voltage. The default reference analog input is 5v, then the input is 0 to
5v and the output of the A/D circuit is 10 bits (integer number ranging
from0 to 1023).
Software: the instruction used to read the analog input is:

Description
This instruction reads the value from the specified analog pin. Arduino
boards contain a multichannel, 10-bit analog to digital converter. This means
that it will map input voltages between 0 and the operating voltage(5V or
3.3V) into integer values between 0 and 1023. On an Arduino UNO, for
example, this yields a resolution between readings of: 5 volts / 1024 units or,
0.0049 volts (4.9 mV) per unit. See the t able below for the usable pins,
operating voltage and maximum resolution for some Arduino boards.
The input range can be changed using analogReference() instruction, while
the resolution can be changed (only for Zero, Due and MKR boards)
using analogReadResolution().
On ATmega based boards (UNO, Nano, Mini, Mega), it takes about 100
microseconds (0.0001 s) to read an analog input, so the maximum reading
rate is about 10,000 times a second.

Parameters
pin: the name of the analog input pin to read from (A0 to A5 on most boards,
A0 to A6 on MKR boards, A0 to A7 on the Mini and Nano, A0 to A15 on the
Mega).

Returns
The analog reading on the pin. Although it is limited to the resolution of the
analog to digital converter (0-1023 for 10 bits or 0-4095 for 12 bits). Data
type: int.

1
Analog output
Most of MCUs have no real analog output, but most of them have the ability
to generate PWM output. PWM is a digital or rectangular signal with
controllable duty cycle, then it can be viewed as analog signal where it would
produce variable voltage output if it had been filtered.
PWM signal is used extensively in many applications such as controlling DC
motors speed and light intensity.
Arduino boards have many pins which can be used to produce PWM signal,
these pins are not a separated pins, but they are a set of digital pins. For
example, Arduino uno has 6 pins and they are 3,5,6,9,10 and 11.
Software: the instruction used to perform analog output is analogRead.

[Analog I/O]

Description
This instruction Writes an analog value (PWM wave) to a pin. It Can be used
to light a LED at varying brightnesses or drive a motor at various speeds.
After a call to analogWrite(), the pin will generate a steady rectangular wave
of the specified duty cycle until the next call to analogWrite() (or a call
to digitalRead() or digitalWrite()) on the same pin.

2
Proj1:- Design MCU based system to control the illumination intensity of a
LED, where this intensity is determined by potentiometer?

int r=0;
void setup() {
pinMode(5,OUTPUT);
pinMode(A3,INPUT);
Serial.begin(9600);
}

void loop() {
r=analogRead(A3);
Serial.println(r);
analogWrite(5 ,r);
delay(100);
}

Proj2:- design MCU based system to form the following state table:-

int r=0;
void setup() {
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(A0,INPUT);
}
void loop() {
r=analogRead(A0);
if(r>50){
digitalWrite(5,1);
digitalWrite(4,1);
digitalWrite(2,0);
digitalWrite(3,0);
delay(2*r);
digitalWrite(5,0);
digitalWrite(3,1);

delay(2*r);
digitalWrite(4,0);
digitalWrite(2,1);
delay(2*r);

3
digitalWrite(3,0);
digitalWrite(5,1);
delay(2*r);
}
if(r<=50){
digitalWrite(5,1);
digitalWrite(4,1);
digitalWrite(2,0);
digitalWrite(3,0);
delay(100);
digitalWrite(5,0);
digitalWrite(3,1);
delay(100);
digitalWrite(4,0);
digitalWrite(2,1);
delay(100);
digitalWrite(3,0);
digitalWrite(5,1);
delay(100);
}
}

Proj3:- Design MCU based system to control the illumination intensity of a


LED using photoresister (LDR) as a light sensor?

int r=0;
void setup() {
pinMode(5,OUTPUT);
pinMode(A3,INPUT);
Serial.begin(9600);
}

void loop() {
r=analogRead(A3);
Serial.println(r);
analogWrite(5 ,r);
delay(100);
}

Proj4:- Design MCU based system to control a LED (switching on off control)
using photoresister (LDR) as a light sensor? Where the LED should be switched on
4
when the light intensity is low.

int r=0;
void setup() {
pinMode(2,OUTPUT);
pinMode(A0,INPUT);
}

void loop() {
r=analogRead(A0);
if(r<200){
digitalWrite(2,0);
}
if(r>200){
digitalWrite(2,1);
}
delay(100);
}

You might also like