Hi all,
I am doing a school electronics project with one atmega16, Lcd 16x2, 2 actuators and a couple of sensors. I am using Bascom-AVR to programme.
I would like to ask if anyone has a code for sharp dust sensor GP2Y1010AU.
Actually I started to work with that sensor last week. I have tested it without micro and now I'm trying to interface it with the mega16. I have done a simple code, just to see the adc changes on lcd, but it doesn't work. Im using Adc(1). See the code please. I think it would be better to use a timmer with 3rd pin( of the sensor) but I don't know how to do that. Anyone can help me please.
$crystal = 4000000
$regfile = "m16def.dat"
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portd.3 , Db5 = Portd.2 , Db6 = Portd.1 , Db7 = Portd.0 , E = Portd.6 , Rs = Portd.7
Config Adc = Free , Prescaler = Auto
Dim A As Long
Dim B As Long
Dim Total As Long
'Config Portc.5 = Output
Config Portc.6 = Output
Start Adc
Cls
Do
Set Portc.5
Set Portc.6
Waitms 0.24
Reset Portc.5
Reset Portc.6
Waitms 0.24
A = Getadc(1)
B = Getadc(1)
Total = A + B
Total = Total / 2
Home
Lcd "ADC(1):" ; Total ; " "
Loop
End
See this please:
http://itp.nyu.edu/physcomp/sensors/Reports/GP2Y1010AU
Thanks Everyone 
elektron_
beetje gek
Limus, are you able to measure a fixed voltage, like a
a 1,5 Volt battery or another source.
Do you have an oscilloscope to check the output of the dust sensor ?
Before writing to the LCD you must locate the cursor.
...
Cls
Lcd "Adc(1): " , write this only one time
Do
..
..
..
Locate 1 , 9
Lcd total
Wait 1
Loop
[Bericht gewijzigd door elektron_ op ]
Hi, yes I have a power supply at home.
I just have an oscilloscope at school, but I have tested the sensor at home with a multimeter and worked fine. (I could check the output of the sensor)
I have read some information about this sensor and the maximum value of output is 800mv.
check this please:
http://www.mil.ufl.edu/imdl/papers/IMDL_Report_Spring_05/skipp-trevor/… ---- page 18.
My problem now, is how to interface it with atmega16. I have all connections done (pin1, 2,3....pin6). I have done that code just to see the ADC changes on LCD, but It doesn't work, but I can see the changes with a multimeter.
I think pin 3 should have a timer. I must connect this two pins (pin 5(Vo)---ADC and 3(ILED) to the micro.
In terms of hardware everything is ok, now I need a code or help to do it, that's urgent mate.
Thanks for your reply 
elektron_
beetje gek
Did you connect the ADC voltage ref pins ?
( ARef, AGrnd, AVcc ) ARef is optional I think the other two are mandatory
See datasheet for details.
7.2 Voltage Reference
For the voltage reference this can be from either of 2 sources: internal or external. Internally there are 2
voltage levels to choose from with 2.56V and AVCC, the voltage at pin 30 of the microcontroller. The
voltage at AVCC is typically identical to Vcc, and Atmel recommend this voltage is within 0.3V of
Vcc. Voltage input at the ADC pins of an identical value to the voltage reference, will result in a full
scale reading of 3FFh.
This is another example:
http://aquaticus.info/pressure_sensor
>> AVcc and AGnd are connected here.
[Bericht gewijzigd door elektron_ op ]
Hi, thanks again. No I don't have these pins connected. I will try that way. In terms of code what do you think? Is there any thing wrong or should work with right connections?
elektron_
beetje gek
No ,I don't think the code is wrong,
execept this
Pinc.6 instead of Portc.6
Config Pinc.5 = Output
Config Pinc.6 = Output
Please try to measure another voltage source first.
I might be that the signal consists of very small pulses.
If you sample between 2 pulses you are measuring just nothing.
That's why they have used a capacitor in the example.
So I should use an integrator like this:
signal ---[ R ]----|-------> Atmega
= c
|
-|- grnd
[Bericht gewijzigd door elektron_ op ]
Op 25 mei 2007 17:24:02 schreef elektron_:
Were you able to measure something ?
Hi mate, how are you. I'm working on it now. Your tips were useful thanks again 
Can you help me with this.... (read the post please)
Hi all,
I'm contacting you because I have a doubt related to Humidity and temperature sensor. I have tested the code in my project and it worked well. As I told you before I'm using the atmega16, lcd 16X2, and 2 actuators ( a cooler and a Thermostate resistor to warm the air). I would like to do the following:
When Humidity is >=75% the cooler starts working, otherwise remains stoped.
The Thermostate resitor is always "on", but when temperature is >= 30º it stops.
I'm using portc.1 for cooler and portc.2 for thermostate resistor.
The instruction to set up cooler and thermostate resistor is Reset portc.1/2 because the actuator circuit (with a relay) works as a not.
I'm working on this for two weeks but I can't put this working. Anyone could help me with this please?
This is for a final year school project and I'm starting to be worried.
Humidity and temperature sensor code:
$crystal = 4000000
$regfile = "m16def.dat"
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portd.3 , Db5 = Portd.2 , Db6 = Portd.1 , Db7 = Portd.0 , E = Portd.6 , Rs = Portd.7
Dim Command As Byte , Msb As Byte , Lsb As Byte , Humi As Word
Dim I As Byte , Temp As Word , Celi As Word , Deseti As Word , Big_celi As Word
Config Portc.0 = Input 'Portc Sensor Chuva
Config Portc.1 = Output
'Config Portc.2 = Input
'Config Portc.3 = Output
'Config Portc.4 = Output
Config Portb.7 = Output
'Config Portb.2 = Output
Deflcdchar 0 , 6 , 9 , 9 , 6 , 32 , 32 , 32 , 32 'Creating "°" character
Sck Alias Portd.0 'Serial CLOCK
Sdata Alias Pind.1 'Serial DATA for INPUT
Sdata_out Alias Portd.1 'Serial DATA for OUTPUT
Ddrd.0 = 1 'Data direction for SCK
Config Watchdog = 2048 'Watchdog time setting
Start Watchdog 'watchdog enable
Cursor Off
Cls 'LCD must move back to DATA mode after creating chr
Waitms 20 'Must wait to stabilize LCD
If Pinc.0 = 0 Then
Goto Rotina_chuva
Else
Goto Start1
End If
Start1: 'Main program
Reset Portb.7
Ddrd.2 = 1
Ddrd.0 = 1
Set Portb.2 'Switch ON LED (measuring start)
Command = &B00011110 'SOFTWARE RESET command
Gosub Trans_start
Gosub Send_cmd
Gosub Write_status
Gosub Conn_reset
Gosub Read_humidity
Gosub Conn_reset
Gosub Read_temp
'Cursor Off
Reset Portb.2 'Switch OFF LED (measuring finish)
'Cls ' Clear display
'Waitms 10
Locate 1 , 1
Lcd "HR:"
Locate 1 , 8
Lcd Humi ; " %"
Locate 2 , 1
Lcd "Temp:"
If Celi < 10 Then
Locate 1 , 9
Lcd Celi
Else
Locate 2 , 8
End If
Lcd Celi
Locate 2 , 10
Lcd "."
Locate 2 , 11
Lcd Deseti
Locate 2 , 13
Lcd Chr(0)
Locate 2 , 14
Lcd "C "
' Reset Watchdog
'L11:
'Goto L11
'Powerdown
'***************'
' HUMIDITY READ '
'***************'
Read_humidity:
Command = &B00000101 'Command "READ HUMIDITY"
Gosub Send_cmd
Waitms 20 'Wait to finish measuring
Gosub Sensor_readout
Humi = 0 'Start of humidity calculation (see App. note)
Humi = Humi + Msb
Shift Humi , Left , 8
Humi = Humi + Lsb
If Humi <= 107 Then
Humi = 143 * Humi
If Humi < 512 Then Humi = 512
Humi = Humi - 512
Else
Humi = 111 * Humi
Humi = Humi + 2893
If Humi > 25600 Then Humi = 25600
End If
Shift Humi , Right , 8
Return
'******************'
' TEMPERATURE READ '
'******************'
Read_temp:
Command = &B00000011 'Command "READ TEMPERATURE"
Gosub Send_cmd
Waitms 60
Gosub Sensor_readout
Temp = 0 'Calculation (see App. note)
Temp = Temp + Msb
Shift Temp , Left , 8
Temp = Temp + Lsb
Temp = Temp * 10
Temp = Temp / 25
Temp = Temp - 400
Celi = Temp / 10
Big_celi = Celi * 10
Deseti = Temp - Big_celi
Return
'******************'
' TRANSMISION START'
'******************'
Trans_start:
Config Sdata = Output
Set Sdata_out
Set Sck
Reset Sdata_out
Reset Sck
Waitus 5
Set Sck
Set Sdata_out
Reset Sck
Return
'******************'
' CONNECTION RESET '
'******************'
Conn_reset:
Config Sdata = Output
Reset Sck
Set Sdata_out
For I = 1 To 12
Set Sck
Reset Sck
Next I
Goto Trans_start
Return
'**************'
' COMMAND SEND '
'**************'
Send_cmd:
Config Sdata = Output
Shiftout Sdata_out , Sck , Command , 1 ', 8 , 1 'data change when sck goes low, 8bit out, 1uS delay
Ddrd.1 = 0
Reset Sck
Set Sck
Bitwait Sdata , Reset 'Wait ACK
Reset Sck
Return
Sensor_readout:
Config Sdata = Input
Shiftin Sdata , Sck , Msb , 1 , 8 , 1
Config Sdata = Output
Reset Sdata_out
Set Sck
Reset Sck
Config Sdata = Input
Shiftin Sdata , Sck , Lsb , 1 , 8 , 1
Config Sdata = Output
Set Sdata_out 'pull-up ACK (CRC not use)
Set Sck
Reset Sck
Return
Write_status:
Gosub Trans_start
Command = &B00000110
Gosub Send_cmd
Command = &B00000001 'Switch to 8/12 bit resolution
Gosub Send_cmd
Return
Rotina_chuva:
Home
Cls
Set Portb.7
Lcd "*Esta a Chover*"
Waitms 500
Goto Start1
Return
End
Actuators code (I tested and worked well)
$regfile = "m16def.dat"
$crystal = 4000000
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portd.3 , Db5 = Portd.2 , Db6 = Portd.1 , Db7 = Portd.0 , E = Portd.6 , Rs = Portd.7
Config Portc.1 = Output
Config Portc.2 = Output
Config Portc.3 = Output
Config Portc.4 = Output
Cls
Do
Home
Lcd "All turned off"
Set Portc.1 'Cooler off
Set Portc.2 'Resistor off
Reset Portc.3 'Led off
Reset Portc.4 'Led off
Wait 5
Cls
Home
Lcd "Resistor On"
Set Portc.4 'Led on
Reset Portc.2 'Resistor on
Reset Portc.3 'Led off
Set Portc.1 'Cooler off
Wait 5
Cls
Home
Lcd "Cooler On"
Set Portc.3 'Led on
Reset Portc.4 'Led off
Set Portc.2 'resistor off
Reset Portc.1 'cooler on
Loop
My problem now is how to interface this two codes, to do what I have said previously. When Humidity is >=75% the cooler starts working, the resistor is allways on but when temperature is >30º it stops.
Please help me with this..
If you want the two codes in attachment please ask me, I put this way because you might don't have Bascom installed on your Pc.
Many thanks,
Gonçalo
pcnerd
Take a parachute, and jump!
first of all, we want to help you, and this maybe a little hard for you, but you are not doing exactly the right thing.
-I'm sorry, but this is a Dutch forum, and I do not think that you will find much response here, maybe try an english or a portugese forum. There are various electronics forums in english which all like to help you.
-This topic in the wrong section, you should be in the section "schoolvragen" (which means school-questions), this subforum is set up for students, and the main rules for that subforum is that you have to give an input yourself, what *might* be the problem, we will not give you the exact solution, but help you to it, so that you, and not we, have done it.
-Paiste codes inside the [code ] en [/code ] blocks (without the space ofcourse), or even better, use a pastbin.
note: this is not to do you wrong, but I'm afraid you really should be dutch in order to gain your answer here, I'm sorry, maybe the mods also will disagree with me, I will also be sorry for that when it happends.
Ok mate no problem, I understand. However you were a good help, I have all things working fine now. Thanks again everyone 
Regards
Henry S.
Moderator
Confucius says chà bù duo. Deze post is niet door ChatGPT gegenereerd. De 2019 CO labvoeding.
This mod agrees with pcnerd, but also thinks that this topic has been modest.
Move /Schoolvragen and good luck to Limus with project