Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. analogRead only works in Arduino IDE[solved]

analogRead only works in Arduino IDE[solved]

Scheduled Pinned Locked Moved Troubleshooting
1 Posts 1 Posters 813 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    flopp
    wrote on last edited by flopp
    #1

    Arduino Nano, Arduino IDE 1.6.8.
    I am reading 4 analog inputs, everything works fine when I have the Node powered to my PC and running AIDE with Monitor opened , if I close the Monitor it goes into a special mode waiting for programming(this is normal) but when I power the Node from the wall(USB) it doesn't send Child data. I see the Node is registering in Domoticz but no Child data.

    If i remove the delay(5000) or gw.wait(5000), just before sending Child data, it doesn't work in Arduino IDE either, very strange for me.

    #include <MySensor.h>  
    #include <SPI.h>
    
    #define CHILD_ID_MQ2 0
    #define CHILD_ID_MQ3 1
    #define CHILD_ID_MQ7 2
    #define CHILD_ID_MQ135 3
    
    unsigned long SLEEP_TIME = 60000;
    
    const int MQ2 = A0; //GAS sensor output pin to Arduino analog A0 pin
    const int MQ3 = A1; //GAS sensor output pin to Arduino analog A0 pin
    const int MQ7 = A2; //GAS sensor output pin to Arduino analog A0 pin
    const int MQ135 = A3; //GAS sensor output pin to Arduino analog A0 pin
    
    int mq2;
    int mq3;
    int mq7;
    int mq135;
    
    MySensor gw;
    MyMessage MQ2Msg(CHILD_ID_MQ2, V_LEVEL);
    MyMessage MQ3Msg(CHILD_ID_MQ3, V_LEVEL);
    MyMessage MQ7Msg(CHILD_ID_MQ7, V_LEVEL);
    MyMessage MQ135Msg(CHILD_ID_MQ135, V_LEVEL);
    
    void setup()
    {
      gw.begin();
    
      gw.sendSketchInfo("Multi MQ Sensors", "1.0");
    
      gw.present(CHILD_ID_MQ2, S_AIR_QUALITY);
      gw.present(CHILD_ID_MQ3, S_AIR_QUALITY);
      gw.present(CHILD_ID_MQ7, S_AIR_QUALITY);
      gw.present(CHILD_ID_MQ135, S_AIR_QUALITY);
      
      Serial.begin(115200); //Initialize serial port - 9600 bps
      
    }
    
    void loop()
    {
      mq2 = analogRead(MQ2);
      //gw.wait(5000);
      mq3 = analogRead(MQ3);
      //gw.wait(5000);
      mq7 = analogRead(MQ7);
      //gw.wait(5000);
      mq135 = analogRead(MQ135);
      delay(5000);
      gw.send(MQ2Msg.set(mq2));
      gw.send(MQ3Msg.set(mq3));
      gw.send(MQ7Msg.set(mq7));
      gw.send(MQ135Msg.set(mq135));
      gw.sleep(SLEEP_TIME);
    }
    

    I had some other strange errors, sometimes when I rebooted I could send to GW.

    After I changed the Nano to Pro Mini it works all the time and every where. I think I got a damaged Nano, even if it was working perfect for month as another Node.

    1 Reply Last reply
    0

    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

    With your input, this post could be even better 💗

    Register Login
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    11

    Online

    12.0k

    Users

    11.2k

    Topics

    113.4k

    Posts


    Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • MySensors
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular