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
  • Advertise
You are here: Home / Topics / Interfacing BH1750 sennsor with Atmega8

Interfacing BH1750 sennsor with Atmega8

|

Microcontroller › AVR › Interfacing BH1750 sennsor with Atmega8

  • This topic has 1 reply, 2 voices, and was last updated 8 years, 3 months ago by Ashutosh Bhatt.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • January 1, 2018 at 6:49 am #4708
    mubarra shaikh
    Participant

    Hi,

    I am trying to interface Atmega8 with BH1750 digital light sensor and displayin intensity on LCD.

    I am getting decimel values on LCD.But I want to display fraction values.  I tried a lot but failed..

    can anybody please help. following is main program …

     

    //main.c

    #include <avr/io.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <util/delay.h>
    #include <avr/interrupt.h>
    #include "C:UsersmubarDesktopatmega32light intensitysrcbh1750/bh1750.h"
    #include <avr/pgmspace.h>
     
    #include "C:UsersmubarDesktopatmega32LCDDemo1LCDDemo1liblcd/lcd_hd44780_avr.h"
     
    int main(void)
    {
     
    LCDInit(LS_NONE);
     
    LCDWriteFString(PSTR("LCD Test !"));
     
     
    char printbuff[200];
     
    sei();
    bh1750_init();
     
     
    //infinite loop
    while(1)
    {
     
    float lux = bh1750_getlux();
     
           sprintf(printbuff,"%f",lux);
       LCDWriteString(printbuff);
     
    _delay_ms(1000);
    }
    }
     
    January 7, 2018 at 12:08 pm #14694
    Ashutosh Bhatt
    Participant

    for displaying fraction values on LCD you have to do some juggling with digits.

    first get the final answer in float (may be with 2 digit after decimal point)

    now multiply this answer with 100 – so you will get final value without decimal point

    now convert all digits of this value into ASCII characters and print these values

    one by one on LCD with one decimal point in between

  • 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

  • Some opamp advice please April 12, 2026
  • isolating S-params in of PCB board without connectors April 11, 2026
  • want help with microprocessor April 11, 2026
  • Voltage comparator circuit verification April 11, 2026
  • Integrating 0–5V ECU Signals into a Double-DIN Setup – Module vs Custom Head Unit? April 11, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 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
  • Advertise