Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

10:22 AM a mycourses.purdue.edu Lab 8 Controlling an AC Load Using Relay l Veriz

ID: 2249141 • Letter: 1

Question

10:22 AM a mycourses.purdue.edu Lab 8 Controlling an AC Load Using Relay l Verizon LTE 72%- Program 8-1: Light Sensor controlling an AC load Using a D2n V23105 DPDT Relay (If not available, USE 74R1581 SPDT 5V Relay in lab kit as substitute) construct the circuit of Figure 8-1. Write a program that turns the Light bulb ON when light intensity crosses a certain threshold, otherwise the Light is off ght bu DANGER H VOLTAGE Figure 8-1 Light Sensor controlling an AC load 2n V23105 l: 5V 400 mW 3 A, 220 n 1 & 16> coil n4. 13 Pin 6, 11 => NC Pin 8, 9->NO Free Wheeling Diode across the coil is #include «avr/io.h> #define FCPU 16000000 #include #define THRES 100 // light threshold => turn led on (5/1024)" min light to Il setup ports void setup() (DDRC = 0x00; // Analog input pin channel 0 DDRB = 0x01; // to connect led to PB0 initialize adc void adc init()

Explanation / Answer

#include<avr/io.h>

#define F_CPU 16000000

#include <util/delay.h>

#define THRES 100

void setup()

{

DDRC = 0x00;

DDRB = 0x01;

}

void adc_init()

{

ADMUX = 0b01000000;

ADCSRA = 0b10000111;

}

int adc_read(int ch)

{

ADCSRA |= 1<<6;

while(ADCSRA & (1<<6));

return(ADC);

}

int main()

{

setup();

int adc_result0;

adc_init();

_delay_ms(50);

while(1)

{

adc_result0 = adc_read(0);

if(adc_result0 < THRES)

PORTB = 0x01;

else

PORTB = 0x00;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote