EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
You are here: Home / Topics / project clarity required

project clarity required

|

Microcontroller › AVR › project clarity required

  • This topic has 1 reply, 2 voices, and was last updated 8 years ago by AJISH ALFRED.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • August 14, 2014 at 9:52 am #3232
    govindraj
    Participant

    Dear sir;
    i am doing project with atmega8 controller, when i am connecting load with controller that time not able to get proper voltage from controller , can u give proper relay connection.here i’m sending code of my project.

    “”@@@
    #include <avr/io.h>
    #include <avr/interrupt.h>
    #include <util/delay_basic.h>
    #define F_CPU 1000000
    #define Motor_ON PORTC|=(0X20)
    #define Motor_OFF PORTC&=(~(1<<5))
    void delay(unsigned char);
    uint16_t ReadADC(uint8_t ch);
    void InitADC();
    void init_lcd();
    void ioinit (void);
    void lcd_cmd(unsigned char command);
    void lcd_data(unsigned char data);
    void adc(unsigned int values);
    unsigned int CheckResetButton();
    int display(uint8_t t);
    uint16_t Current_MIN,Current_MAX,valueofthirtyper,sum,avg;
    uint16_t adc_value1,adc_value2,arr[10];
    uint8_t t,a,b,c;

    void ioinit (void)
    {
    DDRB = 0b11111111; //Pin 27 of MCU as input
    //PORTB = 0b00000000; //Enable internal pullup of pin 27
    DDRC=0b00110000; //ADC input
    PORTC|=0b00001000;
    }
    void adc(unsigned int values)
    {
    int h,t,o,ten;
    t=(values/1000);
    h=(values/100)%10;
    ten=(values/10)%10;
    o=(values%10);

    lcd_data(t+48);
    delay(1);
    lcd_data(h+48);
    delay(1);
    lcd_data(ten+48);
    delay(1);
    lcd_data(o+48);
    }

    unsigned int CheckResetButton()
    {
    int i,j;
    sum=0;avg=0;
    for(i=0;i<10;i++)
    {
    arr=ReadADC(0);
    sum+=arr
    ;
    //lcd_cmd(0xC0);
    //adc(sum);
    delay(1);
    PORTC|=0x10;
    delay(2);
    PORTC&=(~(1<<4));
    delay(1);
    for(j=0;j<20;j++)
    delay(2);

    }
    avg=sum/10;
    //return(&avg);
    }
    void main()
    {
    Motor_OFF;
    int i,value;
    //DDRB=0xff;
    DDRD=0xff;
    //DDRC=0xff;
    init_lcd();
    InitADC();
    ioinit ();
    while(1)
    {
    lcd_cmd(0x80);
    value=ReadADC(0);
    adc(value);
    if (bit_is_clear(PINC, 3))
    {
    Motor_OFF;
    CheckResetButton();
    valueofthirtyper=(avg)*0.3;
    Current_MIN=(avg)-valueofthirtyper;
    Current_MAX=(avg)+valueofthirtyper;
    lcd_cmd(0xC0);
    adc(Current_MIN);
    }
    if(value>Current_MIN && value<Current_MAX)
    Motor_ON;
    else
    Motor_OFF;

    }
    }

    void lcd_cmd(unsigned char command)

    {

    //Put command on the Data Bus
    PORTB = command;

    //Enable LCD for command writing
    PORTD = 0b00010000;

    //Allow delay for LCD to read the databus
    delay(1);

    //Disable LCD again
    PORTD = 0b00000000;

    //Allow some more delay
    delay(1);
    }

    //Function for sending Data to LCD
    void lcd_data(unsigned char data)
    {
    //Put data on Data Bus
    PORTB= data;

    //Set R/S (Regiter Select) to High, and Enable to High
    PORTD = 0b00110000;

    //Allow for delay
    delay(1);

    //Disable LCD again
    PORTD = 0b00100000;

    //Allow for some more delay
    delay(1);
    }

    //Function to Initilise LCD
    void init_lcd()
    {
    //Setup both lines of LCD
    lcd_cmd(0x38);
    //Set Cursor off – Enable LCD
    lcd_cmd(0x0E);
    //Clear Screen
    lcd_cmd(0x01);
    //Goto first position
    lcd_cmd(0x80);
    }

    //Delay function

    void delay(unsigned char dtime)
    {
    int i,j;
    for(i=0;i<=dtime;i++)
    {
    for(j=0;j<1000;j++);
    }}
    //You can use your own delay functions and replace this delay function with your code
    /*


    */

    uint16_t ReadADC(uint8_t ch)
    {
    //Select ADC Channel ch must be 0-7
    ch=ch&0b00000111;
    ADMUX|=ch;

    //Start Single conversion
    ADCSRA|=(1<<ADSC);

    //Wait for conversion to complete
    while(!(ADCSRA & (1<<ADIF)));

    //Clear ADIF by writing one to it
    ADCSRA|=(1<<ADIF);

    return(ADC);
    }

    void InitADC()
    {
    ADMUX=(1<<REFS0);
    ADCSRA=(1<<ADEN)|(1<<ADPS2)|(ADPS1)|(ADPS0);//Enable ADC with Prescalar=Fcpu/128 // For Aref=AVcc;//Wait for conversion to complete
    }
    “”””@@@@.
    In this code 1st 1min it will take 10 values from current sensor and it will make average.after that i’m adding and subtraction +-30% tolarance.it will check current value with that +-30%.when it goes beyond the avg+30% or lessthan avg-30% making portc 5th pin as high.that 5th pin giving to relay.while connecting in proteus i’m gettng o/p.but connecting in hardware its not giving constantly.in hardware part i connected o/p of current sensor to controller.can u tell me hw to interface load through relay and current sensor with controller.

    Thank you.

    August 15, 2014 at 8:22 am #12019
    AJISH ALFRED
    Participant

    Hi,

    Simulators are just waste of time, if you want to try the same in real hardware.

     

    Always connect a relay to a microcontroller through a driver circuit. The driver circuit can be a single transistor. Connect the output pin to the base of the transistor through a resistor of 1K and connect the relay to the collector. If it is an NPN transistor connect the other end of relay tp positove and emitter of transistor to ground.

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Circuit Problem August 14, 2022
  • Beam Break Sensor August 14, 2022
  • Drill speed controller fault August 14, 2022
  • uc3843 Buck-boost August 14, 2022
  • Right channel distortion on vintage fisher rs-2010 August 13, 2022

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2022 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools