Close or Esc Key

Arduino Projects   |   Raspberry Pi   |   Electronic Circuits   |   AVR   |   PIC   |   8051   |   Electronic Projects

Interfacing BH1750 sennsor with Atmega8

2 posts / 0 new
Last post
mubarra shaikh
mubarra shaikh's picture
Offline
Last seen: 3 months 1 week ago
Joined: 06/07/2014 - 00:59
Interfacing BH1750 sennsor with Atmega8

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:\Users\mubar\Desktop\atmega32\light intensity\src\bh1750/bh1750.h"
#include <avr/pgmspace.h>
 
#include "C:\Users\mubar\Desktop\atmega32\LCDDemo1\LCDDemo1\lib\lcd/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);
}
}
 
Ashutosh Bhatt
Ashutosh Bhatt's picture
Offline
Last seen: 1 month 1 week ago
Joined: 21/12/2010 - 15:59
for displaying fraction

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