@sanareh (Sanareh) posted a new topic, subject "Temperature based controlled fan arduino code". It read:

   Screenshot (491)1366×768 63.7 KB
    
      
    plz am newbie in coding ,,,,what does this error solved" readTemp not decleared in this page" help plz

After which, @anon73444976 added

    It means you haven't defined a variable called "temp" to receive the value returned from the function "readTemp"
    
    And then the compiler is going to whine about you having two setup functions, and about code not being in a function (though not in such simple terms)  
    Probably other stuff too.
    
    Please remember to use code tags when posting code

@groundFungus (groundFungus) replied

    Images of code are sub-optimal. We cannot copy the code to the IDE or a text editor for examination. Read the forum guidelines to see how to properly post code.  
    **Use the IDE autoformat tool** (ctrl-t or Tools, Auto format) before posting code in code tags. Often autoformatting will point out errors with misplaced and/or missing curly brackets, parenthesis and other formatting and syntax errors.
    
    Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post **in code tags**. Paraphrasing the error message leaves out important information.

To which @sanareh (Sanareh) replied

    ook. thankuu lemme do that

After which, @sanareh (Sanareh) added

    Arduino: 1.8.16 (Windows 10), Board: "Arduino Uno"
    
    C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\ADMIN\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10816 -build-path C:\Users\ADMIN\AppData\Local\Temp\arduino_build_519765 -warnings=none -build-cache C:\Users\ADMIN\AppData\Local\Temp\arduino_cache_224495 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose E:\INDUSTRY\DUINO CODES\sketch_oct18a\sketch_oct18a.ino
    
    C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\ADMIN\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10816 -build-path C:\Users\ADMIN\AppData\Local\Temp\arduino_build_519765 -warnings=none -build-cache C:\Users\ADMIN\AppData\Local\Temp\arduino_cache_224495 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose E:\INDUSTRY\DUINO CODES\sketch_oct18a\sketch_oct18a.ino
    
    Using board 'uno' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
    
    Using core 'arduino' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
    
    Detecting libraries used...
    
    "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\ADMIN\AppData\Local\Temp\arduino_build_519765\sketch\sketch_oct18a.ino.cpp" -o nul
    
    Alternatives for LiquidCrystal.h: [cmoore@example.com]
    
    ResolveLibrary(LiquidCrystal.h)
    
    -> candidates: [cmoore@example.com]
    
    "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\libraries\LiquidCrystal\src" "C:\Users\ADMIN\AppData\Local\Temp\arduino_build_519765\sketch\sketch_oct18a.ino.cpp" -o nul
    
    "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\libraries\LiquidCrystal\src" "C:\Program Files (x86)\Arduino\libraries\LiquidCrystal\src\LiquidCrystal.cpp" -o nul
    
    Generating function prototypes...
    
    "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\libraries\LiquidCrystal\src" "C:\Users\ADMIN\AppData\Local\Temp\arduino_build_519765\sketch\sketch_oct18a.ino.cpp" -o "C:\Users\ADMIN\AppData\Local\Temp\arduino_build_519765\preproc\ctags_target_for_gcc_minus_e.cpp"
    
    "C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\ADMIN\AppData\Local\Temp\arduino_build_519765\preproc\ctags_target_for_gcc_minus_e.cpp"
    
    Compiling sketch...
    
    "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10816 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\libraries\LiquidCrystal\src" "C:\Users\ADMIN\AppData\Local\Temp\arduino_build_519765\sketch\sketch_oct18a.ino.cpp" -o "C:\Users\ADMIN\AppData\Local\Temp\arduino_build_519765\sketch\sketch_oct18a.ino.cpp.o"
    
    E:\INDUSTRY\DUINO CODES\sketch_oct18a\sketch_oct18a.ino: In function 'void loop()':
    
    sketch_oct18a:20:8: error: 'readTemp' was not declared in this scope
    
    temp = readTemp(); // get the temperature
    [code] 
            ^~~~~~~~
        
    [/code]
    
    E:\INDUSTRY\DUINO CODES\sketch_oct18a\sketch_oct18a.ino: At global scope:
    
    sketch_oct18a:22:1: error: expected unqualified-id before 'if'
    
    if(temp <tempMin) { // if temp is lower than minimum temp
    
    ^~
    
    Using library LiquidCrystal at version 1.0.7 in folder: C:\Program Files (x86)\Arduino\libraries\LiquidCrystal
    
    exit status 1
    
    'readTemp' was not declared in this scope

@sanareh (Sanareh) replied

    hello how do i use the said code tag???

After which, @groundFungus (groundFungus) added

    Read the page linked in reply #3.

So @MarkT (MarkT) replied

    You haven't posted your code.
    
    I do note that you have code outside of a function - not allowed in C/C++, only declarations can be top-level.
    
    Its essential to indent your code to match the braces to be able to see sillies like this at a glance.
    
    Use more blank lines - whitespace allows code to be readable, just as paragraphs allow text to be readable.

To which @system (system) replied

    This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.


{'source': 'discourse', 'url': 'https://forum.arduino.cc/t/temperature-based-controlled-fan-arduino-code/916114', 'title': 'Temperature based controlled fan arduino code', 'views': 571, 'has_accepted_answer': False, 'word_count': 1300, 'like_count': 0, 'reply_count': 5, 'participant_count': 4, 'posts': 9, 'tags': '', 'author': '@sanareh (Sanareh)', 'participants': '@sanareh (Sanareh), @anon73444976, @groundFungus (groundFungus), @MarkT (MarkT), @system (system)', 'image_url': ['https://aws1.discourse-cdn.com/arduino/optimized/4X/3/e/a/3ea47d6d3d2bf892f5ff4ab6732683d8286f9bd0_2_1024x575.png'], 'created_at': '2021-10-18T17:34:07.688Z', 'last_posted_at': '2022-04-17T10:24:19.108Z'}