I am creating a project in which an Arduino reads (gets) a value from a DHT sensor. The DHT sensor returns two values:

  1. Temperature
  2. Humidity

enter image description here

My assembly code:

sbi ddrd,5
cbi ddrd,2
sbi portd,5


in r16,Pind2
cpi r16,80
brne On

jmp start

cbi portd ,5
jmp start

After the code, the light remains turned on, but if the sensor sends '80' and I get it correctly it should be turned off.

Question: Am I Using the write way to read a pin?

  • The first thing I saw was a cartoon where apparently a schematic is supposed to be, so I quit before reading any of the text.
    – Olin Lathrop
    Dec 2, 2017 at 13:27
  • 1
    I'm not sure any of your code makes sense. Firstly you've got the roles of pind and portd backwards (port is for writing, pin is for reading). Secondly you haven't defined in your code what half of the stuff is (what is ddrd, what is portd, what is Portd2). Thirdly you are reading in the portd register (not an input), and then comparing it directly to a number (decimal 80, hex 0x50) - even if we assume you mean to read the inputs (pind), you haven't connected most of the pins on that port so who knows what value will return. Dec 2, 2017 at 15:49
  • @TomCarpenter I am new to it can you plz write a simple code for me which will receive data from DHT and Move it to a register? An Example Code?
    – Muhammad Farooq Arshad
    Dec 2, 2017 at 17:20
  • This Tutorial shows how to read and write from complete Port but I just need One Pin and Recieve Serial Data avr-tutorials.com/digital/…
    – Muhammad Farooq Arshad
    Dec 2, 2017 at 17:41
  • 2
    I'm voting to close this question as off-topic because it is about AVR assembly NOT ARDUINO and was properly asked on EESE, but IMPROPERLY MIGRATED. The language is not Aduino, the pin specs are AVR NOT ARDUINO - the only thing "Arduino" about this is some soldermask masquerading as silkscreen on the board. Dec 3, 2017 at 5:02

2 Answers 2


You are simply reading the state of the input pin - this won't work.

Study the datasheet for the DHT22, available from Sparkfun or eslewhere.

To get data from the DTH22, you must first send a start signal, wait a specified time, then watch the level of the data line, measuring the time of each bit to determine whether it is a 1 or 0, and store the bits in five 8-bit variables. You can then examine those variables to determine the temperature and humidity.


Instructions for writing to an individual output bit:-

 sbi portd,5 ; make Port D output bit 5 high (set)

 cbi portd,5 ; make Port D output bit 5 low (clear)

 sbi pind,5  ; toggle Port D output bit 5 (low -> high, high -> low)

Instructions for reading an individual I/O pin:-

 sbis pind,2 ; skip next instruction if Port D pin 2 is high  

 sbic pind,2 ; skip next instruction if Port D pin 2 is low
  • Awsome, this answer is clear and answers the question really well.
    – Dat Ha
    Sep 19, 2018 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.